Changeset 7a55b49 in opengl-game
- Timestamp:
- Jan 31, 2019, 6:09:57 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0414306
- Parents:
- ae0c7f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rae0c7f4 r7a55b49 109 109 }; 110 110 111 struct ShaderModelGroup { 112 GLuint shaderProgram; 113 GLuint vao; 114 unsigned int numPoints; 115 }; 116 111 117 void glfw_error_callback(int error, const char* description); 112 118 … … 146 152 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 147 153 154 ShaderModelGroup createModelGroup(GLuint shaderProgram); 155 void removeModelFromGroup(ShaderModelGroup& modelGroup, SceneObject& model); 156 void addModelToGroup(ShaderModelGroup& modelGroup, SceneObject& model); 157 148 158 void calculateObjectBoundingBox(SceneObject* obj); 149 159 … … 156 166 GLuint* model_mat_idx_vbo); 157 167 158 GLuintinitializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,168 ShaderModelGroup initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp, 159 169 map<GLuint, BufferInfo>& shaderBufferInfo, 160 170 GLuint points_vbo, … … 200 210 void renderMainMenuGui(); 201 211 202 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 203 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp, GLuint explosion_sp,204 GLuint ship_vao, GLuint asteroid_vao, GLuint laser_vao, GLuint explosion_vao,205 GLuint colors_vbo, GLuint ubo, SceneObject* selectedObject);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); 206 216 207 217 void renderSceneGui(); … … 577 587 proj_mat = make_mat4(proj_arr); 578 588 579 GLuint explosion_vao= initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat,589 ShaderModelGroup explosion_group = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, 580 590 explosion_sp, 581 591 shaderBufferInfo, … … 959 969 break; 960 970 case STATE_GAME: 961 renderScene(shaderBufferInfo, 962 ship_sp, asteroid_sp, laser_sp, explosion_sp,963 ship_vao, asteroid_vao, laser_vao, explosion_vao,964 colors_vbo, ubo, selectedObject);971 renderScene(shaderBufferInfo, ubo, 972 ship_sp, asteroid_sp, laser_sp, 973 ship_vao, asteroid_vao, laser_vao, 974 explosion_group); 965 975 renderSceneGui(); 966 976 break; … … 1894 1904 } 1895 1905 1906 ShaderModelGroup createModelGroup(GLuint shaderProgram) { 1907 ShaderModelGroup smg; 1908 1909 smg.shaderProgram = shaderProgram; 1910 1911 return smg; 1912 } 1913 1914 void removeModelFromGroup(ShaderModelGroup& modelGroup, SceneObject& model) { 1915 // TODO: Implement 1916 } 1917 1918 void addModelToGroup(ShaderModelGroup& modelGroup, SceneObject& model) { 1919 // TODO: Implement 1920 } 1921 1896 1922 void initializeBuffers( 1897 1923 GLuint* points_vbo, … … 1920 1946 } 1921 1947 1922 GLuintinitializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,1948 ShaderModelGroup initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp, 1923 1949 map<GLuint, BufferInfo>& shaderBufferInfo, 1924 1950 GLuint points_vbo, … … 1945 1971 mat4 model_mat = translate(mat4(1.0f), origin); 1946 1972 1947 glUseProgram(explosion_sp); 1973 ShaderModelGroup modelGroup; 1974 modelGroup.shaderProgram = explosion_sp; 1975 1976 glUseProgram(modelGroup.shaderProgram); 1948 1977 1949 1978 GLuint proj_mat_loc = glGetUniformLocation(explosion_sp, "proj"); … … 1967 1996 glBufferData(GL_ARRAY_BUFFER, sizeof(vt), vt, GL_STATIC_DRAW); 1968 1997 1969 GLuint vao; 1970 glGenVertexArrays(1, &vao); 1971 glBindVertexArray(vao); 1998 glGenVertexArrays(1, &modelGroup.vao); 1999 glBindVertexArray(modelGroup.vao); 1972 2000 1973 2001 glEnableVertexAttribArray(0); … … 1980 2008 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL); 1981 2009 1982 objExplosion = createExplosion( explosion_sp);2010 objExplosion = createExplosion(modelGroup.shaderProgram); 1983 2011 addObjectToScene(objExplosion, shaderBufferInfo, 1984 2012 points_vbo, … … 1990 2018 0); 1991 2019 1992 return vao;2020 return modelGroup; 1993 2021 } 1994 2022 … … 2316 2344 } 2317 2345 2318 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2319 GLuint ship_sp, GLuint asteroid_sp, GLuint laser_sp, GLuint explosion_sp,2320 GLuint ship_vao, GLuint asteroid_vao, GLuint laser_vao, GLuint explosion_vao,2321 GLuint colors_vbo, GLuint ubo, SceneObject* selectedObject) {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) { 2322 2350 2323 2351 glUseProgram(ship_sp); … … 2338 2366 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2339 2367 2340 // To render explosions, my new shader descriptor object needs to have a refer nece to the shader and the vao2368 // To render explosions, my new shader descriptor object needs to have a reference to the shader and the vao 2341 2369 // and know the number of points to render. 2342 2370 2343 glUseProgram(explosion_ sp);2371 glUseProgram(explosion_group.shaderProgram); 2344 2372 2345 2373 glEnable(GL_PROGRAM_POINT_SIZE); 2346 glBindVertexArray(explosion_ vao);2374 glBindVertexArray(explosion_group.vao); 2347 2375 2348 2376 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2349 2377 glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objExplosion->model_mat)); 2350 2378 2351 glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_ sp].vbo_offset);2379 glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_group.shaderProgram].vbo_offset); 2352 2380 2353 2381 glBindBuffer(GL_UNIFORM_BUFFER, ubo);
Note:
See TracChangeset
for help on using the changeset viewer.