Changeset 05e43cf in opengl-game


Ignore:
Timestamp:
Apr 25, 2018, 2:44:28 AM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
07ed460
Parents:
7280257
Message:

Move the points for all models into one vbo

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • NewOpenGLGame.vcxproj

    r7280257 r05e43cf  
    135135  <ItemGroup>
    136136    <Text Include="gl.log" />
     137    <Text Include="opengl-notes.txt" />
    137138    <Text Include="TODO.txt" />
    138139  </ItemGroup>
  • new-game.cpp

    r7280257 r05e43cf  
    4343   mat4 model_mat;
    4444   GLuint shader_program;
     45   GLvoid* vbo_offset;
     46   unsigned int num_points;
    4547};
    4648
     
    233235   };
    234236
    235    // Each point is made of 3 floats
    236    int numPoints = (sizeof(points) / sizeof(float)) / 3;
    237 
    238237   GLfloat points2[] = {
    239238       0.5f,  0.5f,  0.0f,
     
    263262   };
    264263
    265    // Each point is made of 3 floats
    266    int numPoints2 = (sizeof(points2) / sizeof(float)) / 3;
    267 
    268264   mat4 T_model, R_model;
    269265
     
    271267   objects.push_back(SceneObject());
    272268   objects[0].shader_program = 0;
     269   objects[0].vbo_offset = (GLvoid*) (0 * sizeof(float) * 3);
     270   objects[0].num_points = 6;
    273271
    274272   T_model = translate(mat4(), vec3(0.45f, 0.0f, 0.0f));
     
    287285   objects.push_back(SceneObject());
    288286   objects[1].shader_program = 0;
     287   objects[1].vbo_offset = (GLvoid*) (6 * sizeof(float) * 3);
     288   objects[1].num_points = 6;
    289289
    290290   T_model = translate(mat4(), vec3(-0.5f, 0.0f, -1.00f));
     
    311311   glGenBuffers(1, &points_vbo);
    312312   glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    313    glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
     313   glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(points2), NULL, GL_DYNAMIC_DRAW);
     314
     315   glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(points), points);
     316   glBufferSubData(GL_ARRAY_BUFFER, sizeof(points), sizeof(points2), points2);
    314317
    315318   GLuint colors_vbo = 0;
     
    321324   glGenVertexArrays(1, &vao);
    322325   glBindVertexArray(vao);
    323    glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    324    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    325    glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    326    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    327326
    328327   glEnableVertexAttribArray(0);
    329328   glEnableVertexAttribArray(1);
    330 
    331    GLuint points2_vbo = 0;
    332    glGenBuffers(1, &points2_vbo);
    333    glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);
    334    glBufferData(GL_ARRAY_BUFFER, sizeof(points2), points2, GL_STATIC_DRAW);
    335329
    336330   GLuint colors2_vbo = 0;
     
    347341   glGenVertexArrays(1, &vao2);
    348342   glBindVertexArray(vao2);
    349    glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);
    350    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    351    // glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo);
    352    // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    353    glBindBuffer(GL_ARRAY_BUFFER, vt_vbo);
    354    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    355343
    356344   glEnableVertexAttribArray(0);
     
    515503         glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[*it].model_mat));
    516504
     505         glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
     506         glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vbo_offset);
     507
    517508         if (selectedObject == &objects[*it]) {
    518509            if (*it == 1) {
    519                glBindBuffer(GL_ARRAY_BUFFER, points2_vbo);
    520                glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    521 
    522510               glBindBuffer(GL_ARRAY_BUFFER, colors2_vbo);
    523                glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    524 
    525                glDrawArrays(GL_TRIANGLES, 0, numPoints2);
    526511            } else {
    527                glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    528                glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    529 
    530512               glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    531513               glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW);
    532                glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    533 
    534                glDrawArrays(GL_TRIANGLES, 0, numPoints);
    535514            }
    536515         } else {
    537             glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    538             glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    539 
    540516            glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
    541517            glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
    542             glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    543 
    544             glDrawArrays(GL_TRIANGLES, 0, numPoints);
    545518         }
     519
     520         glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
     521
     522         glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points);
    546523      }
    547524
     
    552529         glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objects[*it].model_mat));
    553530
    554          glDrawArrays(GL_TRIANGLES, 0, numPoints2);
     531         glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
     532         glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, objects[*it].vbo_offset);
     533
     534         glBindBuffer(GL_ARRAY_BUFFER, vt_vbo);
     535         glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
     536
     537         glDrawArrays(GL_TRIANGLES, 0, objects[*it].num_points);
    555538      }
    556539
Note: See TracChangeset for help on using the changeset viewer.