Changeset 25b47d7 in opengl-game for new-game.cpp
- Timestamp:
- Oct 17, 2018, 1:47:23 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1e3dddf, 8e8aed6
- Parents:
- 0e0f851
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r0e0f851 r25b47d7 142 142 GLuint normals_vbo, 143 143 GLuint ubo, 144 GLuint asteroid_hp_ubo,145 GLuint model_mat_idx_vbo);144 GLuint model_mat_idx_vbo, 145 GLuint asteroid_sp); 146 146 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 147 147 … … 155 155 GLuint* normals_vbo, 156 156 GLuint* ubo, 157 GLuint* asteroid_hp_ubo,158 157 GLuint* model_mat_idx_vbo); 159 158 … … 166 165 GLuint normals_vbo, 167 166 GLuint ubo, 168 GLuint asteroid_hp_ubo,169 GLuint model_mat_idx_vbo);167 GLuint model_mat_idx_vbo, 168 GLuint asteroid_sp); 170 169 171 170 void copyObjectDataToBuffers(SceneObject& obj, … … 177 176 GLuint normals_vbo, 178 177 GLuint ubo, 179 GLuint asteroid_hp_ubo,180 GLuint model_mat_idx_vbo);178 GLuint model_mat_idx_vbo, 179 GLuint asteroid_sp); 181 180 182 181 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); … … 187 186 188 187 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo); 189 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp , GLuint asteroid_hp_loc);188 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp); 190 189 bool getLaserAndAsteroidIntersection(vec3& start, vec3& end, SceneObject& asteroid, vec3& intersection); 191 190 … … 452 451 453 452 GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo, 454 normals_vbo, ubo, asteroid_hp_ubo, model_mat_idx_vbo; 455 456 cout << "Initializing buffers" << endl; 453 normals_vbo, ubo, model_mat_idx_vbo; 454 457 455 initializeBuffers( 458 456 &points_vbo, … … 462 460 &normals_vbo, 463 461 &ubo, 464 &asteroid_hp_ubo,465 462 &model_mat_idx_vbo); 466 463 467 cout << "Populating buffers" << endl;468 464 populateBuffers(objects, 469 465 shaderBufferInfo, … … 474 470 normals_vbo, 475 471 ubo, 476 asteroid_hp_ubo, 477 model_mat_idx_vbo); 478 479 cout << "Done" << endl; 472 model_mat_idx_vbo, 473 asteroid_sp); 480 474 481 475 GLuint color_vao = 0; … … 601 595 GLuint asteroid_view_mat_loc = glGetUniformLocation(asteroid_sp, "view"); 602 596 GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj"); 603 GLuint asteroid_hp_loc = glGetUniformLocation(asteroid_sp, "hp");604 597 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models"); 605 598 //GLuint asteroid_sp_hp_ub_index = glGetUniformBlockIndex(asteroid_sp, "hp_uniform"); … … 623 616 624 617 625 GLfloat tempHp = 10.0f;626 mat4 hp(tempHp);627 628 618 glUseProgram(asteroid_sp); 629 619 glUniformMatrix4fv(asteroid_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 630 620 glUniformMatrix4fv(asteroid_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 631 glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp));632 621 633 622 glUniformBlockBinding(asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point); 634 623 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 635 624 636 /*637 glUniformBlockBinding(asteroid_sp, asteroid_sp_hp_ub_index, ub_binding_point);638 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, asteroid_hp_ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);639 */640 625 641 626 glUseProgram(texture_sp); … … 725 710 normals_vbo, 726 711 ubo, 727 asteroid_hp_ubo,728 model_mat_idx_vbo);712 model_mat_idx_vbo, 713 asteroid_sp); 729 714 730 715 elapsed_seconds_spawn -= 0.5f; … … 785 770 normals_vbo, 786 771 ubo, 787 asteroid_hp_ubo,788 model_mat_idx_vbo);772 model_mat_idx_vbo, 773 asteroid_sp); 789 774 } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) { 790 775 removeObjectFromScene(*leftLaser, ubo); … … 803 788 normals_vbo, 804 789 ubo, 805 asteroid_hp_ubo,806 model_mat_idx_vbo);790 model_mat_idx_vbo, 791 asteroid_sp); 807 792 } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) { 808 793 removeObjectFromScene(*rightLaser, ubo); … … 826 811 827 812 if (leftLaser != NULL && !leftLaser->deleted) { 828 updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp , asteroid_hp_loc);813 updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp); 829 814 } 830 815 if (rightLaser != NULL && !rightLaser->deleted) { 831 updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp , asteroid_hp_loc);816 updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp); 832 817 } 833 818 } … … 1287 1272 GLuint normals_vbo, 1288 1273 GLuint ubo, 1289 GLuint asteroid_hp_ubo,1290 GLuint model_mat_idx_vbo) {1274 GLuint model_mat_idx_vbo, 1275 GLuint asteroid_sp) { 1291 1276 objects.push_back(obj); 1292 1277 … … 1312 1297 normals_vbo, 1313 1298 ubo, 1314 asteroid_hp_ubo,1315 model_mat_idx_vbo);1299 model_mat_idx_vbo, 1300 asteroid_sp); 1316 1301 } else { 1317 1302 copyObjectDataToBuffers(*objects.back(), shaderBufferInfo, … … 1322 1307 normals_vbo, 1323 1308 ubo, 1324 asteroid_hp_ubo,1325 model_mat_idx_vbo);1309 model_mat_idx_vbo, 1310 asteroid_sp); 1326 1311 } 1327 1312 } … … 1873 1858 GLuint* normals_vbo, 1874 1859 GLuint* ubo, 1875 GLuint* asteroid_hp_ubo,1876 1860 GLuint* model_mat_idx_vbo) { 1877 1861 *points_vbo = 0; … … 1892 1876 *ubo = 0; 1893 1877 glGenBuffers(1, ubo); 1894 1895 *asteroid_hp_ubo = 0;1896 glGenBuffers(1, asteroid_hp_ubo);1897 1878 1898 1879 *model_mat_idx_vbo = 0; … … 1908 1889 GLuint normals_vbo, 1909 1890 GLuint ubo, 1910 GLuint asteroid_hp_ubo,1911 GLuint ubo_idx_vbo) {1891 GLuint ubo_idx_vbo, 1892 GLuint asteroid_sp) { 1912 1893 GLsizeiptr num_points = 0; 1913 1894 GLsizeiptr num_objects = 0; … … 2003 1984 glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW); 2004 1985 2005 /*2006 glBindBuffer(GL_UNIFORM_BUFFER, asteroid_hp_ubo);2007 glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);2008 */2009 2010 1986 glBindBuffer(GL_ARRAY_BUFFER, ubo_idx_vbo); 2011 1987 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW); … … 2019 1995 normals_vbo, 2020 1996 ubo, 2021 asteroid_hp_ubo,2022 ubo_idx_vbo);1997 ubo_idx_vbo, 1998 asteroid_sp); 2023 1999 } 2024 2000 } … … 2032 2008 GLuint normals_vbo, 2033 2009 GLuint ubo, 2034 GLuint asteroid_hp_ubo,2035 GLuint model_mat_idx_vbo) {2010 GLuint model_mat_idx_vbo, 2011 GLuint asteroid_sp) { 2036 2012 BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program]; 2037 2013 … … 2065 2041 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 2066 2042 2067 /* 2068 //if (obj.type == TYPE_ASTEROID) { 2069 glBindBuffer(GL_UNIFORM_BUFFER, asteroid_hp_ubo); 2070 GLfloat tempHp = 0.1f; // this value has no impact on the actual color, wtf 2071 mat4 tempMat(tempHp); 2072 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(tempMat)); 2073 //} 2074 */ 2043 if (obj.type == TYPE_ASTEROID) { 2044 glUseProgram(asteroid_sp); 2045 2046 ostringstream oss; 2047 oss << "hp[" << obj.ubo_offset << "]"; 2048 glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp); 2049 } 2075 2050 2076 2051 bufferInfo->vbo_offset += obj.num_points; … … 2121 2096 } 2122 2097 2123 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp , GLuint asteroid_hp_loc) {2098 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp) { 2124 2099 // TODO: A lot of the values calculated here can be calculated once and saved when the laser is created, 2125 2100 // and then re-used here … … 2156 2131 2157 2132 if (closestAsteroid != NULL) { 2158 eot = new EffectOverTime(closestAsteroid->hp, - 10.0f, closestAsteroid);2133 eot = new EffectOverTime(closestAsteroid->hp, -20.0f, closestAsteroid); 2159 2134 effects.push_back(eot); 2160 2135 } … … 2172 2147 length = glm::length(closestIntersection - start); 2173 2148 2174 // TODO: Find a better way of doing this 2175 2176 GLfloat tempHp = closestAsteroid->hp; 2177 mat4 hp(tempHp); 2149 // TODO: Find a more generic way of updating the laser hp than in updateLaserTarget 2178 2150 2179 2151 glUseProgram(asteroid_sp); 2180 glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp)); 2152 2153 ostringstream oss; 2154 oss << "hp[" << closestAsteroid->ubo_offset << "]"; 2155 glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), closestAsteroid->hp); 2181 2156 } 2182 2157 … … 2436 2411 obj->colors = { 2437 2412 // front 2438 0. 8f, 0.0f, 0.0f,2439 0. 8f, 0.0f, 0.0f,2440 0. 8f, 0.0f, 0.0f,2441 0. 8f, 0.0f, 0.0f,2442 0. 8f, 0.0f, 0.0f,2443 0. 8f, 0.0f, 0.0f,2413 0.4f, 0.4f, 0.4f, 2414 0.4f, 0.4f, 0.4f, 2415 0.4f, 0.4f, 0.4f, 2416 0.4f, 0.4f, 0.4f, 2417 0.4f, 0.4f, 0.4f, 2418 0.4f, 0.4f, 0.4f, 2444 2419 2445 2420 // top 2446 0. 8f, 0.0f, 0.0f,2447 0. 8f, 0.0f, 0.0f,2448 0. 8f, 0.0f, 0.0f,2449 0. 8f, 0.0f, 0.0f,2450 0. 8f, 0.0f, 0.0f,2451 0. 8f, 0.0f, 0.0f,2421 0.4f, 0.4f, 0.4f, 2422 0.4f, 0.4f, 0.4f, 2423 0.4f, 0.4f, 0.4f, 2424 0.4f, 0.4f, 0.4f, 2425 0.4f, 0.4f, 0.4f, 2426 0.4f, 0.4f, 0.4f, 2452 2427 2453 2428 // bottom 2454 0. 8f, 0.0f, 0.0f,2455 0. 8f, 0.0f, 0.0f,2456 0. 8f, 0.0f, 0.0f,2457 0. 8f, 0.0f, 0.0f,2458 0. 8f, 0.0f, 0.0f,2459 0. 8f, 0.0f, 0.0f,2429 0.4f, 0.4f, 0.4f, 2430 0.4f, 0.4f, 0.4f, 2431 0.4f, 0.4f, 0.4f, 2432 0.4f, 0.4f, 0.4f, 2433 0.4f, 0.4f, 0.4f, 2434 0.4f, 0.4f, 0.4f, 2460 2435 2461 2436 // back 2462 0. 8f, 0.0f, 0.0f,2463 0. 8f, 0.0f, 0.0f,2464 0. 8f, 0.0f, 0.0f,2465 0. 8f, 0.0f, 0.0f,2466 0. 8f, 0.0f, 0.0f,2467 0. 8f, 0.0f, 0.0f,2437 0.4f, 0.4f, 0.4f, 2438 0.4f, 0.4f, 0.4f, 2439 0.4f, 0.4f, 0.4f, 2440 0.4f, 0.4f, 0.4f, 2441 0.4f, 0.4f, 0.4f, 2442 0.4f, 0.4f, 0.4f, 2468 2443 2469 2444 // right 2470 0. 8f, 0.0f, 0.0f,2471 0. 8f, 0.0f, 0.0f,2472 0. 8f, 0.0f, 0.0f,2473 0. 8f, 0.0f, 0.0f,2474 0. 8f, 0.0f, 0.0f,2475 0. 8f, 0.0f, 0.0f,2445 0.4f, 0.4f, 0.4f, 2446 0.4f, 0.4f, 0.4f, 2447 0.4f, 0.4f, 0.4f, 2448 0.4f, 0.4f, 0.4f, 2449 0.4f, 0.4f, 0.4f, 2450 0.4f, 0.4f, 0.4f, 2476 2451 2477 2452 // left 2478 0. 8f, 0.0f, 0.0f,2479 0. 8f, 0.0f, 0.0f,2480 0. 8f, 0.0f, 0.0f,2481 0. 8f, 0.0f, 0.0f,2482 0. 8f, 0.0f, 0.0f,2483 0. 8f, 0.0f, 0.0f,2453 0.4f, 0.4f, 0.4f, 2454 0.4f, 0.4f, 0.4f, 2455 0.4f, 0.4f, 0.4f, 2456 0.4f, 0.4f, 0.4f, 2457 0.4f, 0.4f, 0.4f, 2458 0.4f, 0.4f, 0.4f, 2484 2459 }; 2485 2460 obj->texcoords = { 0.0f };
Note:
See TracChangeset
for help on using the changeset viewer.