I have a program that is to be capable of several things, first, if I hit a button multiple times it will toggle between multiple modes.
Right now though while I can toggle between either a wireframe or a solid I can’t have both. I know conceptually the solution is to have “two” objects, one wiremesh and one a solid and then use gloffset etc etc etc.
However I can’t seem to get the code to work:
void display()
{
//Background color
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Matrix setup
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, width, height);
glLoadIdentity();
gluPerspective(40, (float)width / (float)height, 0.1, 1000);
// Matrix setup
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES);
for (int i = 0; i<mesh->nfaces.size(); i += 1)
for (int j = 0; j<3; j += 1){
glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
mesh->normal[mesh->nfaces[i][j]][1],
mesh->normal[mesh->nfaces[i][j]][2]);
glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
mesh->vertex[mesh->faces[i][j]][1],
mesh->vertex[mesh->faces[i][j]][2]);
}
cout << "Here 1" << endl;
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//glEnable(GL_POLYGON_OFFSET_LINE);
//glPolygonOffset(-2.0f, -2.0f);
glColor3f(1.0f, 0.0f, 0.0f);
//glLineWidth(1.0f);
//draw object
glBegin(GL_TRIANGLES);
for (int i = 0; i<mesh->nfaces.size(); i += 1)
for (int j = 0; j<3; j += 1){
glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
mesh->normal[mesh->nfaces[i][j]][1],
mesh->normal[mesh->nfaces[i][j]][2]);
glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
mesh->vertex[mesh->faces[i][j]][1],
mesh->vertex[mesh->faces[i][j]][2]);
}
glEnd();
cout << "Here 2" << endl;
//glDisable(GL_POLYGON_OFFSET_LINE);
glutSwapBuffers();
}
Here’s my main with callbacks.
void main(int argc, char **argv)
{
// GLUT initialization.
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(width, height);
glutCreateWindow("CodeBase");
// Register call backs.
initialize();
glutDisplayFunc(display);
glutReshapeFunc(reshapeMainWindow);
glutMotionFunc(mouse_motion);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse_button);
// Enter GLUT loop.
glutMainLoop();
delete mesh;
}
Here’s my keyboard function:
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case(27) :
exit(0);
break;
case('s') :
{
int myFlagCtr = getFlagCtr();
cout << "Pressed Before: " << getFlagCtr() << endl;
if (myFlagCtr == 0) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
setFlagCtr(1);
}
else if (myFlagCtr == 1) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
setFlagCtr(2);
}
else if (myFlagCtr == 2) {
setFlagCtr(0);
cout << "Pressed Before: " << getFlagCtr() << endl;
}
break;
}
}
}
Right now I just want to see if there’s a way, ANY way at all, to do both wiremesh+solid.
Thanks.