Changeset 646f3f2 in opengl-game
- Timestamp:
- Jan 30, 2019, 3:10:23 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 39ac76d
- Parents:
- fe5e3ca
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
explosion.vert
rfe5e3ca r646f3f2 5 5 uniform mat4 view, proj; 6 6 uniform mat4 model_mat; 7 8 /*9 7 layout (std140) uniform models { 10 8 mat4 model_mats[MAX_NUM_OBJECTS]; 11 9 }; 12 */13 10 14 11 uniform float explosion_start_time; … … 43 40 p += normalize(v_i) * mod(t, duration) / duration * 0.3; // allow time to loop around so particle emitter keeps going 44 41 45 //gl_Position = proj * view * model_mats[ 0] * vec4(p, 1.0);46 gl_Position = proj * view * model_mat * vec4(p, 1.0);42 //gl_Position = proj * view * model_mats[ubo_index] * vec4(p, 1.0); 43 gl_Position = proj * view * model_mats[0] * vec4(p, 1.0); 47 44 gl_PointSize = 15.0; // size in pixels 48 45 } -
new-game.cpp
rfe5e3ca r646f3f2 50 50 TYPE_ASTEROID, 51 51 TYPE_LASER, 52 TYPE_EXPLOSION, 52 53 }; 53 54 … … 157 158 GLuint* model_mat_idx_vbo); 158 159 159 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp); 160 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp, 161 map<GLuint, BufferInfo>& shaderBufferInfo, 162 GLuint points_vbo, 163 GLuint colors_vbo, 164 GLuint selected_colors_vbo, 165 GLuint texcoords_vbo, 166 GLuint normals_vbo, 167 GLuint ubo, 168 GLuint model_mat_idx_vbo); 160 169 161 170 void populateBuffers(vector<SceneObject*>& objects, … … 183 192 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); 184 193 194 // TODO: instead of using these methods, create constructors for these 185 195 SceneObject* createShip(GLuint shader); 186 196 Asteroid* createAsteroid(vec3 pos, GLuint shader); 187 197 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp); 198 SceneObject* createExplosion(GLuint shader); 188 199 189 200 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo); … … 197 208 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 198 209 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 199 GLuint colors_vbo, GLuint selected_colors_vbo, 210 GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo, 200 211 SceneObject* selectedObject); 201 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex);202 212 203 213 void renderSceneGui(); … … 248 258 Laser* rightLaser = NULL; 249 259 EffectOverTime* rightLaserEffect = NULL; 260 261 SceneObject* objExplosion; 262 SceneObject* objFirst; 250 263 251 264 /* … … 450 463 shaderBufferInfo[texture_sp] = BufferInfo(); 451 464 shaderBufferInfo[laser_sp] = BufferInfo(); 465 shaderBufferInfo[explosion_sp] = BufferInfo(); 452 466 453 467 cam_pos = vec3(0.0f, 0.0f, 2.0f); … … 494 508 495 509 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 496 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);510 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 497 511 498 512 // Comment these two lines out when I want to use selected colors 499 513 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 500 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);514 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 501 515 502 516 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 503 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);517 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL); 504 518 505 519 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 506 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);520 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL); 507 521 508 522 GLuint asteroid_vao = 0; … … 516 530 517 531 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 518 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);532 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 519 533 520 534 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 521 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);535 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 522 536 523 537 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 524 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);538 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL); 525 539 526 540 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 527 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);541 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL); 528 542 529 543 GLuint texture_vao = 0; … … 537 551 538 552 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 539 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);553 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 540 554 541 555 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 542 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);556 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 543 557 544 558 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 545 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);559 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL); 546 560 547 561 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 548 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);562 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL); 549 563 550 564 GLuint laser_vao = 0; … … 557 571 558 572 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 559 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);573 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 560 574 561 575 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 562 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);576 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 563 577 564 578 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 565 glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, 0);579 glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, NULL); 566 580 567 581 float cam_speed = 1.0f; … … 597 611 proj_mat = make_mat4(proj_arr); 598 612 599 GLuint explosion_vao = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, explosion_sp); 613 GLuint explosion_vao = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, 614 explosion_sp, 615 shaderBufferInfo, 616 points_vbo, 617 colors_vbo, 618 selected_colors_vbo, 619 texcoords_vbo, 620 normals_vbo, 621 ubo, 622 model_mat_idx_vbo); 600 623 601 624 GLuint ub_binding_point = 0; … … 621 644 GLuint explosion_start_time_loc = glGetUniformLocation(explosion_sp, "explosion_start_time"); 622 645 GLuint cur_time_loc = glGetUniformLocation(explosion_sp, "cur_time"); 646 GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex(explosion_sp, "models"); 623 647 624 648 … … 653 677 654 678 glUniformBlockBinding(laser_sp, laser_sp_models_ub_index, ub_binding_point); 679 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 680 681 682 glUseProgram(explosion_sp); 683 glUniformBlockBinding(explosion_sp, explosion_sp_models_ub_index, ub_binding_point); 655 684 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 656 685 … … 825 854 removeObjectFromScene(*objects[i], ubo); 826 855 } 856 // MARKER: Continue code review from here 827 857 if (((Asteroid*)objects[i])->hp <= 0) { 858 // TODO: Optimize this so I don't recalculate the camera rotation every time 859 float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f; 860 mat4 pitch_mat = rotate(mat4(1.0f), cam_pitch, vec3(1.0f, 0.0f, 0.0f)); 861 mat4 model_mat = translate(mat4(1.0f), objects[i]->bounding_center + vec3(0.0f, 0.0f, 0.0f)) * pitch_mat; 862 828 863 removeObjectFromScene(*objects[i], ubo); 829 864 score++; 830 865 831 // render an explosion 866 objExplosion->model_mat = model_mat; 867 868 // initiate an explosion 832 869 glUseProgram(explosion_sp); 870 871 GLuint model_mat_loc = glGetUniformLocation(explosion_sp, "model_mat"); 872 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objExplosion->model_mat)); 873 833 874 glUniform1f(explosion_start_time_loc, (GLfloat)glfwGetTime()); 834 cout << "REMOVED" << endl;835 cout << i << endl;836 875 } 837 876 } … … 944 983 color_sp, asteroid_sp, texture_sp, laser_sp, explosion_sp, 945 984 color_vao, asteroid_vao, texture_vao, laser_vao, explosion_vao, 946 colors_vbo, selected_colors_vbo, 985 colors_vbo, selected_colors_vbo, ubo, 947 986 selectedObject); 948 987 renderSceneGui(); … … 1288 1327 } 1289 1328 1290 if (obj->type != TYPE_LASER) {1329 if (obj->type == TYPE_SHIP || obj->type == TYPE_ASTEROID) { 1291 1330 calculateObjectBoundingBox(obj); 1292 1331 … … 1311 1350 // Check if the buffers aren't large enough to fit the new object and, if so, call 1312 1351 // populateBuffers() to resize and repopupulate them 1313 if (bufferInfo->vbo_capacity < (bufferInfo-> ubo_offset + obj->num_points) ||1352 if (bufferInfo->vbo_capacity < (bufferInfo->vbo_offset + obj->num_points) || 1314 1353 bufferInfo->ubo_capacity < (bufferInfo->ubo_offset + 1)) { 1315 1354 … … 1805 1844 */ 1806 1845 // TODO: Make the color parameter have an effect 1807 // TODO: Come up with a better way of passing the object back than copying it1808 1846 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp) { 1809 1847 Laser* obj = new Laser(); … … 1912 1950 } 1913 1951 1914 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp) { 1915 //unsigned int num_explosions = 1; 1916 1952 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp, 1953 map<GLuint, BufferInfo>& shaderBufferInfo, 1954 GLuint points_vbo, 1955 GLuint colors_vbo, 1956 GLuint selected_colors_vbo, 1957 GLuint texcoords_vbo, 1958 GLuint normals_vbo, 1959 GLuint ubo, 1960 GLuint model_mat_idx_vbo) { 1917 1961 float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3 1918 1962 float vt[EXPLOSION_PARTICLE_COUNT]; // initial times … … 1944 1988 glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat)); 1945 1989 1946 /*1947 GLuint model_ubo = 0;1948 glGenBuffers(1, &model_ubo);1949 1950 glBindBuffer(GL_UNIFORM_BUFFER, model_ubo);1951 glBufferData(GL_UNIFORM_BUFFER, num_explosions * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);1952 1953 //glBindBuffer(GL_UNIFORM_BUFFER, ubo);1954 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(model_mat));1955 */1956 1957 1990 GLuint velocity_vbo; 1958 1991 glGenBuffers(1, &velocity_vbo); … … 1969 2002 glBindVertexArray(vao); 1970 2003 2004 glEnableVertexAttribArray(0); 2005 glEnableVertexAttribArray(1); 2006 1971 2007 glBindBuffer(GL_ARRAY_BUFFER, velocity_vbo); 1972 2008 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); … … 1975 2011 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL); 1976 2012 1977 glEnableVertexAttribArray(0); 1978 glEnableVertexAttribArray(1); 2013 objExplosion = createExplosion(explosion_sp); 2014 addObjectToScene(objExplosion, shaderBufferInfo, 2015 points_vbo, 2016 colors_vbo, 2017 selected_colors_vbo, 2018 texcoords_vbo, 2019 normals_vbo, 2020 ubo, 2021 model_mat_idx_vbo, 2022 0); 1979 2023 1980 2024 return vao; … … 1996 2040 map<GLuint, unsigned int> shaderCounts; 1997 2041 map<GLuint, unsigned int> shaderUboCounts; 2042 2043 map<GLuint, BufferInfo>::iterator shaderIt; 2044 2045 for (shaderIt = shaderBufferInfo.begin(); shaderIt != shaderBufferInfo.end(); shaderIt++) { 2046 shaderCounts[shaderIt->first] = 0; 2047 shaderUboCounts[shaderIt->first] = 0; 2048 } 1998 2049 1999 2050 vector<SceneObject*>::iterator it; … … 2013 2064 num_objects++; 2014 2065 2015 if (shaderCounts.count((*it)->shader_program) == 0) { 2016 shaderCounts[(*it)->shader_program] = (*it)->num_points; 2017 shaderUboCounts[(*it)->shader_program] = 1; 2018 } else { 2019 shaderCounts[(*it)->shader_program] += (*it)->num_points; 2020 shaderUboCounts[(*it)->shader_program]++; 2021 } 2066 shaderCounts[(*it)->shader_program] += (*it)->num_points; 2067 shaderUboCounts[(*it)->shader_program]++; 2022 2068 2023 2069 it++; … … 2029 2075 num_objects *= 2; 2030 2076 2031 map<GLuint, unsigned int>::iterator shader It;2077 map<GLuint, unsigned int>::iterator shaderCountIt; 2032 2078 unsigned int lastShaderCount = 0; 2033 2079 unsigned int lastShaderUboCount = 0; … … 2040 2086 * object being added. 2041 2087 */ 2042 for (shader It = shaderCounts.begin(); shaderIt != shaderCounts.end(); shaderIt++) {2088 for (shaderCountIt = shaderCounts.begin(); shaderCountIt != shaderCounts.end(); shaderCountIt++) { 2043 2089 // When populating the buffers, leave as much empty space as space taken up by existing objects 2044 2090 // to allow new objects to be added without immediately having to resize the buffers 2045 shaderBufferInfo[shaderIt->first].vbo_base = lastShaderCount * 2; 2046 shaderBufferInfo[shaderIt->first].ubo_base = lastShaderUboCount * 2; 2047 2048 /* 2049 cout << "shader: " << shaderIt->first << endl; 2050 cout << "point counts: " << shaderCounts[shaderIt->first] << endl; 2051 cout << "object counts: " << shaderUboCounts[shaderIt->first] << endl; 2052 cout << "vbo_base: " << shaderBufferInfo[shaderIt->first].vbo_base << endl; 2053 cout << "ubo_base: " << shaderBufferInfo[shaderIt->first].ubo_base << endl; 2054 */ 2055 2056 shaderBufferInfo[shaderIt->first].vbo_offset = 0; 2057 shaderBufferInfo[shaderIt->first].ubo_offset = 0; 2058 2059 shaderBufferInfo[shaderIt->first].vbo_capacity = shaderCounts[shaderIt->first] * 2; 2060 shaderBufferInfo[shaderIt->first].ubo_capacity = shaderUboCounts[shaderIt->first] * 2; 2061 2062 lastShaderCount += shaderCounts[shaderIt->first]; 2063 lastShaderUboCount += shaderUboCounts[shaderIt->first]; 2091 shaderBufferInfo[shaderCountIt->first].vbo_base = lastShaderCount * 2; 2092 shaderBufferInfo[shaderCountIt->first].ubo_base = lastShaderUboCount * 2; 2093 2094 shaderBufferInfo[shaderCountIt->first].vbo_offset = 0; 2095 shaderBufferInfo[shaderCountIt->first].ubo_offset = 0; 2096 2097 shaderBufferInfo[shaderCountIt->first].vbo_capacity = shaderCounts[shaderCountIt->first] * 2; 2098 shaderBufferInfo[shaderCountIt->first].ubo_capacity = shaderUboCounts[shaderCountIt->first] * 2; 2099 2100 lastShaderCount += shaderCounts[shaderCountIt->first]; 2101 lastShaderUboCount += shaderUboCounts[shaderCountIt->first]; 2064 2102 } 2065 2103 … … 2115 2153 obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset; 2116 2154 2117 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 2118 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); 2119 2120 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 2121 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]); 2122 2123 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 2124 for (unsigned int i = 0; i < obj.num_points; i++) { 2125 glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset); 2126 } 2127 2128 if (obj.type != TYPE_LASER) { 2129 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2130 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]); 2131 2132 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2133 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]); 2134 2135 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 2136 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.normals.size() * sizeof(GLfloat), &obj.normals[0]); 2137 } 2138 2139 obj.model_mat = obj.model_transform * obj.model_base; 2140 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2141 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 2142 2143 if (obj.type == TYPE_ASTEROID) { 2144 glUseProgram(asteroid_sp); 2145 2146 ostringstream oss; 2147 oss << "hp[" << obj.ubo_offset << "]"; 2148 glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp); 2155 if (obj.ubo_offset == 0) { 2156 objFirst = &obj; 2157 } 2158 2159 if (obj.type != TYPE_EXPLOSION) { 2160 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 2161 for (unsigned int i = 0; i < obj.num_points; i++) { 2162 glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset); 2163 } 2164 2165 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 2166 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]); 2167 2168 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 2169 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]); 2170 2171 if (obj.type != TYPE_LASER) { 2172 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2173 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 2178 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 2179 glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.normals.size() * sizeof(GLfloat), &obj.normals[0]); 2180 } 2181 2182 obj.model_mat = obj.model_transform * obj.model_base; 2183 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2184 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 2185 2186 if (obj.type == TYPE_ASTEROID) { 2187 glUseProgram(asteroid_sp); 2188 2189 ostringstream oss; 2190 oss << "hp[" << obj.ubo_offset << "]"; 2191 glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp); 2192 } 2149 2193 } 2150 2194 … … 2316 2360 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 2317 2361 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 2318 GLuint colors_vbo, GLuint selected_colors_vbo, 2362 GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo, 2319 2363 SceneObject* selectedObject) { 2320 2364 … … 2325 2369 if (selectedObject != NULL) { 2326 2370 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 2327 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);2371 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2328 2372 2329 2373 glDrawArrays(GL_TRIANGLES, selectedObject->vertex_vbo_offset, selectedObject->num_points); … … 2333 2377 // Uncomment this code when I want to use selected colors again 2334 2378 // glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2335 // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);2379 // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 2336 2380 2337 2381 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[color_sp].vbo_base, shaderBufferInfo[color_sp].vbo_offset); … … 2354 2398 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2355 2399 2356 glDisable(GL_BLEND); 2357 2358 renderExplosion(explosion_sp, explosion_vao, 0); 2359 } 2360 2361 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex) { 2362 glEnable(GL_BLEND); 2400 glUseProgram(explosion_sp); 2401 2363 2402 glEnable(GL_PROGRAM_POINT_SIZE); 2364 2365 //glActiveTexture(GL_TEXTURE1);2366 //glBindTexture(GL_TEXTURE_2D, tex);2367 glUseProgram(explosion_sp);2368 2369 2403 glBindVertexArray(explosion_vao); 2370 2404 2371 glDrawArrays(GL_POINTS, 0, EXPLOSION_PARTICLE_COUNT); 2405 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2406 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objExplosion->model_mat)); 2407 2408 glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_sp].vbo_offset); 2409 2410 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2411 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objFirst->model_mat)); 2372 2412 2373 2413 glDisable(GL_PROGRAM_POINT_SIZE); … … 2474 2514 Asteroid* obj = new Asteroid(); 2475 2515 obj->type = TYPE_ASTEROID; 2516 obj->shader_program = shader; 2476 2517 obj->hp = 10.0f; 2477 obj->shader_program = shader;2478 2518 2479 2519 obj->points = { … … 2595 2635 } 2596 2636 2637 SceneObject* createExplosion(GLuint shader) { 2638 SceneObject* obj = new SceneObject(); 2639 obj->type = TYPE_EXPLOSION; 2640 obj->shader_program = shader; 2641 2642 obj->points = {}; 2643 obj->colors = {}; 2644 2645 initObject(obj); 2646 obj->num_points = EXPLOSION_PARTICLE_COUNT; 2647 2648 return obj; 2649 } 2650 2597 2651 float getRandomNum(float low, float high) { 2598 2652 return low + ((float)rand()/RAND_MAX) * (high-low);
Note:
See TracChangeset
for help on using the changeset viewer.