PDA

View Full Version : can you tell me why this program don't work ?



airseb
07-11-2002, 01:13 PM
we just see tree lines of the same vertex but not what i want http://www.opengl.org/discussion_boards/ubb/frown.gif

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

#define X .525731112119133606
#define Z .850650808352039932


void display ()
{
static GLfloat tableau_entrelace [] = {1.0, 1.0, 1.0, -X, 0.0, Z, 1.0, 1.0, 1.0, X, 0.0, Z,
1.0, 1.0, 1.0, -X, 0.0, -Z, 1.0, 1.0, 1.0, X, 0.0, -Z, 1.0, 1.0, 1.0, 0.0, Z, X,
1.0, 1.0, 1.0, 0.0, Z, -X, 1.0, 1.0, 1.0, 0.0, -Z, X, 1.0, 1.0, 1.0, 0.0, -Z, -X,
1.0, 1.0, 1.0, Z, X, 0.0, 1.0, 1.0, 1.0, -Z, X, 0.0,1.0, 1.0, 1.0, Z, -X, 0.0,
1.0, 1.0, 1.0, -Z, -X, 0.0} ;

glInterleavedArrays (GL_C3F_V3F, 0, tableau_entrelace) ;

static GLuint indices [20][3]= {1,4,0,4,9,0,4,5,9,8,5,4,1,8,4,1,10,8,10,3,8,8,3,5 ,3,2,5,
3,7,2,3,10,7,10,6,7,6,11,7,6,0,11,6,1,0,10,1,6,11, 0,9,2,11,9,5,2,9,11,2,7};

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


glDrawElements (GL_TRIANGLES, 60, GL_UNSIGNED_BYTE, indices) ;

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 (0.0, 0.0, 0.0, 0.0) ;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable( GL_DEPTH_TEST );

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-10.0 , 10.0, -10.0, 10.0, -5.0, 20.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutDisplayFunc (display) ;
glutMainLoop () ;

}

zeckensack
07-11-2002, 09:39 PM
Originally posted by airseb:

static GLuint indices [20][3]=...

...

glDrawElements (GL_TRIANGLES, 60, GL_UNSIGNED_BYTE, indices) ;
There you have it. You declared indices as an array of uints and used it as an array of ubytes. Either change the declaration to

static GLubyte indices[20][3]=....

or (preferred) change the DrawElements call to

glDrawElements (GL_TRIANGLES, 60, GL_UNSIGNED_INT, indices);

airseb
07-12-2002, 01:00 AM
thanks http://www.opengl.org/discussion_boards/ubb/biggrin.gif