PDA

View Full Version : vertex arrays



02-14-2002, 05:53 PM
Hi everyone, Iīm also new on OpenGL and while running some of the examples of the red book, I found out Iīm having problems with vertex arrays, hereīs the code:

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

#define X .525731112119133606
#define Z .850650808352039932

void init(void);
void display(void);
void reshape(int, int);

static GLfloat vdata[36] = { -X, 0.0, Z, X, 0.0, Z, -X, 0.0, -Z, X, 0.0, -Z,
0.0, Z, X, 0.0, Z, -X, 0.0, -Z, X, 0.0, -Z, -X,
Z, X, 0.0, -Z, X, 0.0, Z, -X, 0.0, -Z, -X, 0.0};
static GLuint tindices[60] = { 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};

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;
}

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vdata);
}

void display(void)
{
int i;

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);/*
glBegin(GL_TRIANGLES);
for(i = 0; i < 60; i += 3)
{
glArrayElement(tindices[i]);
glArrayElement(tindices[i + 1]);
glArrayElement(tindices[i + 2]);
}
glEnd();/*/
glDrawElements(GL_TRIANGLES, 60, GL_UNSIGNED_INT, tindices);
glFlush();
}

void reshape(int w, int h)
{
glViewport(0.0, 0.0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}

As you can see itīs the icosahedron example and it runs quite well using glArrayElement, but not with glDrawElements, I donīt know whatīs going wrong, I sincerely hope someone does.

Iīm running a Radeon 8500 and Iīve heard about some problems on their vertex arrays driver implementation (just guessing).

And another question: Visual C seems to run OpenGL 1.1, does it require a 1.3 header to use the new functions?, I already know about the library thing, but doesnīt it also require headers for the new ones?

thanx in advanced.

zed
02-15-2002, 11:28 AM
it should work try
init(); glDrawElements(...) ?

02-15-2002, 05:35 PM
sorry but I didnīt understand, again please?

02-15-2002, 05:42 PM
I tried using init(); glDrawElements(); inside the display() function, but it doesnīt work.

Aster
02-15-2002, 06:29 PM
Did you try using glColor? I don't think you are coloring your vertices.

02-16-2002, 10:28 AM
After reading your last note I did, but it didnīt work.

From what Iīve seen, it seems the program is ok, maybe itīs something relating drivers?

Could someone tell me if it runs well on his (her) system?

In case it may help, Iīm using Windows XP and Visual C++ 6.0 sp 5.