PDA

View Full Version : why the rendering of my cube is not perfect ?



airseb
06-27-2002, 03:20 PM
there is an error with GL_LINE and more with GL_FILL


#include <GL/glut.h>
#include <stdlib.h>


void display (void)
{


static GLint vertices [] = {1,1,0, 10,1,0, 10,10,0, 1,10,0, -2,8,10, 7,8,10,
7,17,10, -2,17,10};

static GLfloat colors_RGB [] = {1.0,0.4,0.4, 0.4,0.4,1.0, 0.8,1.0,0.2, 0.75,0.75,0.75,
0.35,0.35,0.35, 0.5,0.5,0.5};

glEnableClientState (GL_COLOR_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (3, GL_FLOAT, 0, colors_RGB);
glVertexPointer (3, GL_INT, 0, vertices);

static GLubyte toutLesSommets [] = { 0,1,2, 2,3,0, 1,5,6, 6,2,1, 4,5,6, 7,6,4, 4,0,3, 3,7,4, 0,1,5, 5,4,0, 3,2,6, 6,7,3 };

glPolygonMode (GL_FRONT, GL_LINE) ;
glFrontFace (GL_CCW) ;
glEnable (GL_CULL_FACE) ;
glCullFace (GL_BACK) ;

glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, toutLesSommets) ;

glutSwapBuffers() ;
glFlush () ;
}

void main (int argc, char** argv)

{
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;

glClearColor (1.0, 1.0, 1.0, 1.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(25.0 , -20.0, 20.0, -20.0, -10.0, 16.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutDisplayFunc (display) ;
glutMainLoop () ;

}

Gavin
07-01-2002, 02:19 AM
Error in what way?

Relic
07-01-2002, 03:56 AM
Because you
- didn't enable GL_DEPTH_TEST.
- didn't clear the depth buffer.
- have triangle (7,6,4) in the wrong order, it needs to be (6,7,4).