Gerard-Meier

OpenGL draw routine

Jun 18th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. void onDraw(void) {
  2.         glPushMatrix();
  3.         glLoadIdentity();
  4.  
  5.         //glScaled(10, 10, 10);
  6.  
  7.         //cout << "num faces:" << mesh->f->size() << endl;
  8.  
  9.        
  10.         // Foreach face:
  11.         for(int i = 0; i < mesh->f->size(); ++i) {
  12.             //glBegin(GL_POLYGON);
  13.             glBegin(GL_LINES);
  14.             glColor3f(1.0f, 0.0f, 0.0f);
  15.  
  16.             // Foreach vertex index:
  17.             for(int j = 0; j < mesh->f->at(i).vertexIndices.size(); ++j) {
  18.  
  19.                 // Support for broken models!
  20.                 if(mesh->f->at(i).vertexIndices.at(j)-1 >= mesh->v->size()) {
  21.                     cout << "j:" << j << " index out of bounds! " << (mesh->f->at(i).vertexIndices.at(j)) << " is more than " << mesh->v->size() << endl;
  22.                 } else {
  23.  
  24.                
  25.                     // Note: The -1 is required b.c obj files start counting at 1, and the computer starts at  0.
  26.                     glVertex3f(
  27.                         mesh->v->at(mesh->f->at(i).vertexIndices.at(j) - 1).x,
  28.                         mesh->v->at(mesh->f->at(i).vertexIndices.at(j) - 1).y,
  29.                         mesh->v->at(mesh->f->at(i).vertexIndices.at(j) - 1).z
  30.                     );
  31.                 }
  32.             }
  33.  
  34.             glEnd();
  35.         }
  36.        
  37.         glTranslatef(center.x, center.y, center.z);
  38.         glPopMatrix();
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment