Changeset 646f3f2 in opengl-game for new-game.cpp


Ignore:
Timestamp:
Jan 30, 2019, 3:10:23 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
39ac76d
Parents:
fe5e3ca
Message:

Make explosions render correctly whenever a ship is destroyed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    rfe5e3ca r646f3f2  
    5050   TYPE_ASTEROID,
    5151   TYPE_LASER,
     52   TYPE_EXPLOSION,
    5253};
    5354
     
    157158                  GLuint* model_mat_idx_vbo);
    158159
    159 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp);
     160GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,
     161                  map<GLuint, BufferInfo>& shaderBufferInfo,
     162                  GLuint points_vbo,
     163                  GLuint colors_vbo,
     164                  GLuint selected_colors_vbo,
     165                  GLuint texcoords_vbo,
     166                  GLuint normals_vbo,
     167                  GLuint ubo,
     168                  GLuint model_mat_idx_vbo);
    160169
    161170void populateBuffers(vector<SceneObject*>& objects,
     
    183192void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo);
    184193
     194// TODO: instead of using these methods, create constructors for these
    185195SceneObject* createShip(GLuint shader);
    186196Asteroid* createAsteroid(vec3 pos, GLuint shader);
    187197Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp);
     198SceneObject* createExplosion(GLuint shader);
    188199
    189200void translateLaser(Laser* laser, const vec3& translation, GLuint ubo);
     
    197208                  GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp,
    198209                  GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao,
    199                   GLuint colors_vbo, GLuint selected_colors_vbo,
     210                  GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo,
    200211                  SceneObject* selectedObject);
    201 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex);
    202212
    203213void renderSceneGui();
     
    248258Laser* rightLaser = NULL;
    249259EffectOverTime* rightLaserEffect = NULL;
     260
     261SceneObject* objExplosion;
     262SceneObject* objFirst;
    250263
    251264/*
     
    450463   shaderBufferInfo[texture_sp] = BufferInfo();
    451464   shaderBufferInfo[laser_sp] = BufferInfo();
     465   shaderBufferInfo[explosion_sp] = BufferInfo();
    452466
    453467   cam_pos = vec3(0.0f, 0.0f, 2.0f);
     
    494508
    495509   glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    496    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
     510   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    497511
    498512   // Comment these two lines out when I want to use selected colors
    499513   glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    500    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
     514   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    501515
    502516   glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);
    503    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
     517   glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    504518
    505519   glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    506    glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);
     520   glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL);
    507521
    508522   GLuint asteroid_vao = 0;
     
    516530
    517531   glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    518    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
     532   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    519533
    520534   glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    521    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
     535   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    522536
    523537   glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);
    524    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
     538   glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    525539
    526540   glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    527    glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);
     541   glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL);
    528542
    529543   GLuint texture_vao = 0;
     
    537551
    538552   glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    539    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
     553   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    540554
    541555   glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);
    542    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
     556   glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    543557
    544558   glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);
    545    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
     559   glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    546560
    547561   glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    548    glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, 0);
     562   glVertexAttribIPointer(3, 1, GL_UNSIGNED_INT, 0, NULL);
    549563
    550564   GLuint laser_vao = 0;
     
    557571
    558572   glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    559    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
     573   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    560574
    561575   glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);
    562    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
     576   glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    563577
    564578   glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    565    glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, 0);
     579   glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, NULL);
    566580
    567581   float cam_speed = 1.0f;
     
    597611   proj_mat = make_mat4(proj_arr);
    598612
    599    GLuint explosion_vao = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, explosion_sp);
     613   GLuint explosion_vao = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat,
     614      explosion_sp,
     615      shaderBufferInfo,
     616      points_vbo,
     617      colors_vbo,
     618      selected_colors_vbo,
     619      texcoords_vbo,
     620      normals_vbo,
     621      ubo,
     622      model_mat_idx_vbo);
    600623
    601624   GLuint ub_binding_point = 0;
     
    621644   GLuint explosion_start_time_loc = glGetUniformLocation(explosion_sp, "explosion_start_time");
    622645   GLuint cur_time_loc = glGetUniformLocation(explosion_sp, "cur_time");
     646   GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex(explosion_sp, "models");
    623647
    624648
     
    653677
    654678   glUniformBlockBinding(laser_sp, laser_sp_models_ub_index, ub_binding_point);
     679   glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);
     680
     681
     682   glUseProgram(explosion_sp);
     683   glUniformBlockBinding(explosion_sp, explosion_sp_models_ub_index, ub_binding_point);
    655684   glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);
    656685
     
    825854                  removeObjectFromScene(*objects[i], ubo);
    826855               }
     856               // MARKER: Continue code review from here
    827857               if (((Asteroid*)objects[i])->hp <= 0) {
     858                  // TODO: Optimize this so I don't recalculate the camera rotation every time
     859                  float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f;
     860                  mat4 pitch_mat = rotate(mat4(1.0f), cam_pitch, vec3(1.0f, 0.0f, 0.0f));
     861                  mat4 model_mat = translate(mat4(1.0f), objects[i]->bounding_center + vec3(0.0f, 0.0f, 0.0f)) * pitch_mat;
     862
    828863                  removeObjectFromScene(*objects[i], ubo);
    829864                  score++;
    830865
    831                   // render an explosion
     866                  objExplosion->model_mat = model_mat;
     867
     868                  // initiate an explosion
    832869                  glUseProgram(explosion_sp);
     870
     871                  GLuint model_mat_loc = glGetUniformLocation(explosion_sp, "model_mat");
     872                  glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objExplosion->model_mat));
     873
    833874                  glUniform1f(explosion_start_time_loc, (GLfloat)glfwGetTime());
    834                   cout << "REMOVED" << endl;
    835                   cout << i << endl;
    836875               }
    837876            }
     
    944983               color_sp, asteroid_sp, texture_sp, laser_sp, explosion_sp,
    945984               color_vao, asteroid_vao, texture_vao, laser_vao, explosion_vao,
    946                colors_vbo, selected_colors_vbo,
     985               colors_vbo, selected_colors_vbo, ubo,
    947986               selectedObject);
    948987            renderSceneGui();
     
    12881327   }
    12891328
    1290    if (obj->type != TYPE_LASER) {
     1329   if (obj->type == TYPE_SHIP || obj->type == TYPE_ASTEROID) {
    12911330      calculateObjectBoundingBox(obj);
    12921331
     
    13111350   // Check if the buffers aren't large enough to fit the new object and, if so, call
    13121351   // populateBuffers() to resize and repopupulate them
    1313    if (bufferInfo->vbo_capacity < (bufferInfo->ubo_offset + obj->num_points) ||
     1352   if (bufferInfo->vbo_capacity < (bufferInfo->vbo_offset + obj->num_points) ||
    13141353      bufferInfo->ubo_capacity < (bufferInfo->ubo_offset + 1)) {
    13151354
     
    18051844*/
    18061845// TODO: Make the color parameter have an effect
    1807 // TODO: Come up with a better way of passing the object back than copying it
    18081846Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp) {
    18091847   Laser* obj = new Laser();
     
    19121950}
    19131951
    1914 GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp) {
    1915    //unsigned int num_explosions = 1;
    1916 
     1952GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp,
     1953                  map<GLuint, BufferInfo>& shaderBufferInfo,
     1954                  GLuint points_vbo,
     1955                  GLuint colors_vbo,
     1956                  GLuint selected_colors_vbo,
     1957                  GLuint texcoords_vbo,
     1958                  GLuint normals_vbo,
     1959                  GLuint ubo,
     1960                  GLuint model_mat_idx_vbo) {
    19171961   float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3
    19181962   float vt[EXPLOSION_PARTICLE_COUNT]; // initial times
     
    19441988   glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat));
    19451989
    1946    /*
    1947    GLuint model_ubo = 0;
    1948    glGenBuffers(1, &model_ubo);
    1949 
    1950    glBindBuffer(GL_UNIFORM_BUFFER, model_ubo);
    1951    glBufferData(GL_UNIFORM_BUFFER, num_explosions * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);
    1952 
    1953    //glBindBuffer(GL_UNIFORM_BUFFER, ubo);
    1954    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(model_mat));
    1955    */
    1956 
    19571990   GLuint velocity_vbo;
    19581991   glGenBuffers(1, &velocity_vbo);
     
    19692002   glBindVertexArray(vao);
    19702003
     2004   glEnableVertexAttribArray(0);
     2005   glEnableVertexAttribArray(1);
     2006
    19712007   glBindBuffer(GL_ARRAY_BUFFER, velocity_vbo);
    19722008   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
     
    19752011   glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);
    19762012
    1977    glEnableVertexAttribArray(0);
    1978    glEnableVertexAttribArray(1);
     2013   objExplosion = createExplosion(explosion_sp);
     2014   addObjectToScene(objExplosion, shaderBufferInfo,
     2015      points_vbo,
     2016      colors_vbo,
     2017      selected_colors_vbo,
     2018      texcoords_vbo,
     2019      normals_vbo,
     2020      ubo,
     2021      model_mat_idx_vbo,
     2022      0);
    19792023
    19802024   return vao;
     
    19962040   map<GLuint, unsigned int> shaderCounts;
    19972041   map<GLuint, unsigned int> shaderUboCounts;
     2042
     2043   map<GLuint, BufferInfo>::iterator shaderIt;
     2044
     2045   for (shaderIt = shaderBufferInfo.begin(); shaderIt != shaderBufferInfo.end(); shaderIt++) {
     2046      shaderCounts[shaderIt->first] = 0;
     2047      shaderUboCounts[shaderIt->first] = 0;
     2048   }
    19982049
    19992050   vector<SceneObject*>::iterator it;
     
    20132064         num_objects++;
    20142065
    2015          if (shaderCounts.count((*it)->shader_program) == 0) {
    2016             shaderCounts[(*it)->shader_program] = (*it)->num_points;
    2017             shaderUboCounts[(*it)->shader_program] = 1;
    2018          } else {
    2019             shaderCounts[(*it)->shader_program] += (*it)->num_points;
    2020             shaderUboCounts[(*it)->shader_program]++;
    2021          }
     2066         shaderCounts[(*it)->shader_program] += (*it)->num_points;
     2067         shaderUboCounts[(*it)->shader_program]++;
    20222068
    20232069         it++;
     
    20292075   num_objects *= 2;
    20302076
    2031    map<GLuint, unsigned int>::iterator shaderIt;
     2077   map<GLuint, unsigned int>::iterator shaderCountIt;
    20322078   unsigned int lastShaderCount = 0;
    20332079   unsigned int lastShaderUboCount = 0;
     
    20402086   * object being added.
    20412087   */
    2042    for (shaderIt = shaderCounts.begin(); shaderIt != shaderCounts.end(); shaderIt++) {
     2088   for (shaderCountIt = shaderCounts.begin(); shaderCountIt != shaderCounts.end(); shaderCountIt++) {
    20432089      // When populating the buffers, leave as much empty space as space taken up by existing objects
    20442090      // to allow new objects to be added without immediately having to resize the buffers
    2045       shaderBufferInfo[shaderIt->first].vbo_base = lastShaderCount * 2;
    2046       shaderBufferInfo[shaderIt->first].ubo_base = lastShaderUboCount * 2;
    2047 
    2048       /*
    2049       cout << "shader: " << shaderIt->first << endl;
    2050       cout << "point counts: " << shaderCounts[shaderIt->first] << endl;
    2051       cout << "object counts: " << shaderUboCounts[shaderIt->first] << endl;
    2052       cout << "vbo_base: " << shaderBufferInfo[shaderIt->first].vbo_base << endl;
    2053       cout << "ubo_base: " << shaderBufferInfo[shaderIt->first].ubo_base << endl;
    2054       */
    2055 
    2056       shaderBufferInfo[shaderIt->first].vbo_offset = 0;
    2057       shaderBufferInfo[shaderIt->first].ubo_offset = 0;
    2058 
    2059       shaderBufferInfo[shaderIt->first].vbo_capacity = shaderCounts[shaderIt->first] * 2;
    2060       shaderBufferInfo[shaderIt->first].ubo_capacity = shaderUboCounts[shaderIt->first] * 2;
    2061 
    2062       lastShaderCount += shaderCounts[shaderIt->first];
    2063       lastShaderUboCount += shaderUboCounts[shaderIt->first];
     2091      shaderBufferInfo[shaderCountIt->first].vbo_base = lastShaderCount * 2;
     2092      shaderBufferInfo[shaderCountIt->first].ubo_base = lastShaderUboCount * 2;
     2093
     2094      shaderBufferInfo[shaderCountIt->first].vbo_offset = 0;
     2095      shaderBufferInfo[shaderCountIt->first].ubo_offset = 0;
     2096
     2097      shaderBufferInfo[shaderCountIt->first].vbo_capacity = shaderCounts[shaderCountIt->first] * 2;
     2098      shaderBufferInfo[shaderCountIt->first].ubo_capacity = shaderUboCounts[shaderCountIt->first] * 2;
     2099
     2100      lastShaderCount += shaderCounts[shaderCountIt->first];
     2101      lastShaderUboCount += shaderUboCounts[shaderCountIt->first];
    20642102   }
    20652103
     
    21152153   obj.ubo_offset = bufferInfo->ubo_base + bufferInfo->ubo_offset;
    21162154
    2117    glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    2118    glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]);
    2119 
    2120    glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);
    2121    glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]);
    2122 
    2123    glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    2124    for (unsigned int i = 0; i < obj.num_points; i++) {
    2125       glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset);
    2126    }
    2127 
    2128    if (obj.type != TYPE_LASER) {
    2129       glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    2130       glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]);
    2131 
    2132       glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo);
    2133       glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]);
    2134 
    2135       glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);
    2136       glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.normals.size() * sizeof(GLfloat), &obj.normals[0]);
    2137    }
    2138 
    2139    obj.model_mat = obj.model_transform * obj.model_base;
    2140    glBindBuffer(GL_UNIFORM_BUFFER, ubo);
    2141    glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat));
    2142 
    2143    if (obj.type == TYPE_ASTEROID) {
    2144       glUseProgram(asteroid_sp);
    2145 
    2146       ostringstream oss;
    2147       oss << "hp[" << obj.ubo_offset << "]";
    2148       glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp);
     2155   if (obj.ubo_offset == 0) {
     2156      objFirst = &obj;
     2157   }
     2158
     2159   if (obj.type != TYPE_EXPLOSION) {
     2160      glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
     2161      for (unsigned int i = 0; i < obj.num_points; i++) {
     2162         glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &obj.ubo_offset);
     2163      }
     2164
     2165      glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
     2166      glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.points.size() * sizeof(GLfloat), &obj.points[0]);
     2167
     2168      glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);
     2169      glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 2, obj.texcoords.size() * sizeof(GLfloat), &obj.texcoords[0]);
     2170
     2171      if (obj.type != TYPE_LASER) {
     2172         glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
     2173         glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.colors.size() * sizeof(GLfloat), &obj.colors[0]);
     2174
     2175         glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo);
     2176         glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.selected_colors.size() * sizeof(GLfloat), &obj.selected_colors[0]);
     2177
     2178         glBindBuffer(GL_ARRAY_BUFFER, normals_vbo);
     2179         glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * sizeof(GLfloat) * 3, obj.normals.size() * sizeof(GLfloat), &obj.normals[0]);
     2180      }
     2181
     2182      obj.model_mat = obj.model_transform * obj.model_base;
     2183      glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     2184      glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat));
     2185
     2186      if (obj.type == TYPE_ASTEROID) {
     2187         glUseProgram(asteroid_sp);
     2188
     2189         ostringstream oss;
     2190         oss << "hp[" << obj.ubo_offset << "]";
     2191         glUniform1f(glGetUniformLocation(asteroid_sp, oss.str().c_str()), ((Asteroid*)&obj)->hp);
     2192      }
    21492193   }
    21502194
     
    23162360                  GLuint color_sp, GLuint asteroid_sp, GLuint texture_sp, GLuint laser_sp, GLuint explosion_sp,
    23172361                  GLuint color_vao, GLuint asteroid_vao, GLuint texture_vao, GLuint laser_vao, GLuint explosion_vao,
    2318                   GLuint colors_vbo, GLuint selected_colors_vbo,
     2362                  GLuint colors_vbo, GLuint selected_colors_vbo, GLuint ubo,
    23192363                  SceneObject* selectedObject) {
    23202364
     
    23252369   if (selectedObject != NULL) {
    23262370      glBindBuffer(GL_ARRAY_BUFFER, selected_colors_vbo);
    2327       glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
     2371      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    23282372
    23292373      glDrawArrays(GL_TRIANGLES, selectedObject->vertex_vbo_offset, selectedObject->num_points);
     
    23332377   // Uncomment this code when I want to use selected colors again
    23342378   // glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    2335    // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
     2379   // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    23362380
    23372381   glDrawArrays(GL_TRIANGLES, shaderBufferInfo[color_sp].vbo_base, shaderBufferInfo[color_sp].vbo_offset);
     
    23542398   glDrawArrays(GL_TRIANGLES, shaderBufferInfo[laser_sp].vbo_base, shaderBufferInfo[laser_sp].vbo_offset);
    23552399
    2356    glDisable(GL_BLEND);
    2357 
    2358    renderExplosion(explosion_sp, explosion_vao, 0);
    2359 }
    2360 
    2361 void renderExplosion(GLuint explosion_sp, GLuint explosion_vao, GLuint tex) {
    2362    glEnable(GL_BLEND);
     2400   glUseProgram(explosion_sp);
     2401
    23632402   glEnable(GL_PROGRAM_POINT_SIZE);
    2364 
    2365    //glActiveTexture(GL_TEXTURE1);
    2366    //glBindTexture(GL_TEXTURE_2D, tex);
    2367    glUseProgram(explosion_sp);
    2368 
    23692403   glBindVertexArray(explosion_vao);
    23702404
    2371    glDrawArrays(GL_POINTS, 0, EXPLOSION_PARTICLE_COUNT);
     2405   glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     2406   glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objExplosion->model_mat));
     2407
     2408   glDrawArrays(GL_POINTS, 0, shaderBufferInfo[explosion_sp].vbo_offset);
     2409
     2410   glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     2411   glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(objFirst->model_mat));
    23722412
    23732413   glDisable(GL_PROGRAM_POINT_SIZE);
     
    24742514   Asteroid* obj = new Asteroid();
    24752515   obj->type = TYPE_ASTEROID;
     2516   obj->shader_program = shader;
    24762517   obj->hp = 10.0f;
    2477    obj->shader_program = shader;
    24782518
    24792519   obj->points = {
     
    25952635}
    25962636
     2637SceneObject* createExplosion(GLuint shader) {
     2638   SceneObject* obj = new SceneObject();
     2639   obj->type = TYPE_EXPLOSION;
     2640   obj->shader_program = shader;
     2641
     2642   obj->points = {};
     2643   obj->colors = {};
     2644
     2645   initObject(obj);
     2646   obj->num_points = EXPLOSION_PARTICLE_COUNT;
     2647
     2648   return obj;
     2649}
     2650
    25972651float getRandomNum(float low, float high) {
    25982652   return low + ((float)rand()/RAND_MAX) * (high-low);
Note: See TracChangeset for help on using the changeset viewer.