Skip to content

Commit f59f93d

Browse files
committed
Rename variables to avoid confusion. Fixes #108 .
1 parent 1dfd117 commit f59f93d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

examples/viewer/viewer.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class timerutil {
123123
};
124124

125125
typedef struct {
126-
GLuint vb; // vertex buffer
126+
GLuint vb_id; // vertex buffer id
127127
int numTriangles;
128128
size_t material_id;
129129
} DrawObject;
@@ -289,7 +289,7 @@ static bool LoadObjAndConvert(float bmin[3], float bmax[3],
289289
{
290290
for (size_t s = 0; s < shapes.size(); s++) {
291291
DrawObject o;
292-
std::vector<float> vb; // pos(3float), normal(3float), color(3float)
292+
std::vector<float> buffer; // pos(3float), normal(3float), color(3float)
293293
for (size_t f = 0; f < shapes[s].mesh.indices.size() / 3; f++) {
294294
tinyobj::index_t idx0 = shapes[s].mesh.indices[3 * f + 0];
295295
tinyobj::index_t idx1 = shapes[s].mesh.indices[3 * f + 1];
@@ -374,12 +374,12 @@ static bool LoadObjAndConvert(float bmin[3], float bmax[3],
374374
}
375375

376376
for (int k = 0; k < 3; k++) {
377-
vb.push_back(v[k][0]);
378-
vb.push_back(v[k][1]);
379-
vb.push_back(v[k][2]);
380-
vb.push_back(n[k][0]);
381-
vb.push_back(n[k][1]);
382-
vb.push_back(n[k][2]);
377+
buffer.push_back(v[k][0]);
378+
buffer.push_back(v[k][1]);
379+
buffer.push_back(v[k][2]);
380+
buffer.push_back(n[k][0]);
381+
buffer.push_back(n[k][1]);
382+
buffer.push_back(n[k][2]);
383383
// Combine normal and diffuse to get color.
384384
float normal_factor = 0.2;
385385
float diffuse_factor = 1 - normal_factor;
@@ -396,16 +396,16 @@ static bool LoadObjAndConvert(float bmin[3], float bmax[3],
396396
c[1] /= len;
397397
c[2] /= len;
398398
}
399-
vb.push_back(c[0] * 0.5 + 0.5);
400-
vb.push_back(c[1] * 0.5 + 0.5);
401-
vb.push_back(c[2] * 0.5 + 0.5);
399+
buffer.push_back(c[0] * 0.5 + 0.5);
400+
buffer.push_back(c[1] * 0.5 + 0.5);
401+
buffer.push_back(c[2] * 0.5 + 0.5);
402402

403-
vb.push_back(tc[k][0]);
404-
vb.push_back(tc[k][1]);
403+
buffer.push_back(tc[k][0]);
404+
buffer.push_back(tc[k][1]);
405405
}
406406
}
407407

408-
o.vb = 0;
408+
o.vb_id = 0;
409409
o.numTriangles = 0;
410410

411411
// OpenGL viewer does not support texturing with per-face material.
@@ -416,12 +416,12 @@ static bool LoadObjAndConvert(float bmin[3], float bmax[3],
416416
o.material_id = materials.size() - 1; // = ID for default material.
417417
}
418418

419-
if (vb.size() > 0) {
420-
glGenBuffers(1, &o.vb);
421-
glBindBuffer(GL_ARRAY_BUFFER, o.vb);
422-
glBufferData(GL_ARRAY_BUFFER, vb.size() * sizeof(float), &vb.at(0),
419+
if (buffer.size() > 0) {
420+
glGenBuffers(1, &o.vb_id);
421+
glBindBuffer(GL_ARRAY_BUFFER, o.vb_id);
422+
glBufferData(GL_ARRAY_BUFFER, buffer.size() * sizeof(float), &buffer.at(0),
423423
GL_STATIC_DRAW);
424-
o.numTriangles = vb.size() / (3 + 3 + 3 + 2) / 3; // 3:vtx, 3:normal, 3:col, 2:texcoord
424+
o.numTriangles = buffer.size() / (3 + 3 + 3 + 2) / 3; // 3:vtx, 3:normal, 3:col, 2:texcoord
425425

426426
printf("shape[%d] # of triangles = %d\n", static_cast<int>(s),
427427
o.numTriangles);
@@ -545,11 +545,11 @@ static void Draw(const std::vector<DrawObject>& drawObjects, std::vector<tinyobj
545545
GLsizei stride = (3 + 3 + 3 + 2) * sizeof(float);
546546
for (size_t i = 0; i < drawObjects.size(); i++) {
547547
DrawObject o = drawObjects[i];
548-
if (o.vb < 1) {
548+
if (o.vb_id < 1) {
549549
continue;
550550
}
551551

552-
glBindBuffer(GL_ARRAY_BUFFER, o.vb);
552+
glBindBuffer(GL_ARRAY_BUFFER, o.vb_id);
553553
glEnableClientState(GL_VERTEX_ARRAY);
554554
glEnableClientState(GL_NORMAL_ARRAY);
555555
glEnableClientState(GL_COLOR_ARRAY);
@@ -579,11 +579,11 @@ static void Draw(const std::vector<DrawObject>& drawObjects, std::vector<tinyobj
579579
glColor3f(0.0f, 0.0f, 0.4f);
580580
for (size_t i = 0; i < drawObjects.size(); i++) {
581581
DrawObject o = drawObjects[i];
582-
if (o.vb < 1) {
582+
if (o.vb_id < 1) {
583583
continue;
584584
}
585585

586-
glBindBuffer(GL_ARRAY_BUFFER, o.vb);
586+
glBindBuffer(GL_ARRAY_BUFFER, o.vb_id);
587587
glEnableClientState(GL_VERTEX_ARRAY);
588588
glEnableClientState(GL_NORMAL_ARRAY);
589589
glDisableClientState(GL_COLOR_ARRAY);

0 commit comments

Comments
 (0)