Changeset 0414306 in opengl-game
- Timestamp:
- Feb 6, 2019, 4:33:22 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 4c7cd57
- Parents:
- 7a55b49
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r7a55b49 r0414306 143 143 void addObjectToScene(SceneObject* obj, 144 144 map<GLuint, BufferInfo>& shaderBufferInfo, 145 map<ObjectType, ShaderModelGroup>& modelGroups, 145 146 GLuint points_vbo, 146 147 GLuint colors_vbo, … … 148 149 GLuint normals_vbo, 149 150 GLuint ubo, 150 GLuint model_mat_idx_vbo, 151 GLuint asteroid_sp); 151 GLuint model_mat_idx_vbo); 152 152 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 153 153 … … 166 166 GLuint* model_mat_idx_vbo); 167 167 168 ShaderModelGroup initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,168 void initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, 169 169 map<GLuint, BufferInfo>& shaderBufferInfo, 170 map<ObjectType, ShaderModelGroup>& modelGroups, 170 171 GLuint points_vbo, 171 172 GLuint colors_vbo, … … 177 178 void populateBuffers(vector<SceneObject*>& objects, 178 179 map<GLuint, BufferInfo>& shaderBufferInfo, 180 map<ObjectType, ShaderModelGroup>& modelGroups, 179 181 GLuint points_vbo, 180 182 GLuint colors_vbo, … … 182 184 GLuint normals_vbo, 183 185 GLuint ubo, 184 GLuint model_mat_idx_vbo, 185 GLuint asteroid_sp); 186 GLuint model_mat_idx_vbo); 186 187 187 188 void copyObjectDataToBuffers(SceneObject& obj, 188 189 map<GLuint, BufferInfo>& shaderBufferInfo, 190 map<ObjectType, ShaderModelGroup>& modelGroups, 189 191 GLuint points_vbo, 190 192 GLuint colors_vbo, … … 192 194 GLuint normals_vbo, 193 195 GLuint ubo, 194 GLuint model_mat_idx_vbo, 195 GLuint asteroid_sp); 196 GLuint model_mat_idx_vbo); 196 197 197 198 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); … … 210 211 void renderMainMenuGui(); 211 212 212 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, GLuint ubo,213 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp,214 GLuint ship_ vao, GLuint asteroid_vao, GLuint laser_vao,215 ShaderModelGroup& explosion_group);213 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 214 map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo, 215 GLuint ship_sp, GLuint laser_sp, 216 GLuint ship_vao, GLuint laser_vao); 216 217 217 218 void renderSceneGui(); … … 454 455 455 456 map<GLuint, BufferInfo> shaderBufferInfo; 457 map<ObjectType, ShaderModelGroup> modelGroups; 456 458 457 459 GLuint ship_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 458 GLuint asteroid_sp = loadShaderProgram("./asteroid.vert", "./asteroid.frag");459 460 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 460 GLuint explosion_sp = loadShaderProgram("./explosion.vert", "./explosion.frag");461 461 462 462 shaderBufferInfo[ship_sp] = BufferInfo(); 463 shaderBufferInfo[asteroid_sp] = BufferInfo();464 463 shaderBufferInfo[laser_sp] = BufferInfo(); 465 shaderBufferInfo[explosion_sp] = BufferInfo(); 464 465 modelGroups[TYPE_ASTEROID] = createModelGroup( 466 loadShaderProgram("./asteroid.vert", "./asteroid.frag")); 467 shaderBufferInfo[modelGroups[TYPE_ASTEROID].shaderProgram] = BufferInfo(); // temporary 468 modelGroups[TYPE_EXPLOSION] = createModelGroup( 469 loadShaderProgram("./explosion.vert", "./explosion.frag")); 470 shaderBufferInfo[modelGroups[TYPE_EXPLOSION].shaderProgram] = BufferInfo(); // temporary 466 471 467 472 cam_pos = vec3(0.0f, 0.0f, 2.0f); … … 486 491 487 492 populateBuffers(objects, 488 shaderBufferInfo, 493 shaderBufferInfo, modelGroups, 489 494 points_vbo, 490 495 colors_vbo, … … 492 497 normals_vbo, 493 498 ubo, 494 model_mat_idx_vbo, 495 asteroid_sp); 499 model_mat_idx_vbo); 496 500 497 501 GLuint ship_vao = 0; … … 517 521 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL); 518 522 519 GLuint asteroid_vao = 0; 520 glGenVertexArrays(1, &asteroid_vao); 521 glBindVertexArray(asteroid_vao); 523 glBindVertexArray(modelGroups[TYPE_ASTEROID].vao); 522 524 523 525 glEnableVertexAttribArray(0); … … 587 589 proj_mat = make_mat4(proj_arr); 588 590 589 ShaderModelGroup explosion_group = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, 590 explosion_sp, 591 initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, 591 592 shaderBufferInfo, 593 modelGroups, 592 594 points_vbo, 593 595 colors_vbo, … … 637 639 GLuint ship_sp_models_ub_index = glGetUniformBlockIndex(ship_sp, "models"); 638 640 639 GLuint asteroid_view_mat_loc = glGetUniformLocation( asteroid_sp, "view");640 GLuint asteroid_proj_mat_loc = glGetUniformLocation( asteroid_sp, "proj");641 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex( asteroid_sp, "models");641 GLuint asteroid_view_mat_loc = glGetUniformLocation(modelGroups[TYPE_ASTEROID].shaderProgram, "view"); 642 GLuint asteroid_proj_mat_loc = glGetUniformLocation(modelGroups[TYPE_ASTEROID].shaderProgram, "proj"); 643 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_ASTEROID].shaderProgram, "models"); 642 644 643 645 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); … … 646 648 GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(laser_sp, "models"); 647 649 648 GLuint explosion_start_time_loc = glGetUniformLocation( explosion_sp, "explosion_start_time");649 GLuint cur_time_loc = glGetUniformLocation( explosion_sp, "cur_time");650 GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex( explosion_sp, "models");650 GLuint explosion_start_time_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "explosion_start_time"); 651 GLuint cur_time_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "cur_time"); 652 GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_EXPLOSION].shaderProgram, "models"); 651 653 652 654 … … 659 661 660 662 661 glUseProgram( asteroid_sp);663 glUseProgram(modelGroups[TYPE_ASTEROID].shaderProgram); 662 664 glUniformMatrix4fv(asteroid_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 663 665 glUniformMatrix4fv(asteroid_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 664 666 665 glUniformBlockBinding( asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point);667 glUniformBlockBinding(modelGroups[TYPE_ASTEROID].shaderProgram, asteroid_sp_models_ub_index, ub_binding_point); 666 668 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 667 669 … … 676 678 677 679 678 glUseProgram( explosion_sp);679 glUniformBlockBinding( explosion_sp, explosion_sp_models_ub_index, ub_binding_point);680 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 681 glUniformBlockBinding(modelGroups[TYPE_EXPLOSION].shaderProgram, explosion_sp_models_ub_index, ub_binding_point); 680 682 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 681 683 … … 748 750 elapsed_seconds_spawn += elapsed_seconds; 749 751 if (elapsed_seconds_spawn > 0.5f) { 750 SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)), asteroid_sp);751 addObjectToScene(obj, shaderBufferInfo, 752 SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)), modelGroups[TYPE_ASTEROID].shaderProgram); 753 addObjectToScene(obj, shaderBufferInfo, modelGroups, 752 754 points_vbo, 753 755 colors_vbo, … … 755 757 normals_vbo, 756 758 ubo, 757 model_mat_idx_vbo, 758 asteroid_sp); 759 model_mat_idx_vbo); 759 760 760 761 elapsed_seconds_spawn -= 0.5f; … … 808 809 leftLaser = createLaser(vec3(-0.21f, -1.19f, 1.76f)+offset, vec3(-0.21f, -1.19f, -3.0f)+offset, 809 810 vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp); 810 addObjectToScene(leftLaser, shaderBufferInfo, 811 addObjectToScene(leftLaser, shaderBufferInfo, modelGroups, 811 812 points_vbo, 812 813 colors_vbo, … … 814 815 normals_vbo, 815 816 ubo, 816 model_mat_idx_vbo, 817 asteroid_sp); 817 model_mat_idx_vbo); 818 818 } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) { 819 819 removeObjectFromScene(*leftLaser, ubo); … … 825 825 rightLaser = createLaser(vec3(0.21f, -1.19f, 1.76f) + offset, vec3(0.21f, -1.19f, -3.0f) + offset, 826 826 vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp); 827 addObjectToScene(rightLaser, shaderBufferInfo, 827 addObjectToScene(rightLaser, shaderBufferInfo, modelGroups, 828 828 points_vbo, 829 829 colors_vbo, … … 831 831 normals_vbo, 832 832 ubo, 833 model_mat_idx_vbo, 834 asteroid_sp); 833 model_mat_idx_vbo); 835 834 } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) { 836 835 removeObjectFromScene(*rightLaser, ubo); … … 859 858 860 859 // initiate an explosion 861 glUseProgram( explosion_sp);862 863 GLuint model_mat_loc = glGetUniformLocation( explosion_sp, "model_mat");860 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 861 862 GLuint model_mat_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "model_mat"); 864 863 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objExplosion->model_mat)); 865 864 … … 870 869 871 870 if (leftLaser != NULL && !leftLaser->deleted) { 872 updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp);871 updateLaserTarget(leftLaser, objects, points_vbo, modelGroups[TYPE_ASTEROID].shaderProgram); 873 872 } 874 873 if (rightLaser != NULL && !rightLaser->deleted) { 875 updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp);874 updateLaserTarget(rightLaser, objects, points_vbo, modelGroups[TYPE_ASTEROID].shaderProgram); 876 875 } 877 876 } … … 956 955 } 957 956 958 glUseProgram( explosion_sp);957 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 959 958 glUniform1f(cur_time_loc, (GLfloat)current_seconds); 960 959 … … 969 968 break; 970 969 case STATE_GAME: 971 renderScene(shaderBufferInfo, ubo, 972 ship_sp, asteroid_sp, laser_sp, 973 ship_vao, asteroid_vao, laser_vao, 974 explosion_group); 970 renderScene(shaderBufferInfo, modelGroups, ubo, 971 ship_sp, laser_sp, 972 ship_vao, laser_vao); 975 973 renderSceneGui(); 976 974 break; … … 1324 1322 void addObjectToScene(SceneObject* obj, 1325 1323 map<GLuint, BufferInfo>& shaderBufferInfo, 1324 map<ObjectType, ShaderModelGroup>& modelGroups, 1326 1325 GLuint points_vbo, 1327 1326 GLuint colors_vbo, … … 1329 1328 GLuint normals_vbo, 1330 1329 GLuint ubo, 1331 GLuint model_mat_idx_vbo, 1332 GLuint asteroid_sp) { 1330 GLuint model_mat_idx_vbo) { 1333 1331 objects.push_back(obj); 1334 1332 1335 1333 BufferInfo* bufferInfo = &shaderBufferInfo[obj->shader_program]; 1334 1335 unsigned int numPoints = obj->type == TYPE_ASTEROID || obj->type == TYPE_EXPLOSION ? 1336 modelGroups[obj->type].numPoints : 1337 bufferInfo->vbo_offset; 1336 1338 1337 1339 // Check if the buffers aren't large enough to fit the new object and, if so, call 1338 1340 // populateBuffers() to resize and repopupulate them 1339 if (bufferInfo->vbo_capacity < ( bufferInfo->vbo_offset+ obj->num_points) ||1341 if (bufferInfo->vbo_capacity < (numPoints + obj->num_points) || 1340 1342 bufferInfo->ubo_capacity < (bufferInfo->ubo_offset + 1)) { 1341 1343 … … 1347 1349 } 1348 1350 1349 populateBuffers(objects, shaderBufferInfo, 1351 populateBuffers(objects, shaderBufferInfo, modelGroups, 1350 1352 points_vbo, 1351 1353 colors_vbo, … … 1353 1355 normals_vbo, 1354 1356 ubo, 1355 model_mat_idx_vbo, 1356 asteroid_sp); 1357 model_mat_idx_vbo); 1357 1358 } else { 1358 copyObjectDataToBuffers(*objects.back(), shaderBufferInfo, 1359 copyObjectDataToBuffers(*objects.back(), shaderBufferInfo, modelGroups, 1359 1360 points_vbo, 1360 1361 colors_vbo, … … 1362 1363 normals_vbo, 1363 1364 ubo, 1364 model_mat_idx_vbo, 1365 asteroid_sp); 1365 model_mat_idx_vbo); 1366 1366 } 1367 1367 } … … 1908 1908 1909 1909 smg.shaderProgram = shaderProgram; 1910 glGenVertexArrays(1, &smg.vao); 1911 smg.numPoints = 0; 1910 1912 1911 1913 return smg; … … 1946 1948 } 1947 1949 1948 ShaderModelGroup initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,1950 void initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, 1949 1951 map<GLuint, BufferInfo>& shaderBufferInfo, 1952 map<ObjectType, ShaderModelGroup>& modelGroups, 1950 1953 GLuint points_vbo, 1951 1954 GLuint colors_vbo, … … 1971 1974 mat4 model_mat = translate(mat4(1.0f), origin); 1972 1975 1973 ShaderModelGroup modelGroup; 1974 modelGroup.shaderProgram = explosion_sp; 1975 1976 glUseProgram(modelGroup.shaderProgram); 1977 1978 GLuint proj_mat_loc = glGetUniformLocation(explosion_sp, "proj"); 1979 GLuint view_mat_loc = glGetUniformLocation(explosion_sp, "view"); 1976 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 1977 1978 GLuint proj_mat_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "proj"); 1979 GLuint view_mat_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "view"); 1980 1980 1981 1981 glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj)); 1982 1982 glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view)); 1983 1983 1984 GLuint model_mat_loc = glGetUniformLocation( explosion_sp, "model_mat");1984 GLuint model_mat_loc = glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, "model_mat"); 1985 1985 1986 1986 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat)); … … 1996 1996 glBufferData(GL_ARRAY_BUFFER, sizeof(vt), vt, GL_STATIC_DRAW); 1997 1997 1998 glGenVertexArrays(1, &modelGroup.vao); 1999 glBindVertexArray(modelGroup.vao); 1998 glBindVertexArray(modelGroups[TYPE_EXPLOSION].vao); 2000 1999 2001 2000 glEnableVertexAttribArray(0); … … 2008 2007 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL); 2009 2008 2010 objExplosion = createExplosion(modelGroup .shaderProgram);2011 addObjectToScene(objExplosion, shaderBufferInfo, 2009 objExplosion = createExplosion(modelGroups[TYPE_EXPLOSION].shaderProgram); 2010 addObjectToScene(objExplosion, shaderBufferInfo, modelGroups, 2012 2011 points_vbo, 2013 2012 colors_vbo, … … 2015 2014 normals_vbo, 2016 2015 ubo, 2017 model_mat_idx_vbo, 2018 0); 2019 2020 return modelGroup; 2016 model_mat_idx_vbo); 2021 2017 } 2022 2018 2023 2019 void populateBuffers(vector<SceneObject*>& objects, 2024 2020 map<GLuint, BufferInfo>& shaderBufferInfo, 2021 map<ObjectType, ShaderModelGroup>& modelGroups, 2025 2022 GLuint points_vbo, 2026 2023 GLuint colors_vbo, … … 2028 2025 GLuint normals_vbo, 2029 2026 GLuint ubo, 2030 GLuint ubo_idx_vbo, 2031 GLuint asteroid_sp) { 2027 GLuint ubo_idx_vbo) { 2032 2028 GLsizeiptr num_points = 0; 2033 2029 GLsizeiptr num_objects = 0; … … 2087 2083 shaderBufferInfo[shaderCountIt->first].ubo_base = lastShaderUboCount * 2; 2088 2084 2089 shaderBufferInfo[shaderCountIt->first].vbo_offset = 0; 2085 if (shaderCountIt->first != modelGroups[TYPE_ASTEROID].shaderProgram && 2086 shaderCountIt->first != modelGroups[TYPE_EXPLOSION].shaderProgram) { 2087 shaderBufferInfo[shaderCountIt->first].vbo_offset = 0; 2088 } 2090 2089 shaderBufferInfo[shaderCountIt->first].ubo_offset = 0; 2091 2090 … … 2097 2096 } 2098 2097 2098 modelGroups[TYPE_ASTEROID].numPoints = 0; 2099 modelGroups[TYPE_EXPLOSION].numPoints = 0; 2100 2099 2101 // Allocate all the buffers using the counts calculated above 2100 2102 … … 2118 2120 2119 2121 for (it = objects.begin(); it != objects.end(); it++) { 2120 copyObjectDataToBuffers(**it, shaderBufferInfo, 2122 copyObjectDataToBuffers(**it, shaderBufferInfo, modelGroups, 2121 2123 points_vbo, 2122 2124 colors_vbo, … … 2124 2126 normals_vbo, 2125 2127 ubo, 2126 ubo_idx_vbo, 2127 asteroid_sp); 2128 ubo_idx_vbo); 2128 2129 } 2129 2130 } … … 2131 2132 void copyObjectDataToBuffers(SceneObject& obj, 2132 2133 map<GLuint, BufferInfo>& shaderBufferInfo, 2134 map<ObjectType, ShaderModelGroup>& modelGroups, 2133 2135 GLuint points_vbo, 2134 2136 GLuint colors_vbo, … … 2136 2138 GLuint normals_vbo, 2137 2139 GLuint ubo, 2138 GLuint model_mat_idx_vbo, 2139 GLuint asteroid_sp) { 2140 GLuint model_mat_idx_vbo) { 2140 2141 BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program]; 2141 2142 2142 obj.vertex_vbo_offset = bufferInfo->vbo_base + bufferInfo->vbo_offset; 2143 if (obj.type == TYPE_ASTEROID || obj.type == TYPE_EXPLOSION) { 2144 obj.vertex_vbo_offset = bufferInfo->vbo_base + modelGroups[obj.type].numPoints; 2145 } else { 2146 obj.vertex_vbo_offset = bufferInfo->vbo_base + bufferInfo->vbo_offset; 2147 } 2148 2143 2149 obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset; 2144 2150 … … 2172 2178 2173 2179 if (obj.type == TYPE_ASTEROID) { 2174 glUseProgram( asteroid_sp);2180 glUseProgram(modelGroups[TYPE_ASTEROID].shaderProgram); 2175 2181 2176 2182 ostringstream oss; 2177 2183 oss << "hp[" << obj.ubo_offset << "]"; 2178 glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp); 2179 } 2180 } 2181 2182 bufferInfo->vbo_offset += obj.num_points; 2184 glUniform1f(glGetUniformLocation(modelGroups[TYPE_ASTEROID].shaderProgram, oss.str().c_str()), ((Asteroid*)&obj)->hp); 2185 } 2186 } 2187 2188 if (obj.type == TYPE_ASTEROID || obj.type == TYPE_EXPLOSION) { 2189 modelGroups[obj.type].numPoints += obj.num_points; 2190 } else { 2191 bufferInfo->vbo_offset += obj.num_points; 2192 } 2183 2193 bufferInfo->ubo_offset++; 2184 2194 } … … 2344 2354 } 2345 2355 2346 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, GLuint ubo,2347 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp,2348 GLuint ship_ vao, GLuint asteroid_vao, GLuint laser_vao,2349 ShaderModelGroup& explosion_group) {2356 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2357 map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo, 2358 GLuint ship_sp, GLuint laser_sp, 2359 GLuint ship_vao, GLuint laser_vao) { 2350 2360 2351 2361 glUseProgram(ship_sp); … … 2354 2364 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[ship_sp].vbo_base, shaderBufferInfo[ship_sp].vbo_offset); 2355 2365 2356 glUseProgram( asteroid_sp);2357 glBindVertexArray( asteroid_vao);2358 2359 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[ asteroid_sp].vbo_base, shaderBufferInfo[asteroid_sp].vbo_offset);2366 glUseProgram(modelGroups[TYPE_ASTEROID].shaderProgram); 2367 glBindVertexArray(modelGroups[TYPE_ASTEROID].vao); 2368 2369 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[modelGroups[TYPE_ASTEROID].shaderProgram].vbo_base, modelGroups[TYPE_ASTEROID].numPoints); 2360 2370 2361 2371 glEnable(GL_BLEND); … … 2366 2376 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2367 2377 2368 // To render explosions, my new shader descriptor object needs to have a reference to the shader and the vao 2369 // and know the number of points to render. 2370 2371 glUseProgram(explosion_group.shaderProgram); 2378 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 2379 glBindVertexArray(modelGroups[TYPE_EXPLOSION].vao); 2372 2380 2373 2381 glEnable(GL_PROGRAM_POINT_SIZE); 2374 glBindVertexArray(explosion_group.vao);2375 2382 2376 2383 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2377 2384 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objExplosion->model_mat)); 2378 2385 2379 glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_group.shaderProgram].vbo_offset);2386 glDrawArrays(GL_POINTS, 0, modelGroups[TYPE_EXPLOSION].numPoints); 2380 2387 2381 2388 glBindBuffer(GL_UNIFORM_BUFFER, ubo);
Note:
See TracChangeset
for help on using the changeset viewer.