Changeset db06984 in opengl-game for new-game.cpp
- Timestamp:
- Nov 14, 2018, 4:55:06 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- adb104f
- Parents:
- f71d87d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rf71d87d rdb06984 157 157 GLuint* model_mat_idx_vbo); 158 158 159 GLuint initializeParticleEffectBuffers(); 160 159 161 void populateBuffers(vector<SceneObject*>& objects, 160 162 map<GLuint, BufferInfo>& shaderBufferInfo, … … 193 195 194 196 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 195 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, 196 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, 197 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 198 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 197 199 GLuint colors_vbo, GLuint selected_colors_vbo, 198 200 SceneObject* selectedObject); 201 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex); 202 199 203 void renderSceneGui(); 200 204 … … 206 210 const int KEY_STATE_UNCHANGED = -1; 207 211 const bool FULLSCREEN = false; 212 const int EXPLOSION_PARTICLE_COUNT = 300; 208 213 unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const 209 214 … … 438 443 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag"); 439 444 GLuint laser_sp = loadShaderProgram("./laser.vert", "./laser.frag"); 445 GLuint explosion_sp = loadShaderProgram("./explosion.vert", "./explosion.frag"); 440 446 441 447 shaderBufferInfo[color_sp] = BufferInfo(); … … 558 564 glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, 0); 559 565 566 GLuint explosion_vao = initializeParticleEffectBuffers(); 567 560 568 float cam_speed = 1.0f; 561 569 float cam_yaw_speed = 60.0f*ONE_DEG_IN_RAD; … … 600 608 GLuint asteroid_proj_mat_loc = glGetUniformLocation(asteroid_sp, "proj"); 601 609 GLuint asteroid_sp_models_ub_index = glGetUniformBlockIndex(asteroid_sp, "models"); 602 //GLuint asteroid_sp_hp_ub_index = glGetUniformBlockIndex(asteroid_sp, "hp_uniform");603 610 604 611 GLuint view_mat_loc = glGetUniformLocation(texture_sp, "view"); … … 610 617 GLuint laser_color_loc = glGetUniformLocation(laser_sp, "laser_color"); 611 618 GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(laser_sp, "models"); 619 620 GLuint elapsed_system_time_loc = glGetUniformLocation(explosion_sp, "elapsed_system_time"); 612 621 613 622 … … 905 914 } 906 915 916 glUseProgram(explosion_sp); 917 glUniform1f(elapsed_system_time_loc, (GLfloat)current_seconds); 918 907 919 // Render scene 908 920 … … 916 928 case STATE_GAME: 917 929 renderScene(shaderBufferInfo, 918 color_sp, asteroid_sp, texture_sp, laser_sp, 919 color_vao, asteroid_vao, texture_vao, laser_vao, 930 color_sp, asteroid_sp, texture_sp, laser_sp, explosion_sp, 931 color_vao, asteroid_vao, texture_vao, laser_vao, explosion_vao, 920 932 colors_vbo, selected_colors_vbo, 921 933 selectedObject); … … 1886 1898 } 1887 1899 1900 GLuint initializeParticleEffectBuffers() { 1901 float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3 1902 float vt[EXPLOSION_PARTICLE_COUNT]; // initial times 1903 float t_accum = 0.0f; // start time 1904 1905 for (int i = 0; i < EXPLOSION_PARTICLE_COUNT; i++) { 1906 vt[i] = t_accum; 1907 t_accum += 0.01f; 1908 1909 float randx = ((float)rand() / (float)RAND_MAX) * 1.0f - 0.5f; 1910 float randz = ((float)rand() / (float)RAND_MAX) * 1.0f - 0.5f; 1911 vv[i*3] = randx; 1912 vv[i*3 + 1] = 1.0f; 1913 vv[i*3 + 2] = randz; 1914 } 1915 1916 GLuint velocity_vbo; 1917 glGenBuffers(1, &velocity_vbo); 1918 glBindBuffer(GL_ARRAY_BUFFER, velocity_vbo); 1919 glBufferData(GL_ARRAY_BUFFER, sizeof(vv), vv, GL_STATIC_DRAW); 1920 1921 GLuint time_vbo; 1922 glGenBuffers(1, &time_vbo); 1923 glBindBuffer(GL_ARRAY_BUFFER, time_vbo); 1924 glBufferData(GL_ARRAY_BUFFER, sizeof(vt), vt, GL_STATIC_DRAW); 1925 1926 GLuint vao; 1927 glGenVertexArrays(1, &vao); 1928 glBindVertexArray(vao); 1929 1930 glBindBuffer(GL_ARRAY_BUFFER, velocity_vbo); 1931 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 1932 1933 glBindBuffer(GL_ARRAY_BUFFER, time_vbo); 1934 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL); 1935 1936 glEnableVertexAttribArray(0); 1937 glEnableVertexAttribArray(1); 1938 1939 return vao; 1940 } 1941 1888 1942 void populateBuffers(vector<SceneObject*>& objects, 1889 1943 map<GLuint, BufferInfo>& shaderBufferInfo, … … 2219 2273 2220 2274 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 2221 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, 2222 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, 2275 GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp, 2276 GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao, 2223 2277 GLuint colors_vbo, GLuint selected_colors_vbo, 2224 2278 SceneObject* selectedObject) { … … 2259 2313 glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset); 2260 2314 2315 glDisable(GL_BLEND); 2316 2317 renderExplosion(explosion_sp, explosion_vao, 0); 2318 } 2319 2320 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex) { 2321 glEnable(GL_BLEND); 2322 glEnable(GL_PROGRAM_POINT_SIZE); 2323 2324 //glActiveTexture(GL_TEXTURE1); 2325 //glBindTexture(GL_TEXTURE_2D, tex); 2326 glUseProgram(explosion_sp); 2327 2328 glBindVertexArray(explosion_vao); 2329 2330 glDrawArrays(GL_POINTS, 0, EXPLOSION_PARTICLE_COUNT); 2331 2332 glDisable(GL_PROGRAM_POINT_SIZE); 2261 2333 glDisable(GL_BLEND); 2262 2334 }
Note:
See TracChangeset
for help on using the changeset viewer.