X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp.cpp;h=038aa1aebbcd16a7ad4a1ae4a50830e4b41b59d1;hb=d18be10ef3f0a7b61c6f5c4c4096ca2b776c75b3;hp=d54e8df56d1d0e875da4e599cca3ae67ea4b67cb;hpb=b314df303ffedbd6d2e81872908d12fc9712801a;p=blank.git diff --git a/src/app.cpp b/src/app.cpp index d54e8df..038aa1a 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -7,9 +7,9 @@ namespace { constexpr GLfloat vtx_coords[] = { - -1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, - 0.0f, 1.0f, -1.0f, + -1.0f, -1.0f, 0.0f, + 1.0f, -1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, }; } @@ -18,13 +18,15 @@ namespace blank { Application::Application() : init_sdl() +, init_img() , init_gl() , window() , ctx(window.CreateContext()) , init_glew() , program() +, cam() +, model() , vtx_buf(0) -, mvp() , mvp_handle(0) , running(false) { GLContext::EnableVSync(); @@ -60,19 +62,7 @@ Application::Application() glBindBuffer(GL_ARRAY_BUFFER, vtx_buf); glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW); - glm::mat4 projection = glm::perspective( - 45.0f, // FOV in degrees - 1.0f, // aspect ratio - 0.1f, // near clip - 100.0f // far clip - ); - glm::mat4 view = glm::lookAt( - glm::vec3(0, 0, 0), // observer - glm::vec3(0, 0, -1), // target - glm::vec3(0, 1, 0) // up - ); - glm::mat4 model(1.0f); // identity: no transformation - mvp = projection * view * model; + model.Position(glm::vec3(0, 0, -4)); mvp_handle = program.UniformLocation("MVP"); @@ -108,6 +98,15 @@ void Application::HandleEvents() { case SDL_QUIT: running = false; break; + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + cam.Viewport(event.window.data1, event.window.data2); + break; + default: + break; + } + break; default: break; } @@ -119,6 +118,7 @@ void Application::Render() { program.Use(); + glm::mat4 mvp(cam.MakeMVP(model.Transform())); glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]); glEnableVertexAttribArray(0);