Changeset 39ac76d in opengl-game for new-game.cpp
- Timestamp:
- Jan 31, 2019, 5:04:01 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- ae0c7f4
- Parents:
- 646f3f2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r646f3f2 r39ac76d 70 70 vector<GLfloat> texcoords; 71 71 vector<GLfloat> normals; 72 vector<GLfloat> selected_colors;73 72 bool deleted; 74 73 vec3 bounding_center; … … 92 91 SceneObject* effectedObject; 93 92 93 // TODO: Why not just use an initializer list for all the instance variables 94 94 EffectOverTime(float& effectedValue, float changePerSecond, SceneObject* object) 95 95 : effectedValue(effectedValue), changePerSecond(changePerSecond), effectedObject(object) { … … 139 139 GLuint points_vbo, 140 140 GLuint colors_vbo, 141 GLuint selected_colors_vbo,142 141 GLuint texcoords_vbo, 143 142 GLuint normals_vbo, … … 152 151 GLuint* points_vbo, 153 152 GLuint* colors_vbo, 154 GLuint* selected_colors_vbo,155 153 GLuint* texcoords_vbo, 156 154 GLuint* normals_vbo, … … 162 160 GLuint points_vbo, 163 161 GLuint colors_vbo, 164 GLuint selected_colors_vbo,165 162 GLuint texcoords_vbo, 166 163 GLuint normals_vbo, … … 172 169 GLuint points_vbo, 173 170 GLuint colors_vbo, 174 GLuint selected_colors_vbo,175 171 GLuint texcoords_vbo, 176 172 GLuint normals_vbo, … … 183 179 GLuint points_vbo, 184 180 GLuint colors_vbo, 185 GLuint selected_colors_vbo,186 181 GLuint texcoords_vbo, 187 182 GLuint normals_vbo, … … 206 201 207 202 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 208 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 209 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 210 GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo, 211 SceneObject* selectedObject); 203 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp, GLuint explosion_sp, 204 GLuint ship_vao, GLuint asteroid_vao, GLuint laser_vao, GLuint explosion_vao, 205 GLuint colors_vbo, GLuint ubo, SceneObject* selectedObject); 212 206 213 207 void renderSceneGui(); … … 451 445 map<GLuint, BufferInfo> shaderBufferInfo; 452 446 453 // TODO: Rename color_sp to ship_sp and comment out texture_sp) 454 455 GLuint color_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 447 GLuint ship_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 456 448 GLuint asteroid_sp = loadShaderProgram("./asteroid.vert", "./asteroid.frag"); 457 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag");458 449 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 459 450 GLuint explosion_sp = loadShaderProgram("./explosion.vert", "./explosion.frag"); 460 451 461 shaderBufferInfo[ color_sp] = BufferInfo();452 shaderBufferInfo[ship_sp] = BufferInfo(); 462 453 shaderBufferInfo[asteroid_sp] = BufferInfo(); 463 shaderBufferInfo[texture_sp] = BufferInfo();464 454 shaderBufferInfo[laser_sp] = BufferInfo(); 465 455 shaderBufferInfo[explosion_sp] = BufferInfo(); … … 470 460 471 461 // player ship 472 SceneObject* ship = createShip( color_sp);462 SceneObject* ship = createShip(ship_sp); 473 463 objects.push_back(ship); 474 464 475 465 vector<SceneObject>::iterator obj_it; 476 466 477 GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo, 478 normals_vbo, ubo, model_mat_idx_vbo; 467 GLuint points_vbo, colors_vbo, texcoords_vbo, normals_vbo, ubo, model_mat_idx_vbo; 479 468 480 469 initializeBuffers( 481 470 &points_vbo, 482 471 &colors_vbo, 483 &selected_colors_vbo,484 472 &texcoords_vbo, 485 473 &normals_vbo, … … 491 479 points_vbo, 492 480 colors_vbo, 493 selected_colors_vbo,494 481 texcoords_vbo, 495 482 normals_vbo, … … 498 485 asteroid_sp); 499 486 500 GLuint color_vao = 0;501 glGenVertexArrays(1, & color_vao);502 glBindVertexArray( color_vao);487 GLuint ship_vao = 0; 488 glGenVertexArrays(1, &ship_vao); 489 glBindVertexArray(ship_vao); 503 490 504 491 glEnableVertexAttribArray(0); … … 534 521 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 535 522 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 536 537 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);538 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);539 540 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);541 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL);542 543 GLuint texture_vao = 0;544 glGenVertexArrays(1, &texture_vao);545 glBindVertexArray(texture_vao);546 547 glEnableVertexAttribArray(0);548 glEnableVertexAttribArray(1);549 glEnableVertexAttribArray(2);550 glEnableVertexAttribArray(3);551 552 glBindBuffer(GL_ARRAY_BUFFER, points_vbo);553 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);554 555 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);556 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);557 523 558 524 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); … … 616 582 points_vbo, 617 583 colors_vbo, 618 selected_colors_vbo,619 584 texcoords_vbo, 620 585 normals_vbo, … … 624 589 GLuint ub_binding_point = 0; 625 590 626 // TODO: Replace test_loc and mat_loc with more descriptive names 627 GLuint view_test_loc = glGetUniformLocation(color_sp, "view"); 628 GLuint proj_test_loc = glGetUniformLocation(color_sp, "proj"); 629 GLuint color_sp_models_ub_index = glGetUniformBlockIndex(color_sp, "models"); 591 GLuint ship_view_mat_loc = glGetUniformLocation(ship_sp, "view"); 592 GLuint ship_proj_mat_loc = glGetUniformLocation(ship_sp, "proj"); 593 GLuint ship_sp_models_ub_index = glGetUniformBlockIndex(ship_sp, "models"); 630 594 631 595 GLuint asteroid_view_mat_loc = glGetUniformLocation(asteroid_sp, "view"); 632 596 GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj"); 633 597 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models"); 634 635 GLuint view_mat_loc = glGetUniformLocation(texture_sp, "view");636 GLuint proj_mat_loc = glGetUniformLocation(texture_sp, "proj");637 GLuint texture_sp_models_ub_index = glGetUniformBlockIndex(texture_sp, "models");638 598 639 599 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); … … 647 607 648 608 649 glUseProgram( color_sp);650 glUniformMatrix4fv( view_test_loc, 1, GL_FALSE, value_ptr(view_mat));651 glUniformMatrix4fv( proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat));652 653 glUniformBlockBinding( color_sp, color_sp_models_ub_index, ub_binding_point);609 glUseProgram(ship_sp); 610 glUniformMatrix4fv(ship_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 611 glUniformMatrix4fv(ship_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 612 613 glUniformBlockBinding(ship_sp, ship_sp_models_ub_index, ub_binding_point); 654 614 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 655 615 … … 660 620 661 621 glUniformBlockBinding(asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point); 662 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);663 664 665 glUseProgram(texture_sp);666 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));667 glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));668 669 glUniformBlockBinding(texture_sp, texture_sp_models_ub_index, ub_binding_point);670 622 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 671 623 … … 756 708 points_vbo, 757 709 colors_vbo, 758 selected_colors_vbo,759 710 texcoords_vbo, 760 711 normals_vbo, … … 816 767 points_vbo, 817 768 colors_vbo, 818 selected_colors_vbo,819 769 texcoords_vbo, 820 770 normals_vbo, … … 834 784 points_vbo, 835 785 colors_vbo, 836 selected_colors_vbo,837 786 texcoords_vbo, 838 787 normals_vbo, … … 955 904 //printVector("cam pos", cam_pos); 956 905 957 glUseProgram(color_sp); 958 glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat)); 959 960 glUseProgram(texture_sp); 961 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 906 glUseProgram(ship_sp); 907 glUniformMatrix4fv(ship_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 962 908 963 909 glUseProgram(laser_sp); … … 981 927 case STATE_GAME: 982 928 renderScene(shaderBufferInfo, 983 color_sp, asteroid_sp, texture_sp, laser_sp, explosion_sp, 984 color_vao, asteroid_vao, texture_vao, laser_vao, explosion_vao, 985 colors_vbo, selected_colors_vbo, ubo, 986 selectedObject); 929 ship_sp, asteroid_sp, laser_sp, explosion_sp, 930 ship_vao, asteroid_vao, laser_vao, explosion_vao, 931 colors_vbo, ubo, selectedObject); 987 932 renderSceneGui(); 988 933 break; … … 1338 1283 GLuint points_vbo, 1339 1284 GLuint colors_vbo, 1340 GLuint selected_colors_vbo,1341 1285 GLuint texcoords_vbo, 1342 1286 GLuint normals_vbo, … … 1363 1307 points_vbo, 1364 1308 colors_vbo, 1365 selected_colors_vbo,1366 1309 texcoords_vbo, 1367 1310 normals_vbo, … … 1373 1316 points_vbo, 1374 1317 colors_vbo, 1375 selected_colors_vbo,1376 1318 texcoords_vbo, 1377 1319 normals_vbo, … … 1818 1760 }; 1819 1761 ship->texcoords = { 0.0f }; 1820 ship->selected_colors = { 0.0f };1821 1762 1822 1763 mat4 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)); … … 1923 1864 GLuint* points_vbo, 1924 1865 GLuint* colors_vbo, 1925 GLuint* selected_colors_vbo,1926 1866 GLuint* texcoords_vbo, 1927 1867 GLuint* normals_vbo, … … 1934 1874 glGenBuffers(1, colors_vbo); 1935 1875 1936 *selected_colors_vbo = 0;1937 glGenBuffers(1, selected_colors_vbo);1938 1939 1876 *texcoords_vbo = 0; 1940 1877 glGenBuffers(1, texcoords_vbo); … … 1954 1891 GLuint points_vbo, 1955 1892 GLuint colors_vbo, 1956 GLuint selected_colors_vbo,1957 1893 GLuint texcoords_vbo, 1958 1894 GLuint normals_vbo, … … 2015 1951 points_vbo, 2016 1952 colors_vbo, 2017 selected_colors_vbo,2018 1953 texcoords_vbo, 2019 1954 normals_vbo, … … 2029 1964 GLuint points_vbo, 2030 1965 GLuint colors_vbo, 2031 GLuint selected_colors_vbo,2032 1966 GLuint texcoords_vbo, 2033 1967 GLuint normals_vbo, … … 2110 2044 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2111 2045 2112 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo);2113 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW);2114 2115 2046 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 2116 2047 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 2, NULL, GL_DYNAMIC_DRAW); … … 2129 2060 points_vbo, 2130 2061 colors_vbo, 2131 selected_colors_vbo,2132 2062 texcoords_vbo, 2133 2063 normals_vbo, … … 2142 2072 GLuint points_vbo, 2143 2073 GLuint colors_vbo, 2144 GLuint selected_colors_vbo,2145 2074 GLuint texcoords_vbo, 2146 2075 GLuint normals_vbo, … … 2172 2101 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2173 2102 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]); 2174 2175 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo);2176 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]);2177 2103 2178 2104 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); … … 2358 2284 2359 2285 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2360 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 2361 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 2362 GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo, 2363 SceneObject* selectedObject) { 2364 2365 glUseProgram(color_sp); 2366 glBindVertexArray(color_vao); 2367 2368 /* 2369 if (selectedObject != NULL) { 2370 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2371 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2372 2373 glDrawArrays(GL_TRIANGLES, selectedObject->vertex_vbo_offset, selectedObject->num_points); 2374 } 2375 */ 2376 2377 // Uncomment this code when I want to use selected colors again 2378 // glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2379 // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2380 2381 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[color_sp].vbo_base, shaderBufferInfo[color_sp].vbo_offset); 2286 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp, GLuint explosion_sp, 2287 GLuint ship_vao, GLuint asteroid_vao, GLuint laser_vao, GLuint explosion_vao, 2288 GLuint colors_vbo, GLuint ubo, SceneObject* selectedObject) { 2289 2290 glUseProgram(ship_sp); 2291 glBindVertexArray(ship_vao); 2292 2293 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[ship_sp].vbo_base, shaderBufferInfo[ship_sp].vbo_offset); 2382 2294 2383 2295 glUseProgram(asteroid_sp); … … 2386 2298 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[asteroid_sp].vbo_base, shaderBufferInfo[asteroid_sp].vbo_offset); 2387 2299 2388 glUseProgram(texture_sp);2389 glBindVertexArray(texture_vao);2390 2391 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[texture_sp].vbo_base, shaderBufferInfo[texture_sp].vbo_offset);2392 2393 2300 glEnable(GL_BLEND); 2394 2301 … … 2397 2304 2398 2305 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2306 2307 // To render explosions, my new shader descriptor object needs to have a refernece to the shader and the vao 2308 // and know the number of points to render. 2399 2309 2400 2310 glUseProgram(explosion_sp); … … 2616 2526 }; 2617 2527 obj->texcoords = { 0.0f }; 2618 obj->selected_colors = { 0.0f };2619 2528 2620 2529 mat4 T = translate(mat4(1.0f), pos);
Note:
See TracChangeset
for help on using the changeset viewer.