Changeset 93baa0e in opengl-game
- Timestamp:
- Aug 5, 2017, 6:55:49 PM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 49756cb
- Parents:
- d0b9596
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rd0b9596 r93baa0e 9 9 #include <iostream> 10 10 #include <fstream> 11 #include <cmath> 11 12 12 13 using namespace std; … … 74 75 printf("Renderer: %s\n", renderer); 75 76 printf("OpenGL version supported %s\n", version); 77 76 78 glEnable(GL_DEPTH_TEST); 77 79 glDepthFunc(GL_LESS); 78 80 81 glEnable(GL_CULL_FACE); 82 // glCullFace(GL_BACK); 83 // glFrontFace(GL_CW); 84 79 85 GLfloat points[] = { 80 86 0.0f, 0.5f, 0.0f, 87 -0.5f, -0.5f, 0.0f, 81 88 0.5f, -0.5f, 0.0f, 82 -0.5f, -0.5f, 0.0f,83 89 }; 84 90 85 91 GLfloat colors[] = { 86 92 1.0, 0.0, 0.0, 93 0.0, 0.0, 1.0, 87 94 0.0, 1.0, 0.0, 88 0.0, 0.0, 1.0, 95 }; 96 97 GLfloat model[] = { 98 1.0f, 0.0f, 0.0f, 0.0f, // column 1 99 0.0f, 1.0f, 0.0f, 0.0f, // column 2 100 0.0f, 0.0f, 1.0f, 0.0f, // column 3 101 0.5f, 0.0f, 0.0f, 1.0f, // column 4 89 102 }; 90 103 … … 119 132 glLinkProgram(shader_program); 120 133 134 GLint location = glGetUniformLocation(shader_program, "model"); 135 136 float speed = 1.0f; 137 float last_position = 0.0f; 138 139 double previous_seconds = glfwGetTime(); 121 140 while (!glfwWindowShouldClose(window)) { 141 double current_seconds = glfwGetTime(); 142 double elapsed_seconds = current_seconds - previous_seconds; 143 previous_seconds = current_seconds; 144 145 if (fabs(last_position) > 1.0f) { 146 speed = -speed; 147 } 148 149 model[12] = last_position + speed*elapsed_seconds; 150 last_position = model[12]; 151 glUseProgram(shader_program); 152 glUniformMatrix4fv(location, 1, GL_FALSE, model); 153 122 154 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 123 glUseProgram(shader_program);124 155 glBindVertexArray(vao); 156 125 157 glDrawArrays(GL_TRIANGLES, 0, 3); 126 158 -
test.vert
rd0b9596 r93baa0e 1 1 #version 410 2 3 uniform mat4 model; 2 4 3 5 layout(location = 0) in vec3 vertex_position; … … 8 10 void main() { 9 11 color = vertex_color; 10 gl_Position = vec4(vertex_position, 1.0);12 gl_Position = model * vec4(vertex_position, 1.0); 11 13 }
Note:
See TracChangeset
for help on using the changeset viewer.