Changeset 05e43cf in opengl-game
- Timestamp:
- Apr 25, 2018, 2:44:28 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 07ed460
- Parents:
- 7280257
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
NewOpenGLGame.vcxproj
r7280257 r05e43cf 135 135 <ItemGroup> 136 136 <Text Include="gl.log" /> 137 <Text Include="opengl-notes.txt" /> 137 138 <Text Include="TODO.txt" /> 138 139 </ItemGroup> -
new-game.cpp
r7280257 r05e43cf 43 43 mat4 model_mat; 44 44 GLuint shader_program; 45 GLvoid* vbo_offset; 46 unsigned int num_points; 45 47 }; 46 48 … … 233 235 }; 234 236 235 // Each point is made of 3 floats236 int numPoints = (sizeof(points) / sizeof(float)) / 3;237 238 237 GLfloat points2[] = { 239 238 0.5f, 0.5f, 0.0f, … … 263 262 }; 264 263 265 // Each point is made of 3 floats266 int numPoints2 = (sizeof(points2) / sizeof(float)) / 3;267 268 264 mat4 T_model, R_model; 269 265 … … 271 267 objects.push_back(SceneObject()); 272 268 objects[0].shader_program = 0; 269 objects[0].vbo_offset = (GLvoid*) (0 * sizeof(float) * 3); 270 objects[0].num_points = 6; 273 271 274 272 T_model = translate(mat4(), vec3(0.45f, 0.0f, 0.0f)); … … 287 285 objects.push_back(SceneObject()); 288 286 objects[1].shader_program = 0; 287 objects[1].vbo_offset = (GLvoid*) (6 * sizeof(float) * 3); 288 objects[1].num_points = 6; 289 289 290 290 T_model = translate(mat4(), vec3(-0.5f, 0.0f, -1.00f)); … … 311 311 glGenBuffers(1, &points_vbo); 312 312 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 313 glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); 313 glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(points2), NULL, GL_DYNAMIC_DRAW); 314 315 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(points), points); 316 glBufferSubData(GL_ARRAY_BUFFER, sizeof(points), sizeof(points2), points2); 314 317 315 318 GLuint colors_vbo = 0; … … 321 324 glGenVertexArrays(1, &vao); 322 325 glBindVertexArray(vao); 323 glBindBuffer(GL_ARRAY_BUFFER, points_vbo);324 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);325 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);326 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);327 326 328 327 glEnableVertexAttribArray(0); 329 328 glEnableVertexAttribArray(1); 330 331 GLuint points2_vbo = 0;332 glGenBuffers(1, &points2_vbo);333 glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);334 glBufferData(GL_ARRAY_BUFFER, sizeof(points2), points2, GL_STATIC_DRAW);335 329 336 330 GLuint colors2_vbo = 0; … … 347 341 glGenVertexArrays(1, &vao2); 348 342 glBindVertexArray(vao2); 349 glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);350 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);351 // glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo);352 // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);353 glBindBuffer(GL_ARRAY_BUFFER, vt_vbo);354 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);355 343 356 344 glEnableVertexAttribArray(0); … … 515 503 glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[*it].model_mat)); 516 504 505 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 506 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vbo_offset); 507 517 508 if (selectedObject == &objects[*it]) { 518 509 if (*it == 1) { 519 glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);520 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);521 522 510 glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo); 523 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);524 525 glDrawArrays(GL_TRIANGLES, 0, numPoints2);526 511 } else { 527 glBindBuffer(GL_ARRAY_BUFFER, points_vbo);528 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);529 530 512 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 531 513 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW); 532 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);533 534 glDrawArrays(GL_TRIANGLES, 0, numPoints);535 514 } 536 515 } else { 537 glBindBuffer(GL_ARRAY_BUFFER, points_vbo);538 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);539 540 516 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 541 517 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); 542 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);543 544 glDrawArrays(GL_TRIANGLES, 0, numPoints);545 518 } 519 520 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 521 522 glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points); 546 523 } 547 524 … … 552 529 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objects[*it].model_mat)); 553 530 554 glDrawArrays(GL_TRIANGLES, 0, numPoints2); 531 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 532 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vbo_offset); 533 534 glBindBuffer(GL_ARRAY_BUFFER, vt_vbo); 535 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 536 537 glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points); 555 538 } 556 539
Note:
See TracChangeset
for help on using the changeset viewer.