Changeset 4a9416a in opengl-game for new-game.cpp
- Timestamp:
- Apr 26, 2020, 9:50:00 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- b8d4456
- Parents:
- 52a02e6
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (04/26/20 19:00:18)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (04/26/20 21:50:00)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r52a02e6 r4a9416a 47 47 }; 48 48 49 /*** START OF REFACTORED CODE ***/ 49 50 enum ObjectType { 50 51 TYPE_SHIP, … … 67 68 UNIFORM_3F, 68 69 }; 70 /*** END OF REFACTORED CODE ***/ 69 71 70 72 enum UIValueType { … … 73 75 }; 74 76 77 /*** START OF REFACTORED CODE ***/ 75 78 struct SceneObject { 76 79 unsigned int id; … … 153 156 unsigned int vboCapacity; 154 157 }; 158 /*** END OF REFACTORED CODE ***/ 155 159 156 160 struct UIValue { … … 193 197 map<ObjectType, ShaderModelGroup>& modelGroups, 194 198 GLuint ubo); 195 /*** END OF REFACTORED CODE ***/196 199 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 197 200 … … 200 203 void addModelToGroup(ShaderModelGroup& modelGroup, SceneObject& model); 201 204 202 /*** START OF REFACTORED CODE ***/203 205 void defineModelGroupAttrib(ShaderModelGroup& modelGroup, string name, AttribType attribType, GLint size, GLenum type, size_t fieldOffset); 204 206 void defineModelGroupUniform(ShaderModelGroup& modelGroup, string name, AttribType attribType, GLint size, UniformType type, GLfloat* data); … … 206 208 void bindUniformData(AttribInfo& attrib); 207 209 void bindUniformData(AttribInfo& attrib, GLfloat* data); 208 /*** END OF REFACTORED CODE ***/209 210 210 211 size_t GLsizeof(GLenum); … … 214 215 void calculateObjectBoundingBox(SceneObject* obj); 215 216 216 /*** START OF REFACTORED CODE ***/217 217 void populateBuffers(vector<SceneObject*>& objects, 218 218 map<GLuint, BufferInfo>& shaderBufferInfo, … … 231 231 Asteroid* createAsteroid(vec3 pos); 232 232 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width); 233 /*** END OF REFACTORED CODE ***/234 233 ParticleEffect* createExplosion(mat4 model_mat); 235 234 236 /*** START OF REFACTORED CODE ***/237 235 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo); 238 236 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, ShaderModelGroup& laserSmg, GLuint asteroid_sp); … … 254 252 255 253 const int KEY_STATE_UNCHANGED = -1; 254 /*** START OF REFACTORED CODE ***/ 256 255 const bool FULLSCREEN = false; 257 256 const int EXPLOSION_PARTICLE_COUNT = 300; 258 257 unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const 258 /*** END OF REFACTORED CODE ***/ 259 259 260 260 int key_state[NUM_KEYS]; … … 381 381 cout << "OpenGL debug message callback is not supported" << endl; 382 382 } 383 /*** END OF REFACTORED CODE ***/384 383 385 384 srand(time(0)); … … 409 408 cout << "MAX_UNIFORMS: " << MAX_UNIFORMS << endl; 410 409 411 /*** START OF REFACTORED CODE ***/412 410 // Setup Dear ImGui binding 413 411 IMGUI_CHECKVERSION(); … … 489 487 */ 490 488 489 /*** START OF REFACTORED CODE ***/ 491 490 GLfloat laserColor[3] = {0.2f, 1.0f, 0.2f}; 492 491 GLfloat curTime, prevTime, elapsedTime; … … 498 497 map<ObjectType, ShaderModelGroup> modelGroups; 499 498 500 /*** START OF REFACTORED CODE ***/501 499 modelGroups[TYPE_SHIP] = createModelGroup( 502 500 loadShaderProgram("gl-shaders/ship.vert", "gl-shaders/ship.frag")); … … 558 556 559 557 initModelGroupAttribs(modelGroups[TYPE_LASER]); 560 /*** END OF REFACTORED CODE ***/561 558 562 559 modelGroups[TYPE_EXPLOSION] = createModelGroup( … … 580 577 initModelGroupAttribs(modelGroups[TYPE_EXPLOSION]); 581 578 582 /*** START OF REFACTORED CODE ***/583 579 cam_pos = vec3(0.0f, 0.0f, 2.0f); 584 580 float cam_yaw = 0.0f * 2.0f * 3.14159f / 360.0f; … … 666 662 667 663 GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_LASER].shaderProgram, "models"); 668 /*** END OF REFACTORED CODE ***/669 664 670 665 GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_EXPLOSION].shaderProgram, "models"); 671 666 672 667 673 /*** START OF REFACTORED CODE ***/674 668 glUseProgram(modelGroups[TYPE_SHIP].shaderProgram); 675 669 bindUniformData(modelGroups[TYPE_SHIP].attribs["view"]); … … 698 692 glUniformBlockBinding(modelGroups[TYPE_LASER].shaderProgram, laser_sp_models_ub_index, ub_binding_point); 699 693 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 700 /*** END OF REFACTORED CODE ***/701 694 702 695 … … 707 700 glUniformBlockBinding(modelGroups[TYPE_EXPLOSION].shaderProgram, explosion_sp_models_ub_index, ub_binding_point); 708 701 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 702 /*** END OF REFACTORED CODE ***/ 709 703 710 704 … … 881 875 score++; 882 876 877 /*** START OF REFACTORED CODE ***/ 883 878 addObjectToScene(createExplosion(model_mat), shaderBufferInfo, modelGroups, ubo); 884 879 } … … 889 884 } 890 885 } 891 /*** START OF REFACTORED CODE ***/892 886 } 893 887 } … … 977 971 cam_moved = false; 978 972 } 979 /*** END OF REFACTORED CODE ***/980 973 981 974 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); 982 975 bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["cur_time"]); 983 976 984 /*** START OF REFACTORED CODE ***/985 977 // Render scene 986 978 … … 1200 1192 1201 1193 1194 /*** START OF REFACTORED CODE ***/ 1202 1195 GLuint loadShader(GLenum type, string file) { 1203 1196 cout << "Loading shader from file " << file << endl; … … 1279 1272 return image_data; 1280 1273 } 1274 /*** END OF REFACTORED CODE ***/ 1281 1275 1282 1276 bool faceClicked(array<vec3, 3> points, SceneObject* obj, vec4 world_ray, vec4 cam, vec4& click_point) { … … 1324 1318 } 1325 1319 1320 /*** START OF REFACTORED CODE ***/ 1326 1321 // TODO: Pass a reference, not a pointer 1327 1322 void initObject(SceneObject* obj) { … … 1446 1441 } 1447 1442 1448 /*** START OF REFACTORED CODE ***/1449 1443 SceneObject* createShip() { 1450 1444 SceneObject* ship = new SceneObject(); … … 1917 1911 return obj; 1918 1912 } 1919 /*** END OF REFACTORED CODE ***/1920 1913 1921 1914 ShaderModelGroup createModelGroup(GLuint shaderProgram) { … … 1942 1935 } 1943 1936 1944 /*** START OF REFACTORED CODE ***/1945 1937 void defineModelGroupAttrib(ShaderModelGroup& modelGroup, string name, AttribType attribType, 1946 1938 GLint size, GLenum type, size_t fieldOffset) { … … 2031 2023 } 2032 2024 } 2033 /*** END OF REFACTORED CODE ***/2034 2025 2035 2026 /* The purpose of this function is to replace the use of sizeof() when calling … … 2403 2394 glDisable(GL_BLEND); 2404 2395 } 2396 /*** END OF REFACTORED CODE ***/ 2405 2397 2406 2398 void renderSceneGui(map<string, vector<UIValue>> valueLists) { … … 2671 2663 return obj; 2672 2664 } 2673 /*** END OF REFACTORED CODE ***/2674 2665 2675 2666 // TODO: Maybe pass in startTime instead of calling glfwGetTime() here … … 2703 2694 return obj; 2704 2695 } 2696 /*** END OF REFACTORED CODE ***/
Note:
See TracChangeset
for help on using the changeset viewer.