diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-16 18:09:15 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-16 18:09:15 +0000 |
commit | 400410fcd436d5e4310bfa779f0309c5fae5b2c2 (patch) | |
tree | 89661918c487e63b6c71f2e9281b553928010606 /main.cpp | |
download | ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.bz2 ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.xz ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.zip |
Initial commit
Stripped back and formatted from https://github.com/BennyQBD/ModernOpenGLTutorial/
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..431610b --- /dev/null +++ b/main.cpp @@ -0,0 +1,101 @@ +#include "camera.h" +#include "display.h" +#include "mesh.h" +#include "shader.h" +#include "texture.h" +#include "transform.h" +#include <SDL2/SDL.h> +#include <iostream> + +static const int DISPLAY_WIDTH = 800; +static const int DISPLAY_HEIGHT = 600; + +int +main(int argc, char ** argv) +{ + Display display(DISPLAY_WIDTH, DISPLAY_HEIGHT, "OpenGL"); + + Vertex vertices[] = { + Vertex(glm::vec3(-1, -1, -1), glm::vec2(1, 0), glm::vec3(0, 0, -1)), + Vertex(glm::vec3(-1, 1, -1), glm::vec2(0, 0), glm::vec3(0, 0, -1)), + Vertex(glm::vec3(1, 1, -1), glm::vec2(0, 1), glm::vec3(0, 0, -1)), + Vertex(glm::vec3(1, -1, -1), glm::vec2(1, 1), glm::vec3(0, 0, -1)), + + Vertex(glm::vec3(-1, -1, 1), glm::vec2(1, 0), glm::vec3(0, 0, 1)), + Vertex(glm::vec3(-1, 1, 1), glm::vec2(0, 0), glm::vec3(0, 0, 1)), + Vertex(glm::vec3(1, 1, 1), glm::vec2(0, 1), glm::vec3(0, 0, 1)), + Vertex(glm::vec3(1, -1, 1), glm::vec2(1, 1), glm::vec3(0, 0, 1)), + + Vertex(glm::vec3(-1, -1, -1), glm::vec2(0, 1), glm::vec3(0, -1, 0)), + Vertex(glm::vec3(-1, -1, 1), glm::vec2(1, 1), glm::vec3(0, -1, 0)), + Vertex(glm::vec3(1, -1, 1), glm::vec2(1, 0), glm::vec3(0, -1, 0)), + Vertex(glm::vec3(1, -1, -1), glm::vec2(0, 0), glm::vec3(0, -1, 0)), + + Vertex(glm::vec3(-1, 1, -1), glm::vec2(0, 1), glm::vec3(0, 1, 0)), + Vertex(glm::vec3(-1, 1, 1), glm::vec2(1, 1), glm::vec3(0, 1, 0)), + Vertex(glm::vec3(1, 1, 1), glm::vec2(1, 0), glm::vec3(0, 1, 0)), + Vertex(glm::vec3(1, 1, -1), glm::vec2(0, 0), glm::vec3(0, 1, 0)), + + Vertex(glm::vec3(-1, -1, -1), glm::vec2(1, 1), glm::vec3(-1, 0, 0)), + Vertex(glm::vec3(-1, -1, 1), glm::vec2(1, 0), glm::vec3(-1, 0, 0)), + Vertex(glm::vec3(-1, 1, 1), glm::vec2(0, 0), glm::vec3(-1, 0, 0)), + Vertex(glm::vec3(-1, 1, -1), glm::vec2(0, 1), glm::vec3(-1, 0, 0)), + + Vertex(glm::vec3(1, -1, -1), glm::vec2(1, 1), glm::vec3(1, 0, 0)), + Vertex(glm::vec3(1, -1, 1), glm::vec2(1, 0), glm::vec3(1, 0, 0)), + Vertex(glm::vec3(1, 1, 1), glm::vec2(0, 0), glm::vec3(1, 0, 0)), + Vertex(glm::vec3(1, 1, -1), glm::vec2(0, 1), glm::vec3(1, 0, 0)), + }; + + unsigned int indices[] = {0, 1, 2, 0, 2, 3, + + 6, 5, 4, 7, 6, 4, + + 10, 9, 8, 11, 10, 8, + + 12, 13, 14, 12, 14, 15, + + 16, 17, 18, 16, 18, 19, + + 22, 21, 20, 23, 22, 20}; + + Mesh mesh(vertices, sizeof(vertices) / sizeof(vertices[0]), indices, sizeof(indices) / sizeof(indices[0])); + Mesh monkey("./res/monkey3.obj"); + Shader shader("./res/basicShader"); + Texture texture("./res/bricks.jpg"); + Transform transform; + Camera camera(glm::vec3(0.0f, 0.0f, -5.0f), 70.0f, (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT, 0.1f, 100.0f); + + SDL_Event e; + bool isRunning = true; + float counter = 0.0f; + while (isRunning) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) + isRunning = false; + } + + display.Clear(0.0f, 0.0f, 0.0f, 1.0f); + + float sinCounter = sinf(counter); + float absSinCounter = abs(sinCounter); + + // transform.GetPos()->x = sinCounter; + transform.GetRot()->y = counter * 100; + // transform.GetRot()->z = counter * 100; + // transform.GetScale()->x = absSinCounter; + // transform.GetScale()->y = absSinCounter; + + shader.Bind(); + texture.Bind(); + shader.Update(transform, camera); + monkey.Draw(); + // mesh.Draw(); + + display.SwapBuffers(); + SDL_Delay(1); + counter += 0.01f; + } + + return 0; +} |