Changeset 0e0f851 in opengl-game for new-game.cpp
- Timestamp:
- Oct 12, 2018, 12:52:54 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 25b47d7
- Parents:
- 2b0214c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r2b0214c r0e0f851 76 76 77 77 struct Asteroid : SceneObject { 78 doublehp;78 float hp; 79 79 }; 80 80 … … 84 84 85 85 struct EffectOverTime { 86 double& effectedValue;87 doublestartValue;86 float& effectedValue; 87 float startValue; 88 88 double startTime; 89 doublechangePerSecond;89 float changePerSecond; 90 90 bool deleted; 91 91 SceneObject* effectedObject; 92 92 93 EffectOverTime( double& effectedValue, doublechangePerSecond, SceneObject* object)94 : effectedValue(effectedValue), effectedObject(object) {93 EffectOverTime(float& effectedValue, float changePerSecond, SceneObject* object) 94 : effectedValue(effectedValue), changePerSecond(changePerSecond), effectedObject(object) { 95 95 startValue = effectedValue; 96 96 startTime = glfwGetTime(); 97 this->changePerSecond = changePerSecond;98 97 deleted = false; 99 98 } … … 113 112 void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); 114 113 void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); 114 115 void APIENTRY debugGlCallback( 116 GLenum source, 117 GLenum type, 118 GLuint id, 119 GLenum severity, 120 GLsizei length, 121 const GLchar* message, 122 const void* userParam 123 ); 115 124 116 125 bool faceClicked(array<vec3, 3> points, SceneObject* obj, vec4 world_ray, vec4 cam, vec4& click_point); … … 133 142 GLuint normals_vbo, 134 143 GLuint ubo, 144 GLuint asteroid_hp_ubo, 135 145 GLuint model_mat_idx_vbo); 136 146 void removeObjectFromScene(SceneObject& obj, GLuint ubo); … … 145 155 GLuint* normals_vbo, 146 156 GLuint* ubo, 157 GLuint* asteroid_hp_ubo, 147 158 GLuint* model_mat_idx_vbo); 148 159 … … 155 166 GLuint normals_vbo, 156 167 GLuint ubo, 168 GLuint asteroid_hp_ubo, 157 169 GLuint model_mat_idx_vbo); 158 170 … … 165 177 GLuint normals_vbo, 166 178 GLuint ubo, 179 GLuint asteroid_hp_ubo, 167 180 GLuint model_mat_idx_vbo); 168 181 … … 174 187 175 188 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo); 176 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo );189 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp, GLuint asteroid_hp_loc); 177 190 bool getLaserAndAsteroidIntersection(vec3& start, vec3& end, SceneObject& asteroid, vec3& intersection); 178 191 … … 181 194 182 195 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 183 GLuint color_sp, GLuint texture_sp, GLuint laser_sp,184 GLuint color_vao, GLuint texture_vao, GLuint laser_vao,196 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, 197 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, 185 198 GLuint colors_vbo, GLuint selected_colors_vbo, 186 199 SceneObject* selectedObject); … … 254 267 #endif 255 268 256 glfwWindowHint(GLFW_SAMPLES, 16);257 258 269 GLFWwindow* window = NULL; 259 270 GLFWmonitor* mon = NULL; 271 272 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 273 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 274 glfwWindowHint(GLFW_SAMPLES, 16); 275 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); 260 276 261 277 if (FULLSCREEN) { … … 278 294 glewExperimental = GL_TRUE; 279 295 glewInit(); 296 297 if (GLEW_KHR_debug) { 298 cout << "FOUND GLEW debug extension" << endl; 299 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); 300 glDebugMessageCallback((GLDEBUGPROC)debugGlCallback, nullptr); 301 cout << "Bound debug callback" << endl; 302 } 280 303 281 304 srand(time(0)); … … 322 345 const GLubyte* renderer = glGetString(GL_RENDERER); 323 346 const GLubyte* version = glGetString(GL_VERSION); 324 printf("Renderer: %s\n", renderer);325 printf("OpenGL version supported %s\n", version);347 cout << "Renderer: " << renderer << endl; 348 cout << "OpenGL version supported " << version << endl; 326 349 327 350 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); … … 406 429 map<GLuint, BufferInfo> shaderBufferInfo; 407 430 408 GLuint color_sp = loadShaderProgram("./color.vert", "./color.frag"); 431 // TODO: Rename color_sp to ship_sp and comment out texture_sp) 432 433 GLuint color_sp = loadShaderProgram("./ship.vert", "./ship.frag"); 434 GLuint asteroid_sp = loadShaderProgram("./asteroid.vert", "./asteroid.frag"); 409 435 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag"); 410 436 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 411 437 412 438 shaderBufferInfo[color_sp] = BufferInfo(); 439 shaderBufferInfo[asteroid_sp] = BufferInfo(); 413 440 shaderBufferInfo[texture_sp] = BufferInfo(); 414 441 shaderBufferInfo[laser_sp] = BufferInfo(); … … 425 452 426 453 GLuint points_vbo, colors_vbo, selected_colors_vbo, texcoords_vbo, 427 normals_vbo, ubo, model_mat_idx_vbo; 428 454 normals_vbo, ubo, asteroid_hp_ubo, model_mat_idx_vbo; 455 456 cout << "Initializing buffers" << endl; 429 457 initializeBuffers( 430 458 &points_vbo, … … 434 462 &normals_vbo, 435 463 &ubo, 464 &asteroid_hp_ubo, 436 465 &model_mat_idx_vbo); 437 466 467 cout << "Populating buffers" << endl; 438 468 populateBuffers(objects, 439 469 shaderBufferInfo, … … 444 474 normals_vbo, 445 475 ubo, 476 asteroid_hp_ubo, 446 477 model_mat_idx_vbo); 478 479 cout << "Done" << endl; 447 480 448 481 GLuint color_vao = 0; … … 459 492 460 493 // Comment these two lines out when I want to use selected colors 494 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 495 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); 496 497 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 498 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0); 499 500 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 501 glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0); 502 503 GLuint asteroid_vao = 0; 504 glGenVertexArrays(1, &asteroid_vao); 505 glBindVertexArray(asteroid_vao); 506 507 glEnableVertexAttribArray(0); 508 glEnableVertexAttribArray(1); 509 glEnableVertexAttribArray(2); 510 glEnableVertexAttribArray(3); 511 512 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 513 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); 514 461 515 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 462 516 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); … … 543 597 GLuint view_test_loc = glGetUniformLocation(color_sp, "view"); 544 598 GLuint proj_test_loc = glGetUniformLocation(color_sp, "proj"); 545 GLuint color_sp_ub_index = glGetUniformBlockIndex(color_sp, "models"); 599 GLuint color_sp_models_ub_index = glGetUniformBlockIndex(color_sp, "models"); 600 601 GLuint asteroid_view_mat_loc = glGetUniformLocation(asteroid_sp, "view"); 602 GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj"); 603 GLuint asteroid_hp_loc = glGetUniformLocation(asteroid_sp, "hp"); 604 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models"); 605 //GLuint asteroid_sp_hp_ub_index = glGetUniformBlockIndex(asteroid_sp, "hp_uniform"); 546 606 547 607 GLuint view_mat_loc = glGetUniformLocation(texture_sp, "view"); 548 608 GLuint proj_mat_loc = glGetUniformLocation(texture_sp, "proj"); 549 GLuint texture_sp_ ub_index = glGetUniformBlockIndex(texture_sp, "models");609 GLuint texture_sp_models_ub_index = glGetUniformBlockIndex(texture_sp, "models"); 550 610 551 611 GLuint laser_view_mat_loc = glGetUniformLocation(laser_sp, "view"); 552 612 GLuint laser_proj_mat_loc = glGetUniformLocation(laser_sp, "proj"); 553 613 GLuint laser_color_loc = glGetUniformLocation(laser_sp, "laser_color"); 554 GLuint laser_sp_ ub_index = glGetUniformBlockIndex(laser_sp, "models");614 GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(laser_sp, "models"); 555 615 556 616 … … 559 619 glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat)); 560 620 561 glUniformBlockBinding(color_sp, color_sp_ ub_index, ub_binding_point);621 glUniformBlockBinding(color_sp, color_sp_models_ub_index, ub_binding_point); 562 622 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 563 623 624 625 GLfloat tempHp = 10.0f; 626 mat4 hp(tempHp); 627 628 glUseProgram(asteroid_sp); 629 glUniformMatrix4fv(asteroid_view_mat_loc, 1, GL_FALSE, value_ptr(view_mat)); 630 glUniformMatrix4fv(asteroid_proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 631 glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp)); 632 633 glUniformBlockBinding(asteroid_sp, asteroid_sp_models_ub_index, ub_binding_point); 634 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 635 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 */ 564 640 565 641 glUseProgram(texture_sp); … … 567 643 glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat)); 568 644 569 glUniformBlockBinding(texture_sp, texture_sp_ ub_index, ub_binding_point);645 glUniformBlockBinding(texture_sp, texture_sp_models_ub_index, ub_binding_point); 570 646 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 571 647 … … 576 652 glUniform3f(laser_color_loc, 0.2f, 1.0f, 0.2f); 577 653 578 glUniformBlockBinding(laser_sp, laser_sp_ ub_index, ub_binding_point);654 glUniformBlockBinding(laser_sp, laser_sp_models_ub_index, ub_binding_point); 579 655 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 580 656 … … 641 717 elapsed_seconds_spawn += elapsed_seconds; 642 718 if (elapsed_seconds_spawn > 0.5f) { 643 SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)), color_sp);719 SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)), asteroid_sp); 644 720 addObjectToScene(obj, shaderBufferInfo, 645 721 points_vbo, … … 649 725 normals_vbo, 650 726 ubo, 727 asteroid_hp_ubo, 651 728 model_mat_idx_vbo); 652 729 … … 708 785 normals_vbo, 709 786 ubo, 787 asteroid_hp_ubo, 710 788 model_mat_idx_vbo); 711 789 } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) { … … 725 803 normals_vbo, 726 804 ubo, 805 asteroid_hp_ubo, 727 806 model_mat_idx_vbo); 728 807 } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) { … … 747 826 748 827 if (leftLaser != NULL && !leftLaser->deleted) { 749 updateLaserTarget(leftLaser, objects, points_vbo );828 updateLaserTarget(leftLaser, objects, points_vbo, asteroid_sp, asteroid_hp_loc); 750 829 } 751 830 if (rightLaser != NULL && !rightLaser->deleted) { 752 updateLaserTarget(rightLaser, objects, points_vbo );831 updateLaserTarget(rightLaser, objects, points_vbo, asteroid_sp, asteroid_hp_loc); 753 832 } 754 833 } … … 847 926 case STATE_GAME: 848 927 renderScene(shaderBufferInfo, 849 color_sp, texture_sp, laser_sp,850 color_vao, texture_vao, laser_vao,928 color_sp, asteroid_sp, texture_sp, laser_sp, 929 color_vao, asteroid_vao, texture_vao, laser_vao, 851 930 colors_vbo, selected_colors_vbo, 852 931 selectedObject); … … 936 1015 } 937 1016 1017 void APIENTRY debugGlCallback( 1018 GLenum source, 1019 GLenum type, 1020 GLuint id, 1021 GLenum severity, 1022 GLsizei length, 1023 const GLchar* message, 1024 const void* userParam 1025 ) { 1026 string strMessage(message); 1027 1028 // TODO: Use C++ strings directly 1029 char source_str[2048]; 1030 char type_str[2048]; 1031 char severity_str[2048]; 1032 1033 switch (source) { 1034 case 0x8246: 1035 strcpy(source_str, "API"); 1036 break; 1037 case 0x8247: 1038 strcpy(source_str, "WINDOW_SYSTEM"); 1039 break; 1040 case 0x8248: 1041 strcpy(source_str, "SHADER_COMPILER"); 1042 break; 1043 case 0x8249: 1044 strcpy(source_str, "THIRD_PARTY"); 1045 break; 1046 case 0x824A: 1047 strcpy(source_str, "APPLICATION"); 1048 break; 1049 case 0x824B: 1050 strcpy(source_str, "OTHER"); 1051 break; 1052 default: 1053 strcpy(source_str, "undefined"); 1054 break; 1055 } 1056 1057 switch (type) { 1058 case 0x824C: 1059 strcpy(type_str, "ERROR"); 1060 break; 1061 case 0x824D: 1062 strcpy(type_str, "DEPRECATED_BEHAVIOR"); 1063 break; 1064 case 0x824E: 1065 strcpy(type_str, "UNDEFINED_BEHAVIOR"); 1066 break; 1067 case 0x824F: 1068 strcpy(type_str, "PORTABILITY"); 1069 break; 1070 case 0x8250: 1071 strcpy(type_str, "PERFORMANCE"); 1072 break; 1073 case 0x8251: 1074 strcpy(type_str, "OTHER"); 1075 break; 1076 case 0x8268: 1077 strcpy(type_str, "MARKER"); 1078 break; 1079 case 0x8269: 1080 strcpy(type_str, "PUSH_GROUP"); 1081 break; 1082 case 0x826A: 1083 strcpy(type_str, "POP_GROUP"); 1084 break; 1085 default: 1086 strcpy(type_str, "undefined"); 1087 break; 1088 } 1089 switch (severity) { 1090 case 0x9146: 1091 strcpy(severity_str, "HIGH"); 1092 break; 1093 case 0x9147: 1094 strcpy(severity_str, "MEDIUM"); 1095 break; 1096 case 0x9148: 1097 strcpy(severity_str, "LOW"); 1098 break; 1099 case 0x826B: 1100 strcpy(severity_str, "NOTIFICATION"); 1101 break; 1102 default: 1103 strcpy(severity_str, "undefined"); 1104 break; 1105 } 1106 1107 if (string(severity_str) != "NOTIFICATION") { 1108 cout << "OpenGL Error!!!" << endl; 1109 cout << "Source: " << string(source_str) << endl; 1110 cout << "Type: " << string(type_str) << endl; 1111 cout << "Severity: " << string(severity_str) << endl; 1112 cout << strMessage << endl; 1113 } 1114 } 1115 938 1116 939 1117 GLuint loadShader(GLenum type, string file) { … … 1109 1287 GLuint normals_vbo, 1110 1288 GLuint ubo, 1289 GLuint asteroid_hp_ubo, 1111 1290 GLuint model_mat_idx_vbo) { 1112 1291 objects.push_back(obj); … … 1133 1312 normals_vbo, 1134 1313 ubo, 1314 asteroid_hp_ubo, 1135 1315 model_mat_idx_vbo); 1136 1316 } else { … … 1142 1322 normals_vbo, 1143 1323 ubo, 1324 asteroid_hp_ubo, 1144 1325 model_mat_idx_vbo); 1145 1326 } … … 1692 1873 GLuint* normals_vbo, 1693 1874 GLuint* ubo, 1875 GLuint* asteroid_hp_ubo, 1694 1876 GLuint* model_mat_idx_vbo) { 1695 1877 *points_vbo = 0; … … 1710 1892 *ubo = 0; 1711 1893 glGenBuffers(1, ubo); 1894 1895 *asteroid_hp_ubo = 0; 1896 glGenBuffers(1, asteroid_hp_ubo); 1712 1897 1713 1898 *model_mat_idx_vbo = 0; … … 1723 1908 GLuint normals_vbo, 1724 1909 GLuint ubo, 1725 GLuint model_mat_idx_vbo) { 1726 GLsizeiptr points_buffer_size = 0; 1727 GLsizeiptr textures_buffer_size = 0; 1728 GLsizeiptr ubo_buffer_size = 0; 1729 GLsizeiptr model_mat_idx_buffer_size = 0; 1910 GLuint asteroid_hp_ubo, 1911 GLuint ubo_idx_vbo) { 1912 GLsizeiptr num_points = 0; 1913 GLsizeiptr num_objects = 0; 1730 1914 1731 1915 map<GLuint, unsigned int> shaderCounts; … … 1745 1929 it = objects.erase(it); 1746 1930 } else { 1747 points_buffer_size += (*it)->num_points * sizeof(GLfloat) * 3; 1748 textures_buffer_size += (*it)->num_points * sizeof(GLfloat) * 2; 1749 ubo_buffer_size += 16 * sizeof(GLfloat); 1750 model_mat_idx_buffer_size += (*it)->num_points * sizeof(GLuint); 1931 num_points += (*it)->num_points; 1932 num_objects++; 1751 1933 1752 1934 if (shaderCounts.count((*it)->shader_program) == 0) { … … 1763 1945 1764 1946 // double the buffer sizes to leave room for new objects 1765 points_buffer_size *= 2; 1766 textures_buffer_size *= 2; 1767 ubo_buffer_size *= 2; 1768 model_mat_idx_buffer_size *= 2; 1947 num_points *= 2; 1948 num_objects *= 2; 1769 1949 1770 1950 map<GLuint, unsigned int>::iterator shaderIt; … … 1780 1960 */ 1781 1961 for (shaderIt = shaderCounts.begin(); shaderIt != shaderCounts.end(); shaderIt++) { 1962 // When populating the buffers, leave as much empty space as space taken up by existing objects 1963 // to allow new objects to be added without immediately having to resize the buffers 1782 1964 shaderBufferInfo[shaderIt->first].vbo_base = lastShaderCount * 2; 1783 1965 shaderBufferInfo[shaderIt->first].ubo_base = lastShaderUboCount * 2; … … 1804 1986 1805 1987 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 1806 glBufferData(GL_ARRAY_BUFFER, points_buffer_size, NULL, GL_DYNAMIC_DRAW);1988 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 1807 1989 1808 1990 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 1809 glBufferData(GL_ARRAY_BUFFER, points_buffer_size, NULL, GL_DYNAMIC_DRAW);1991 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 1810 1992 1811 1993 glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo); 1812 glBufferData(GL_ARRAY_BUFFER, points_buffer_size, NULL, GL_DYNAMIC_DRAW);1994 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 1813 1995 1814 1996 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 1815 glBufferData(GL_ARRAY_BUFFER, textures_buffer_size, NULL, GL_DYNAMIC_DRAW);1997 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 2, NULL, GL_DYNAMIC_DRAW); 1816 1998 1817 1999 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 1818 glBufferData(GL_ARRAY_BUFFER, points_buffer_size, NULL, GL_DYNAMIC_DRAW);2000 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 1819 2001 1820 2002 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 1821 glBufferData(GL_UNIFORM_BUFFER, ubo_buffer_size, NULL, GL_DYNAMIC_DRAW); 1822 1823 glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo); 1824 glBufferData(GL_ARRAY_BUFFER, model_mat_idx_buffer_size, NULL, GL_DYNAMIC_DRAW); 2003 glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW); 2004 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 glBindBuffer(GL_ARRAY_BUFFER, ubo_idx_vbo); 2011 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW); 1825 2012 1826 2013 for (it = objects.begin(); it != objects.end(); it++) { … … 1832 2019 normals_vbo, 1833 2020 ubo, 1834 model_mat_idx_vbo); 2021 asteroid_hp_ubo, 2022 ubo_idx_vbo); 1835 2023 } 1836 2024 } … … 1844 2032 GLuint normals_vbo, 1845 2033 GLuint ubo, 2034 GLuint asteroid_hp_ubo, 1846 2035 GLuint model_mat_idx_vbo) { 1847 2036 BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program]; … … 1875 2064 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 1876 2065 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 2066 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 */ 1877 2075 1878 2076 bufferInfo->vbo_offset += obj.num_points; … … 1923 2121 } 1924 2122 1925 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo ) {2123 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, GLuint points_vbo, GLuint asteroid_sp, GLuint asteroid_hp_loc) { 1926 2124 // TODO: A lot of the values calculated here can be calculated once and saved when the laser is created, 1927 2125 // and then re-used here … … 1958 2156 1959 2157 if (closestAsteroid != NULL) { 1960 eot = new EffectOverTime(closestAsteroid->hp, -10 , closestAsteroid);2158 eot = new EffectOverTime(closestAsteroid->hp, -10.0f, closestAsteroid); 1961 2159 effects.push_back(eot); 1962 2160 } … … 1973 2171 if (closestAsteroid != NULL) { 1974 2172 length = glm::length(closestIntersection - start); 2173 2174 // TODO: Find a better way of doing this 2175 2176 GLfloat tempHp = closestAsteroid->hp; 2177 mat4 hp(tempHp); 2178 2179 glUseProgram(asteroid_sp); 2180 glUniformMatrix4fv(asteroid_hp_loc, 1, GL_FALSE, value_ptr(hp)); 1975 2181 } 1976 2182 … … 2035 2241 2036 2242 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2037 GLuint color_sp, GLuint texture_sp, GLuint laser_sp,2038 GLuint color_vao, GLuint texture_vao, GLuint laser_vao,2243 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, 2244 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, 2039 2245 GLuint colors_vbo, GLuint selected_colors_vbo, 2040 2246 SceneObject* selectedObject) { … … 2057 2263 2058 2264 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[color_sp].vbo_base, shaderBufferInfo[color_sp].vbo_offset); 2265 2266 glUseProgram(asteroid_sp); 2267 glBindVertexArray(asteroid_vao); 2268 2269 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[asteroid_sp].vbo_base, shaderBufferInfo[asteroid_sp].vbo_offset); 2059 2270 2060 2271 glUseProgram(texture_sp);
Note:
See TracChangeset
for help on using the changeset viewer.