Changes in / [ae0c7f4:bebfd5c] in opengl-game
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
explosion.vert
rae0c7f4 rbebfd5c 41 41 42 42 //gl_Position = proj * view * model_mats[ubo_index] * vec4(p, 1.0); 43 gl_Position = proj * view * model_mat s[0]* vec4(p, 1.0);43 gl_Position = proj * view * model_mat * vec4(p, 1.0); 44 44 gl_PointSize = 15.0; // size in pixels 45 45 } -
new-game.cpp
rae0c7f4 rbebfd5c 70 70 vector<GLfloat> texcoords; 71 71 vector<GLfloat> normals; 72 vector<GLfloat> selected_colors; 72 73 bool deleted; 73 74 vec3 bounding_center; … … 91 92 SceneObject* effectedObject; 92 93 93 // TODO: Why not just use an initializer list for all the instance variables94 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 GLuint texcoords_vbo, 143 GLuint normals_vbo, 144 GLuint ubo, 145 GLuint model_mat_idx_vbo, 146 GLuint asteroid_sp, 147 GLuint explosion_sp); 148 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 149 150 void calculateObjectBoundingBox(SceneObject* obj); 151 152 void initializeBuffers( 153 GLuint* points_vbo, 154 GLuint* colors_vbo, 155 GLuint* selected_colors_vbo, 156 GLuint* texcoords_vbo, 157 GLuint* normals_vbo, 158 GLuint* ubo, 159 GLuint* model_mat_idx_vbo); 160 161 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp, 162 map<GLuint, BufferInfo>& shaderBufferInfo, 163 GLuint points_vbo, 164 GLuint colors_vbo, 165 GLuint selected_colors_vbo, 166 GLuint texcoords_vbo, 167 GLuint normals_vbo, 168 GLuint ubo, 169 GLuint model_mat_idx_vbo); 170 171 void populateBuffers(vector<SceneObject*>& objects, 172 map<GLuint, BufferInfo>& shaderBufferInfo, 173 GLuint points_vbo, 174 GLuint colors_vbo, 175 GLuint selected_colors_vbo, 176 GLuint texcoords_vbo, 177 GLuint normals_vbo, 178 GLuint ubo, 179 GLuint model_mat_idx_vbo, 180 GLuint asteroid_sp, 181 GLuint explosion_sp); 182 183 void copyObjectDataToBuffers(SceneObject& obj, 184 map<GLuint, BufferInfo>& shaderBufferInfo, 185 GLuint points_vbo, 186 GLuint colors_vbo, 187 GLuint selected_colors_vbo, 141 188 GLuint texcoords_vbo, 142 189 GLuint normals_vbo, … … 144 191 GLuint model_mat_idx_vbo, 145 192 GLuint asteroid_sp); 146 void removeObjectFromScene(SceneObject& obj, GLuint ubo);147 148 void calculateObjectBoundingBox(SceneObject* obj);149 150 void initializeBuffers(151 GLuint* points_vbo,152 GLuint* colors_vbo,153 GLuint* texcoords_vbo,154 GLuint* normals_vbo,155 GLuint* ubo,156 GLuint* model_mat_idx_vbo);157 158 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,159 map<GLuint, BufferInfo>& shaderBufferInfo,160 GLuint points_vbo,161 GLuint colors_vbo,162 GLuint texcoords_vbo,163 GLuint normals_vbo,164 GLuint ubo,165 GLuint model_mat_idx_vbo);166 167 void populateBuffers(vector<SceneObject*>& objects,168 map<GLuint, BufferInfo>& shaderBufferInfo,169 GLuint points_vbo,170 GLuint colors_vbo,171 GLuint texcoords_vbo,172 GLuint normals_vbo,173 GLuint ubo,174 GLuint model_mat_idx_vbo,175 GLuint asteroid_sp);176 177 void copyObjectDataToBuffers(SceneObject& obj,178 map<GLuint, BufferInfo>& shaderBufferInfo,179 GLuint points_vbo,180 GLuint colors_vbo,181 GLuint texcoords_vbo,182 GLuint normals_vbo,183 GLuint ubo,184 GLuint model_mat_idx_vbo,185 GLuint asteroid_sp);186 193 187 194 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); 188 195 189 // TODO:instead of using these methods, create constructors for these196 // instead of using these methods, create constructors for these 190 197 SceneObject* createShip(GLuint shader); 191 198 Asteroid* createAsteroid(vec3 pos, GLuint shader); … … 201 208 202 209 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 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); 210 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 211 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 212 GLuint colors_vbo, GLuint selected_colors_vbo, 213 SceneObject* selectedObject); 206 214 207 215 void renderSceneGui(); … … 254 262 255 263 SceneObject* objExplosion; 256 SceneObject* objFirst; 264 SceneObject* objFirst; // TODO: Set this, probably in populateBuffers and wherever else is appropriate. 257 265 258 266 /* … … 445 453 map<GLuint, BufferInfo> shaderBufferInfo; 446 454 447 GLuint ship_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 455 // TODO: Rename color_sp to ship_sp and comment out texture_sp) 456 457 GLuint color_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 448 458 GLuint asteroid_sp = loadShaderProgram("./asteroid.vert", "./asteroid.frag"); 459 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag"); 449 460 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 450 461 GLuint explosion_sp = loadShaderProgram("./explosion.vert", "./explosion.frag"); 451 462 452 shaderBufferInfo[ ship_sp] = BufferInfo();463 shaderBufferInfo[color_sp] = BufferInfo(); 453 464 shaderBufferInfo[asteroid_sp] = BufferInfo(); 465 shaderBufferInfo[texture_sp] = BufferInfo(); 454 466 shaderBufferInfo[laser_sp] = BufferInfo(); 455 467 shaderBufferInfo[explosion_sp] = BufferInfo(); … … 460 472 461 473 // player ship 462 SceneObject* ship = createShip( ship_sp);474 SceneObject* ship = createShip(color_sp); 463 475 objects.push_back(ship); 464 476 465 477 vector<SceneObject>::iterator obj_it; 466 478 467 GLuint points_vbo, colors_vbo, texcoords_vbo, normals_vbo, ubo, model_mat_idx_vbo; 479 GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo, 480 normals_vbo, ubo, model_mat_idx_vbo; 468 481 469 482 initializeBuffers( 470 483 &points_vbo, 471 484 &colors_vbo, 485 &selected_colors_vbo, 472 486 &texcoords_vbo, 473 487 &normals_vbo, … … 479 493 points_vbo, 480 494 colors_vbo, 495 selected_colors_vbo, 481 496 texcoords_vbo, 482 497 normals_vbo, 483 498 ubo, 484 499 model_mat_idx_vbo, 485 asteroid_sp); 486 487 GLuint ship_vao = 0; 488 glGenVertexArrays(1, &ship_vao); 489 glBindVertexArray(ship_vao); 500 asteroid_sp, 501 explosion_sp); 502 503 GLuint color_vao = 0; 504 glGenVertexArrays(1, &color_vao); 505 glBindVertexArray(color_vao); 490 506 491 507 glEnableVertexAttribArray(0); … … 521 537 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 522 538 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 539 540 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 541 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL); 542 543 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 544 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL); 545 546 GLuint texture_vao = 0; 547 glGenVertexArrays(1, &texture_vao); 548 glBindVertexArray(texture_vao); 549 550 glEnableVertexAttribArray(0); 551 glEnableVertexAttribArray(1); 552 glEnableVertexAttribArray(2); 553 glEnableVertexAttribArray(3); 554 555 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 556 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 557 558 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 559 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 523 560 524 561 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); … … 582 619 points_vbo, 583 620 colors_vbo, 621 selected_colors_vbo, 584 622 texcoords_vbo, 585 623 normals_vbo, … … 623 661 GLuint ub_binding_point = 0; 624 662 625 GLuint ship_view_mat_loc = glGetUniformLocation(ship_sp, "view"); 626 GLuint ship_proj_mat_loc = glGetUniformLocation(ship_sp, "proj"); 627 GLuint ship_sp_models_ub_index = glGetUniformBlockIndex(ship_sp, "models"); 663 // TODO: Replace test_loc and mat_loc with more descriptive names 664 GLuint view_test_loc = glGetUniformLocation(color_sp, "view"); 665 GLuint proj_test_loc = glGetUniformLocation(color_sp, "proj"); 666 GLuint color_sp_models_ub_index = glGetUniformBlockIndex(color_sp, "models"); 628 667 629 668 GLuint asteroid_view_mat_loc = glGetUniformLocation(asteroid_sp, "view"); 630 669 GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj"); 631 670 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models"); 671 672 GLuint view_mat_loc = glGetUniformLocation(texture_sp, "view"); 673 GLuint proj_mat_loc = glGetUniformLocation(texture_sp, "proj"); 674 GLuint texture_sp_models_ub_index = glGetUniformBlockIndex(texture_sp, "models"); 632 675 633 676 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); … … 641 684 642 685 643 glUseProgram( ship_sp);644 glUniformMatrix4fv( ship_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));645 glUniformMatrix4fv( ship_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));646 647 glUniformBlockBinding( ship_sp, ship_sp_models_ub_index, ub_binding_point);686 glUseProgram(color_sp); 687 glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat)); 688 glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat)); 689 690 glUniformBlockBinding(color_sp, color_sp_models_ub_index, ub_binding_point); 648 691 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 649 692 … … 654 697 655 698 glUniformBlockBinding(asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point); 699 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 700 701 702 glUseProgram(texture_sp); 703 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 704 glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 705 706 glUniformBlockBinding(texture_sp, texture_sp_models_ub_index, ub_binding_point); 656 707 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 657 708 … … 742 793 points_vbo, 743 794 colors_vbo, 795 selected_colors_vbo, 744 796 texcoords_vbo, 745 797 normals_vbo, 746 798 ubo, 747 799 model_mat_idx_vbo, 748 asteroid_sp); 800 asteroid_sp, 801 explosion_sp); 749 802 750 803 elapsed_seconds_spawn -= 0.5f; … … 801 854 points_vbo, 802 855 colors_vbo, 856 selected_colors_vbo, 803 857 texcoords_vbo, 804 858 normals_vbo, 805 859 ubo, 806 860 model_mat_idx_vbo, 807 asteroid_sp); 861 asteroid_sp, 862 explosion_sp); 808 863 } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) { 809 864 removeObjectFromScene(*leftLaser, ubo); … … 818 873 points_vbo, 819 874 colors_vbo, 875 selected_colors_vbo, 820 876 texcoords_vbo, 821 877 normals_vbo, 822 878 ubo, 823 879 model_mat_idx_vbo, 824 asteroid_sp); 880 asteroid_sp, 881 explosion_sp); 825 882 } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) { 826 883 removeObjectFromScene(*rightLaser, ubo); … … 838 895 } 839 896 if (((Asteroid*)objects[i])->hp <= 0) { 897 printVector("center", objects[i]->bounding_center); 898 840 899 // TODO: Optimize this so I don't recalculate the camera rotation every time 841 900 float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f; … … 850 909 // initiate an explosion 851 910 glUseProgram(explosion_sp); 852 911 853 912 GLuint model_mat_loc = glGetUniformLocation(explosion_sp, "model_mat"); 854 913 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objExplosion->model_mat)); 855 914 915 // TODO: To get ubos working for the explosion, 916 // I need to calculate the correct ubo index for the model matrix 917 // Then I need to copy the matrix into the right place in the ubo and 918 // copy the index into the correct uniform 919 920 // STEP 1: Make sure the UBO offset for the explosion shader is correct 921 922 cout << "UBO OFFSET: " << objExplosion->ubo_offset << endl; 923 //glBindBuffer(GL_UNIFORM_BUFFER, ubo); 924 //glBufferSubData(GL_UNIFORM_BUFFER, objExplosion->ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(objExplosion->model_mat)); 925 856 926 glUniform1f(explosion_start_time_loc, (GLfloat)glfwGetTime()); 927 928 // generic code used to change a matrix in the ubo 929 // we need to know the matrix of the first object in the ubo so we can save it and move it back 930 // after the explosion is rendered 931 // However, that should be done in the render loop, not here 932 // Here, we are already saving the explosion model mat in objExplosion->model_mat, so that is all we need 933 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 934 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 857 935 } 858 936 } … … 937 1015 //printVector("cam pos", cam_pos); 938 1016 939 glUseProgram(ship_sp); 940 glUniformMatrix4fv(ship_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 1017 glUseProgram(color_sp); 1018 glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat)); 1019 1020 glUseProgram(texture_sp); 1021 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 941 1022 942 1023 glUseProgram(laser_sp); … … 960 1041 case STATE_GAME: 961 1042 renderScene(shaderBufferInfo, 962 ship_sp, asteroid_sp, laser_sp, explosion_sp, 963 ship_vao, asteroid_vao, laser_vao, explosion_vao, 964 colors_vbo, ubo, selectedObject); 1043 color_sp, asteroid_sp, texture_sp, laser_sp, explosion_sp, 1044 color_vao, asteroid_vao, texture_vao, laser_vao, explosion_vao, 1045 colors_vbo, selected_colors_vbo, 1046 selectedObject); 965 1047 renderSceneGui(); 966 1048 break; … … 1316 1398 GLuint points_vbo, 1317 1399 GLuint colors_vbo, 1400 GLuint selected_colors_vbo, 1318 1401 GLuint texcoords_vbo, 1319 1402 GLuint normals_vbo, 1320 1403 GLuint ubo, 1321 1404 GLuint model_mat_idx_vbo, 1322 GLuint asteroid_sp) { 1405 GLuint asteroid_sp, 1406 GLuint explosion_sp) { 1323 1407 objects.push_back(obj); 1324 1408 … … 1340 1424 points_vbo, 1341 1425 colors_vbo, 1426 selected_colors_vbo, 1342 1427 texcoords_vbo, 1343 1428 normals_vbo, 1344 1429 ubo, 1345 1430 model_mat_idx_vbo, 1346 asteroid_sp); 1431 asteroid_sp, 1432 explosion_sp); 1347 1433 } else { 1348 1434 copyObjectDataToBuffers(*objects.back(), shaderBufferInfo, 1349 1435 points_vbo, 1350 1436 colors_vbo, 1437 selected_colors_vbo, 1351 1438 texcoords_vbo, 1352 1439 normals_vbo, … … 1793 1880 }; 1794 1881 ship->texcoords = { 0.0f }; 1882 ship->selected_colors = { 0.0f }; 1795 1883 1796 1884 mat4 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)); … … 1897 1985 GLuint* points_vbo, 1898 1986 GLuint* colors_vbo, 1987 GLuint* selected_colors_vbo, 1899 1988 GLuint* texcoords_vbo, 1900 1989 GLuint* normals_vbo, … … 1907 1996 glGenBuffers(1, colors_vbo); 1908 1997 1998 *selected_colors_vbo = 0; 1999 glGenBuffers(1, selected_colors_vbo); 2000 1909 2001 *texcoords_vbo = 0; 1910 2002 glGenBuffers(1, texcoords_vbo); … … 1924 2016 GLuint points_vbo, 1925 2017 GLuint colors_vbo, 2018 GLuint selected_colors_vbo, 1926 2019 GLuint texcoords_vbo, 1927 2020 GLuint normals_vbo, 1928 2021 GLuint ubo, 1929 2022 GLuint model_mat_idx_vbo) { 2023 //unsigned int num_explosions = 1; 2024 1930 2025 float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3 1931 2026 float vt[EXPLOSION_PARTICLE_COUNT]; // initial times … … 1957 2052 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat)); 1958 2053 2054 /* 2055 GLuint model_ubo = 0; 2056 glGenBuffers(1, &model_ubo); 2057 2058 glBindBuffer(GL_UNIFORM_BUFFER, model_ubo); 2059 glBufferData(GL_UNIFORM_BUFFER, num_explosions * sizeof(mat4), NULL, GL_DYNAMIC_DRAW); 2060 2061 //glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2062 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(model_mat)); 2063 */ 2064 1959 2065 GLuint velocity_vbo; 1960 2066 glGenBuffers(1, &velocity_vbo); … … 1973 2079 glEnableVertexAttribArray(0); 1974 2080 glEnableVertexAttribArray(1); 2081 glEnableVertexAttribArray(2); 1975 2082 1976 2083 glBindBuffer(GL_ARRAY_BUFFER, velocity_vbo); … … 1980 2087 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL); 1981 2088 2089 // TODO: I think I can call glVertexAttribIPointer whenever the vbo_base changes 2090 // to rebind the ubo index vbo 2091 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 2092 glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, NULL); 2093 1982 2094 objExplosion = createExplosion(explosion_sp); 2095 objExplosion->num_points = EXPLOSION_PARTICLE_COUNT; 1983 2096 addObjectToScene(objExplosion, shaderBufferInfo, 1984 2097 points_vbo, 1985 2098 colors_vbo, 2099 selected_colors_vbo, 1986 2100 texcoords_vbo, 1987 2101 normals_vbo, 1988 2102 ubo, 1989 2103 model_mat_idx_vbo, 1990 0); 2104 0, 2105 explosion_sp); 1991 2106 1992 2107 return vao; … … 1997 2112 GLuint points_vbo, 1998 2113 GLuint colors_vbo, 2114 GLuint selected_colors_vbo, 1999 2115 GLuint texcoords_vbo, 2000 2116 GLuint normals_vbo, 2001 2117 GLuint ubo, 2002 2118 GLuint ubo_idx_vbo, 2003 GLuint asteroid_sp) { 2119 GLuint asteroid_sp, 2120 GLuint explosion_sp) { 2004 2121 GLsizeiptr num_points = 0; 2005 2122 GLsizeiptr num_objects = 0; … … 2059 2176 shaderBufferInfo[shaderCountIt->first].ubo_base = lastShaderUboCount * 2; 2060 2177 2178 if (shaderCountIt->first == explosion_sp) { 2179 cout << "EXPLOSION VBO_BASE: " << shaderBufferInfo[shaderCountIt->first].vbo_base << endl; 2180 } 2181 2182 /* 2183 cout << "shader: " << shaderCountIt->first << endl; 2184 cout << "point counts: " << shaderCounts[shaderCountIt->first] << endl; 2185 cout << "object counts: " << shaderUboCounts[shaderCountIt->first] << endl; 2186 cout << "vbo_base: " << shaderBufferInfo[shaderCountIt->first].vbo_base << endl; 2187 cout << "ubo_base: " << shaderBufferInfo[shaderCountIt->first].ubo_base << endl; 2188 */ 2189 2061 2190 shaderBufferInfo[shaderCountIt->first].vbo_offset = 0; 2062 2191 shaderBufferInfo[shaderCountIt->first].ubo_offset = 0; … … 2075 2204 2076 2205 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2206 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2207 2208 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2077 2209 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2078 2210 … … 2093 2225 points_vbo, 2094 2226 colors_vbo, 2227 selected_colors_vbo, 2095 2228 texcoords_vbo, 2096 2229 normals_vbo, … … 2105 2238 GLuint points_vbo, 2106 2239 GLuint colors_vbo, 2240 GLuint selected_colors_vbo, 2107 2241 GLuint texcoords_vbo, 2108 2242 GLuint normals_vbo, … … 2115 2249 obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset; 2116 2250 2117 if (obj.ubo_offset == 0) { 2118 objFirst = &obj; 2251 if (obj.type == TYPE_EXPLOSION) { 2252 cout << "UBO OFFSET: " << obj.ubo_offset << endl; 2253 } 2254 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 2255 for (unsigned int i = 0; i < obj.num_points; i++) { 2256 glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset); 2119 2257 } 2120 2258 2121 2259 if (obj.type != TYPE_EXPLOSION) { 2122 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);2123 for (unsigned int i = 0; i < obj.num_points; i++) {2124 glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset);2125 }2126 2127 2260 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 2128 2261 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); … … 2134 2267 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2135 2268 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]); 2269 2270 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2271 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]); 2136 2272 2137 2273 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); … … 2317 2453 2318 2454 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2319 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp, GLuint explosion_sp, 2320 GLuint ship_vao, GLuint asteroid_vao, GLuint laser_vao, GLuint explosion_vao, 2321 GLuint colors_vbo, GLuint ubo, SceneObject* selectedObject) { 2322 2323 glUseProgram(ship_sp); 2324 glBindVertexArray(ship_vao); 2325 2326 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[ship_sp].vbo_base, shaderBufferInfo[ship_sp].vbo_offset); 2455 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 2456 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 2457 GLuint colors_vbo, GLuint selected_colors_vbo, 2458 SceneObject* selectedObject) { 2459 2460 glUseProgram(color_sp); 2461 glBindVertexArray(color_vao); 2462 2463 /* 2464 if (selectedObject != NULL) { 2465 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2466 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2467 2468 glDrawArrays(GL_TRIANGLES, selectedObject->vertex_vbo_offset, selectedObject->num_points); 2469 } 2470 */ 2471 2472 // Uncomment this code when I want to use selected colors again 2473 // glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2474 // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2475 2476 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[color_sp].vbo_base, shaderBufferInfo[color_sp].vbo_offset); 2327 2477 2328 2478 glUseProgram(asteroid_sp); … … 2331 2481 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[asteroid_sp].vbo_base, shaderBufferInfo[asteroid_sp].vbo_offset); 2332 2482 2483 glUseProgram(texture_sp); 2484 glBindVertexArray(texture_vao); 2485 2486 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[texture_sp].vbo_base, shaderBufferInfo[texture_sp].vbo_offset); 2487 2333 2488 glEnable(GL_BLEND); 2334 2489 … … 2338 2493 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2339 2494 2340 // To render explosions, my new shader descriptor object needs to have a refernece to the shader and the vao2341 // and know the number of points to render.2342 2343 2495 glUseProgram(explosion_sp); 2496 2497 //glActiveTexture(GL_TEXTURE1); 2498 //glBindTexture(GL_TEXTURE_2D, tex); // tex is 0 here 2344 2499 2345 2500 glEnable(GL_PROGRAM_POINT_SIZE); 2346 2501 glBindVertexArray(explosion_vao); 2347 2502 2348 glBindBuffer(GL_UNIFORM_BUFFER, ubo);2349 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objExplosion->model_mat));2350 2351 2503 glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_sp].vbo_offset); 2352 2353 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2354 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objFirst->model_mat)); 2504 //glDrawArrays(GL_POINTS, shaderBufferInfo[explosion_sp].vbo_base, shaderBufferInfo[explosion_sp].vbo_offset); 2505 //cout << shaderBufferInfo[explosion_sp].vbo_base << ", " << shaderBufferInfo[explosion_sp].vbo_offset << endl; 2355 2506 2356 2507 glDisable(GL_PROGRAM_POINT_SIZE); … … 2559 2710 }; 2560 2711 obj->texcoords = { 0.0f }; 2712 obj->selected_colors = { 0.0f }; 2561 2713 2562 2714 mat4 T = translate(mat4(1.0f), pos); … … 2586 2738 2587 2739 initObject(obj); 2588 obj->num_points = EXPLOSION_PARTICLE_COUNT;2589 2740 2590 2741 return obj;
Note:
See TracChangeset
for help on using the changeset viewer.