PDA

View Full Version : Vertex Arrays - help



buddnugget
12-07-2002, 02:03 PM
I am reading the redbook, and am now learning Vertex arrays -
whenever I declare glArrayElement()
it messes up with some ESP error.
I dont understand what I am doing wrong.
I have a GLfloat array containing verticies for x and y values, and enabled GL_VERTEX_ARRAY, and have the glVertexPointer() with paramters 2, GL_FLOAT, 0, verticies.

Please Help me

buddnugget
12-07-2002, 02:22 PM
here is all the code:

#include <GL/glut.h>

#define WS_X 600
#define WS_Y 600
#define WP_X 50
#define WP_Y 50
#define TITLE "OpenGL Pratice Program"

void init(void);
void display(void);
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);

int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WS_X,WS_Y);
glutInitWindowPosition(WP_X,WP_Y);
glutCreateWindow(TITLE);

init();

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;
}

void init(void)
{
gluOrtho2D (0.0, WS_X, 0.0, WS_Y);
}

void display(void)
{
static GLfloat verticies[] = {
100.0, 25.0,
100.0, 50.0,
100.0, 60.0,
125.0, 80.0};

glClearColor(1.0,1.0,1.0,0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2,GL_FLOAT,0,verticies);
glBegin(GL_TRIANGLES);
glArrayElement(2);
glArrayElement(3);
glArrayElement(4);
glEnd();
glutSwapBuffers();
}

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

void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
break;
default:
break;
}
}

t0y
12-07-2002, 02:32 PM
You're enabling GL_NORMAL_ARRAY without defining any normal array.

Since you don't use lighting anyway, you'd be better off commenting out the line "glEnableClientState(GL_NORMAL_ARRAY)"

buddnugget
12-07-2002, 02:44 PM
that did the trick,
thank you very much