Changeset 92bc4fe in opengl-game for mygame.cpp
- Timestamp:
- Jun 25, 2017, 7:15:12 PM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- fe70cd3
- Parents:
- 8a6d19d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mygame.cpp
r8a6d19d r92bc4fe 2 2 #include <stdio.h> 3 3 #include <stdlib.h> 4 5 #include <iostream> 6 using namespace std; 4 7 5 8 // Include GLEW … … 34 37 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 35 38 36 // Open a window and create its OpenGL context 37 window = glfwCreateWindow( 1024, 768, "Tutorial 04 - Colored Cube", NULL, NULL); 39 const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 40 41 // Open a window and create its OpenGL context 42 window = glfwCreateWindow(mode->width, mode->height, "My Space Game", glfwGetPrimaryMonitor(), NULL); 38 43 if( window == NULL ){ 39 44 fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" ); … … 43 48 } 44 49 glfwMakeContextCurrent(window); 50 glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); 45 51 46 52 // Initialize GLEW … … 213 219 glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW); 214 220 215 216 217 218 219 220 221 222 223 computeMatricesFromInputs();221 do { 222 223 // Clear the screen 224 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 225 226 // Use our shader 227 glUseProgram(programID); 228 229 computeMatricesFromInputs(mode->width, mode->height); 224 230 225 231 // Projection matrix : 45� Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units … … 239 245 240 246 // Remember, matrix multiplication is the other way around 241 247 glm::mat4 MVP = Projection * View * Model; 242 248 243 249 // Send our transformation to the currently bound shader, 244 // in the "MVP" uniform 245 glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); 246 247 // 1rst attribute buffer : vertices 248 glEnableVertexAttribArray(0); 249 glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); 250 glVertexAttribPointer( 251 0, // attribute. No particular reason for 0, but must match the layout in the shader. 252 3, // size 253 GL_FLOAT, // type 254 GL_FALSE, // normalized? 255 0, // stride 256 (void*)0 // array buffer offset 257 ); 258 259 // 2nd attribute buffer : colors 260 glEnableVertexAttribArray(1); 261 glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); 262 glVertexAttribPointer( 263 1, // attribute. No particular reason for 1, but must match the layout in the shader. 264 3, // size 265 GL_FLOAT, // type 266 GL_FALSE, // normalized? 267 0, // stride 268 (void*)0 // array buffer offset 269 ); 270 271 // Draw the triangle ! 272 glDrawArrays(GL_TRIANGLES, 0, 12*3+18); // 12*3 indices starting at 0 -> 12 triangles 273 274 glDisableVertexAttribArray(0); 275 glDisableVertexAttribArray(1); 276 277 // Swap buffers 278 glfwSwapBuffers(window); 279 glfwPollEvents(); 280 281 } // Check if the ESC key was pressed or the window was closed 282 while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && 283 glfwWindowShouldClose(window) == 0 ); 250 // in the "MVP" uniform 251 glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); 252 253 // 1rst attribute buffer : vertices 254 glEnableVertexAttribArray(0); 255 glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); 256 glVertexAttribPointer( 257 0, // attribute. No particular reason for 0, but must match the layout in the shader. 258 3, // size 259 GL_FLOAT, // type 260 GL_FALSE, // normalized? 261 0, // stride 262 (void*)0 // array buffer offset 263 ); 264 265 // 2nd attribute buffer : colors 266 glEnableVertexAttribArray(1); 267 glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); 268 glVertexAttribPointer( 269 1, // attribute. No particular reason for 1, but must match the layout in the shader. 270 3, // size 271 GL_FLOAT, // type 272 GL_FALSE, // normalized? 273 0, // stride 274 (void*)0 // array buffer offset 275 ); 276 277 // Draw the triangle ! 278 glDrawArrays(GL_TRIANGLES, 0, 12*3+18); // 12*3 indices starting at 0 -> 12 triangles 279 280 glDisableVertexAttribArray(0); 281 glDisableVertexAttribArray(1); 282 283 // Swap buffers 284 glfwSwapBuffers(window); 285 glfwPollEvents(); 286 287 // Check if the ESC key was pressed or the window was closed 288 } while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); 284 289 285 290 // Cleanup VBO and shader
Note:
See TracChangeset
for help on using the changeset viewer.