PDA

View Full Version : glInterleavedArrays & glDrawElements



Ryuga
07-16-2002, 12:36 AM
Hi,
I'm try draw some stuff using glInterleavedArrays + glDrawElements.

This is a a simplified version of the problem I'm experiencing:

void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(0.0,0.0,0.0, 0.0,0.0,-1.0, 0.0,1.0,0.0);
glTranslatef(0.0,0.0,-10.0);

static Vertex vertices[] = { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0};
glInterleavedArrays(GL_V3F,0,vertices);

static GLint indices[] = {0, 1, 2, 3};
glDrawElements(GL_QUAD_STRIP,4,GL_UNSIGNED_INT,ind ices);

glutSwapBuffers();
glFlush();
}


I try to comment the istructions

gluLookAt(...);

I cannot see anything
Do you know why?

Relic
07-16-2002, 12:57 AM
Very simple, the glTranslatef(0.0f, 0.0f, -10,0f); moves the geometry 9 units behind the zFar plane of the default viewing frustum. It works if you remove that.

Some other hints for the future:
- Your geomtry is defined clockwise, default for front faces is counter-clockwise in case you'll add culling sometime.
- Use GLuint for the indices.

Ryuga
07-16-2002, 01:17 AM
Thanks a lot... also for the hints, I will follow them! http://www.opengl.org/discussion_boards/ubb/smile.gif

One last question:

void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

//gluLookAt(0.0,0.0,0.0, 0.0,0.0,-1.0, 0.0,1.0,0.0);
glTranslatef(0.0,0.0,-10.0);

static Vertex vertices[] = { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0};
glInterleavedArrays(GL_V3F,0,vertices);

// NEW NEW NEW
int i;
int count = 4;
glBegin(GL_POINTS);
for(i=0; i< count; i++)
glArrayElement(i);
glEnd();
// END NEW NEW NEW

static GLuint indices[] = {0, 1, 2, 3};
glDrawElements(GL_QUAD_STRIP,4,GL_UNSIGNED_INT,ind ices);

glutSwapBuffers();
glFlush();
}

Why it works in this way (just curiosity I'm not going to draw twice!)?

Relic
07-16-2002, 07:09 AM
I don't understand. This is not working if that's all you code (assuming your projection matrix is identity.)

This works for me:



static GLfloat vertices[] = { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0}; // assuming your vertex struct is just a float.
static GLuint indices[] = {0, 1, 2, 3};
int i;
int count = 4;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(0.0,0.0,0.0, 0.0,0.0,-1.0, 0.0,1.0,0.0);
// glTranslatef(0.0,0.0,-10.0); This creates the black-screen-of-death

glInterleavedArrays(GL_V3F,0,vertices);

// NEW NEW NEW
glBegin(GL_POINTS);
for(i=0; i< count; i++)
glArrayElement(i);
glEnd();
glFlush(); ( I used single buffered.
// END NEW NEW NEW
// Put a breakpoint on the next instruction and you'll see the point in the origin.
// Draws a nice white rectangle in the first quadrant.
glDrawElements(GL_QUAD_STRIP,4,GL_UNSIGNED_INT,ind ices);

glFlush();