9 constexpr GLfloat vtx_coords[] = {
19 Application::Application()
24 , ctx(window.CreateContext())
32 GLContext::EnableVSync();
36 "layout(location = 0) in vec3 vertexPosition_modelspace;\n"
39 "vec4 v = vec4(vertexPosition_modelspace, 1);\n"
40 "gl_Position = MVP * v;\n"
48 "color = vec3(1, 1, 1);\n"
52 if (!program.Linked()) {
53 program.Log(std::cerr);
54 throw std::runtime_error("link program");
58 glGenVertexArrays(1, &VertexArrayID);
59 glBindVertexArray(VertexArrayID);
61 glGenBuffers(1, &vtx_buf);
62 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
63 glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW);
65 model.Position(glm::vec3(0, 0, -4));
67 mvp_handle = program.UniformLocation("MVP");
69 glClearColor(0.0, 0.0, 0.0, 1.0);
72 Application::~Application() {
77 void Application::Run() {
79 Uint32 last = SDL_GetTicks();
81 Uint32 now = SDL_GetTicks();
82 int delta = now - last;
88 void Application::Loop(int dt) {
94 void Application::HandleEvents() {
96 while (SDL_PollEvent(&event)) {
101 case SDL_WINDOWEVENT:
102 switch (event.window.event) {
103 case SDL_WINDOWEVENT_RESIZED:
104 cam.Viewport(event.window.data1, event.window.data2);
116 void Application::Render() {
117 glClear(GL_COLOR_BUFFER_BIT);
121 glm::mat4 mvp(cam.MakeMVP(model.Transform()));
122 glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]);
124 glEnableVertexAttribArray(0);
125 glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
126 glVertexAttribPointer(
127 0, // attribute 0 (for shader)
130 GL_FALSE, // normalized
139 glDisableVertexAttribArray(0);