PDA

View Full Version : what is wrong with this code?



openman
08-04-2008, 03:22 AM
Hi all, I'm a begin in graphic programming, I'm trying to draw a cube with glDrawElements() but the programme craches at running.
I figure not out what is wrong, could you help me ?
thanks. here is the code I want to run. I have not pasted the definitions in "points.h"


#include <GL/glut.h>
#include "points.h"

void init(void);
void display();
void reshape(GLsizei w, GLsizei h);


int main(int argc, char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(648,420);
glutInitWindowPosition(100,100);
glutCreateWindow("Maison de cyrildz V2");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);// set the screen to black color
glShadeModel(GL_FLAT);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,frontin dices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,rightin dices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,bottomi ndices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,backind ices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,leftind ices);
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,topindi ces);

glFlush();
}

void reshape( GLsizei w, GLsizei h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);
}

Zengar
08-04-2008, 04:22 AM
I cannnot see where you set up the vertex array (via glVertexPointer)