Changeset 9dd2eb7 in opengl-game for new-game.cpp
- Timestamp:
- Apr 28, 2018, 2:29:20 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 9f4986b
- Parents:
- d9f99b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rd9f99b2 r9dd2eb7 40 40 vector<GLfloat> colors; 41 41 vector<GLfloat> texcoords; 42 vector<GLfloat> normals; 42 43 vector<GLfloat> selected_colors; 43 44 }; … … 240 241 1.0f, 0.0f 241 242 }; 243 objects[0].normals = { 244 0.0f, 0.0f, 1.0f, 245 0.0f, 0.0f, 1.0f, 246 0.0f, 0.0f, 1.0f, 247 0.0f, 0.0f, -1.0f, 248 0.0f, 0.0f, -1.0f, 249 0.0f, 0.0f, -1.0f, 250 }; 242 251 objects[0].selected_colors = { 243 252 0.0f, 1.0f, 0.0f, … … 284 293 1.0f, 0.0f 285 294 }; 295 objects[1].normals = { 296 0.0f, 0.0f, 1.0f, 297 0.0f, 0.0f, 1.0f, 298 0.0f, 0.0f, 1.0f, 299 0.0f, 0.0f, 1.0f, 300 0.0f, 0.0f, 1.0f, 301 0.0f, 0.0f, 1.0f, 302 }; 286 303 objects[1].selected_colors = { 287 304 0.0f, 0.9f, 0.9f, … … 353 370 } 354 371 372 GLuint normals_vbo = 0; 373 glGenBuffers(1, &normals_vbo); 374 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 375 glBufferData(GL_ARRAY_BUFFER, points_buffer_size, NULL, GL_DYNAMIC_DRAW); 376 377 offset = 0; 378 for (obj_it = objects.begin(); obj_it != objects.end(); obj_it++) { 379 glBufferSubData(GL_ARRAY_BUFFER, offset, obj_it->normals.size() * sizeof(GLfloat), &obj_it->normals[0]); 380 offset += obj_it->normals.size() * sizeof(GLfloat); 381 } 382 355 383 GLuint vao = 0; 356 384 glGenVertexArrays(1, &vao); … … 359 387 glEnableVertexAttribArray(0); 360 388 glEnableVertexAttribArray(1); 389 glEnableVertexAttribArray(2); 361 390 362 391 GLuint vao2 = 0; … … 366 395 glEnableVertexAttribArray(0); 367 396 glEnableVertexAttribArray(1); 397 glEnableVertexAttribArray(2); 368 398 369 399 // I can create a vbo to store all points for all models, … … 459 489 double previous_seconds = glfwGetTime(); 460 490 491 // This draws wireframes. Useful for seeing separate faces and occluded objects. 492 //glPolygonMode(GL_FRONT, GL_LINE); 493 461 494 while (!glfwWindowShouldClose(window)) { 462 495 double current_seconds = glfwGetTime(); … … 535 568 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vertex_vbo_offset); 536 569 570 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 571 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vertex_vbo_offset); 572 537 573 glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points); 538 574 } … … 549 585 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 550 586 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, objects[*it].texture_vbo_offset); 587 588 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 589 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vertex_vbo_offset); 551 590 552 591 glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points);
Note:
See TracChangeset
for help on using the changeset viewer.