Sto tentando di creare 2 box in OpenGL, ma appaiono all'interno e talvolta non si sovrappongono correttamente. Video http://www.youtube.com/watch?v=IVJu4zJFp7QOpenGL esegue il rendering di caselle all'interno
Immagino sia un problema di profondità ma non sono stato in grado di capire cosa sto facendo male.
Ecco il codice che sto utilizzando per inizializzare:
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
Qui è la mia funzione distplay glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
drawYellowBox();
drawBlueBox();
E il codice che sto usando per disegnare le forme:
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(0.15, 0.15, 0.0);
// draw front
glVertex3f(-1.0, -1.5, 1.0);
glVertex3f(1.0, -1.5, 1.0);
glVertex3f(0.75, 1.5, 0.75);
glVertex3f(-0.75, 1.5, 0.75);
glColor3f(0.3, 0.3, 0.0);
// draw back
glVertex3f(1.0, -1.5, -1.0);
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f(-0.75, 1.5, -0.75);
glVertex3f(0.75, 1.5, -0.75);
glColor3f(0.45, 0.45, 0.0);
// draw left
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f(-1.0, -1.5, 1.0);
glVertex3f(-0.75, 1.5, 0.75);
glVertex3f(-0.75, 1.5, -0.75);
glColor3f(0.6, 0.6, 0.0);
// draw right
glVertex3f(1.0, -1.5, 1.0);
glVertex3f(1.0, -1.5, -1.0);
glVertex3f(0.75, 1.5, -0.75);
glVertex3f(0.75, 1.5, 0.75);
glColor3f(0.75, 0.75, 0.0);
// draw top
glVertex3f(-0.75, 1.5, 0.75);
glVertex3f(0.75, 1.5, 0.75);
glVertex3f(0.75, 1.5, -0.75);
glVertex3f(-0.75, 1.5, -0.75);
glColor3f(0.9, 0.9, 0.0);
// draw bottom
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f(1.0, -1.5, -1.0);
glVertex3f(1.0, -1.5, 1.0);
glVertex3f(-1.0, -1.5, 1.0);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,2.5,0.0);
glRotatef(joint_ui_data->getDOF(Keyframe::HEAD), 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
glColor3f(0.0, 0.15, 0.15);
// draw front face
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f(0.8, -0.45, 0.8);
glVertex3f(0.75, 0.45, 0.75);
glVertex3f(-0.75, 0.45, 0.75);
glColor3f(0.0, 0.3, 0.3);
// draw back face
glVertex3f(0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.75, 0.45, -0.75);
glVertex3f(0.75, 0.45, -0.75);
glColor3f(0.0, 0.45, 0.45);
// draw left face
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f(-0.75, 0.45, 0.75);
glVertex3f(-0.75, 0.45, -0.75);
glColor3f(0.0, 0.6, 0.6);
// draw right face
glVertex3f(0.8, -0.45, 0.8);
glVertex3f(0.8, -0.45, -0.8);
glVertex3f(0.75, 0.45, -0.75);
glVertex3f(0.75, 0.45, 0.75);
glColor3f(0.0, 0.75, 0.75);
// draw top
glVertex3f(-0.75, 0.45, 0.75);
glVertex3f(0.75, 0.45, 0.75);
glVertex3f(0.75, 0.45, -0.75);
glVertex3f(-0.75, 0.45, -0.75);
glColor3f(0.0, 0.9, 0.9);
// draw bottom
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f(0.8, -0.45, 0.8);
glVertex3f(0.8, -0.45, -0.8);
glEnd();
glPopMatrix();
Grazie.
Purtroppo, questo doesn risolve il problema Ho provato a riordinare i vertici, ma senza alcun effetto. Tornando ai vertici originali e cambiando glFrontFace in CW, il rendering non è stato ancora risolto. – Ares
@Ares guarda la risposta modificata. – Vallentin
Anche questo era il mio problema. (Usando Ubuntu 16.04, python GL e GLUT. Ho provato e isolato usando GLUT per disegnare cubi al posto dei miei vertici: se il cubo di GLUT è all'interno, allora non è un problema di avvolgimento ma ha bisogno che il flag di profondità si accenda.) –