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.