9 constexpr GLfloat vtx_coords[] = {
19 Application::Application()
23 , ctx(window.CreateContext())
30 GLContext::EnableVSync();
34 "layout(location = 0) in vec3 vertexPosition_modelspace;\n"
37 "vec4 v = vec4(vertexPosition_modelspace, 1);\n"
38 "gl_Position = MVP * v;\n"
46 "color = vec3(1, 1, 1);\n"
50 if (!program.Linked()) {
51 program.Log(std::cerr);
52 throw std::runtime_error("link program");
56 glGenVertexArrays(1, &VertexArrayID);
57 glBindVertexArray(VertexArrayID);
59 glGenBuffers(1, &vtx_buf);
60 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
61 glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW);
63 mvp_handle = program.UniformLocation("MVP");
65 glClearColor(0.0, 0.0, 0.0, 1.0);
68 Application::~Application() {
73 void Application::Run() {
75 Uint32 last = SDL_GetTicks();
77 Uint32 now = SDL_GetTicks();
78 int delta = now - last;
84 void Application::Loop(int dt) {
90 void Application::HandleEvents() {
92 while (SDL_PollEvent(&event)) {
98 switch (event.window.event) {
99 case SDL_WINDOWEVENT_RESIZED:
100 cam.Viewport(event.window.data1, event.window.data2);
112 void Application::Render() {
113 glClear(GL_COLOR_BUFFER_BIT);
117 glm::mat4 model(1.0f); // identity: no transformation
118 glm::mat4 mvp(cam.MakeMVP(model));
119 glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]);
121 glEnableVertexAttribArray(0);
122 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
123 glVertexAttribPointer(
124 0, // attribute 0 (for shader)
127 GL_FALSE, // normalized
136 glDisableVertexAttribArray(0);