diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 72 |
1 files changed, 15 insertions, 57 deletions
@@ -5,84 +5,43 @@ #include "texture.h" #include "transform.h" #include <SDL2/SDL.h> -#include <iostream> +#include <cmath> +#include <glm/glm.hpp> +#include <memory> +#include <numbers> static const int DISPLAY_WIDTH = 800; static const int DISPLAY_HEIGHT = 600; int -main(int argc, char ** argv) +main(int, char **) { 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); + 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; + float counter = 0.0F; while (isRunning) { while (SDL_PollEvent(&e)) { - if (e.type == SDL_QUIT) + if (e.type == SDL_QUIT) { isRunning = false; + } } - display.Clear(0.0f, 0.0f, 0.0f, 1.0f); + display.Clear(0.0F, 0.0F, 0.0F, 1.0F); - float sinCounter = sinf(counter); - float absSinCounter = abs(sinCounter); + // float sinCounter = sinf(counter); + // float absSinCounter = abs(sinCounter); // transform.GetPos()->x = sinCounter; - transform.GetRot()->y = counter * 100; - // transform.GetRot()->z = counter * 100; + transform.GetRot().y = std::numbers::pi_v<double> + sin(counter); + transform.GetRot().z = 0.3 * cos(counter * 10); // transform.GetScale()->x = absSinCounter; // transform.GetScale()->y = absSinCounter; @@ -90,11 +49,10 @@ main(int argc, char ** argv) texture.Bind(); shader.Update(transform, camera); monkey.Draw(); - // mesh.Draw(); display.SwapBuffers(); SDL_Delay(1); - counter += 0.01f; + counter += 0.01F; } return 0; |