• Advertisement
Sign in to follow this  

vertex array problem

This topic is 2895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm going to make a cube with vertex array..but i got a problem here.. actually the code is exactly same with the source code in the book.. i hope anyone can help me.. it gives an error like these : First-chance exception at 0x69918400 in chess.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x69918400 in chess.exe: 0xC0000005: Access violation reading location 0x00000000. and, this is the source code: #include<stdlib.h> #include<GL/glut.h> GLfloat vertices[] = {-1.0,-1.0,-1.0,1.0,-1.0,-1.0, 1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0, 1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0}; GLfloat colors[] = {0.0,0.0,0.0,1.0,0.0,0.0, 1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0, 1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0}; GLubyte cubeIndices[24] = {0,3,2,1,2,3,7,6, 0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4}; static GLfloat theta[] = {0.0,0.0,0.0}; static GLint axis = 2; void display(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(theta[0],1.0,0.0,0.0); glRotatef(theta[1],0.0,1.0,0.0); glRotatef(theta[2],0.0,0.0,1.0); glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE, cubeIndices); glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,1.0,1.0); glEnd(); glFlush(); glutSwapBuffers(); } void spinCube(){ theta[axis]+=2.0; if(theta[axis]>360.0) theta[axis]-=360.0; glutPostRedisplay(); } void mouse(int btn,int state,int x,int y){ if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) axis = 0; if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) axis = 1; if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) axis = 2; } void MyReshape(int w, int h){ glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w <= h){ glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat) w, 2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); } else{ glOrtho(-2.0*(GLfloat)w/(GLfloat)h, 2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-10.0,10.0); } glMatrixMode(GL_MODELVIEW); } void main(int argc,char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500,500); glutCreateWindow("Chess"); glutReshapeFunc(MyReshape); glutDisplayFunc(display); glutIdleFunc(spinCube); glutMouseFunc(mouse); glEnable(GL_DEPTH_TEST); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,vertices); glColorPointer(3,GL_FLOAT,0,colors); glColor3f(1.0,1.0,1.0); glutMainLoop(); }

Share this post


Link to post
Share on other sites
Advertisement
It looks like one of the gl functions isn't supported (NULL)

Set a debug brake in your main and display method. When the debug break is hit step through your code until the exception occurs. Also try checking variables before stepping to the next line to see the possible changes.

Share this post


Link to post
Share on other sites
You called glEnableClientState(GL_NORMAL_ARRAY);
but didnt call glNormalPointer

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement