9 constexpr GLfloat vtx_coords[] = {
19 Application::Application()
24 , ctx(window.CreateContext())
31 GLContext::EnableVSync();
35 "layout(location = 0) in vec3 vertexPosition_modelspace;\n"
38 "vec4 v = vec4(vertexPosition_modelspace, 1);\n"
39 "gl_Position = MVP * v;\n"
47 "color = vec3(1, 1, 1);\n"
51 if (!program.Linked()) {
52 program.Log(std::cerr);
53 throw std::runtime_error("link program");
57 glGenVertexArrays(1, &VertexArrayID);
58 glBindVertexArray(VertexArrayID);
60 glGenBuffers(1, &vtx_buf);
61 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
62 glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW);
64 mvp_handle = program.UniformLocation("MVP");
66 glClearColor(0.0, 0.0, 0.0, 1.0);
69 Application::~Application() {
74 void Application::Run() {
76 Uint32 last = SDL_GetTicks();
78 Uint32 now = SDL_GetTicks();
79 int delta = now - last;
85 void Application::Loop(int dt) {
91 void Application::HandleEvents() {
93 while (SDL_PollEvent(&event)) {
99 switch (event.window.event) {
100 case SDL_WINDOWEVENT_RESIZED:
101 cam.Viewport(event.window.data1, event.window.data2);
113 void Application::Render() {
114 glClear(GL_COLOR_BUFFER_BIT);
118 glm::mat4 model(1.0f); // identity: no transformation
119 glm::mat4 mvp(cam.MakeMVP(model));
120 glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]);
122 glEnableVertexAttribArray(0);
123 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
124 glVertexAttribPointer(
125 0, // attribute 0 (for shader)
128 GL_FALSE, // normalized
137 glDisableVertexAttribArray(0);