PDA

View Full Version : What is the reason?



_student
10-20-2004, 09:50 PM
GLuint vertexArray[] = { 0, 1, 2, 3, 4, 5 };

glDrawRangleElements(GL_POLYGON, 2, 5, 4,
GL_UNSIGNED_INT, vertexArray);

But it will draw vertexArray[0123], what is the
reason?

Hylke Donker
10-20-2004, 10:02 PM
Maybe the coordinates aren't correct(check the OpenGL red book for valid and invalid polygons).

_student
10-20-2004, 11:25 PM
Thank you for your help. But if I changed GL_POLYGON to GL_LINES, the result is same.

_student
10-20-2004, 11:41 PM
This is the code.

#include <gl/glut.h>
#include <gl/glprocs.h>

static GLint vertices[] = { 25, 25,
100, 325,
175, 25,
175, 325,
250, 25,
325, 325 };

static GLfloat colors[] = { 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
0.75, 0.75, 0.75,
0.35, 0.35, 0.35,
0.5, 0.5, 0.5 };

void setupVertex()
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(2, GL_INT, 0, vertices);
glColorPointer(3, GL_FLOAT, 0, colors);
}

void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 400.0, 0.0, 400.0);
setupVertex();
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
GLuint front[] = {0, 1, 2, 3, 4, 5 };
//glDrawElements(GL_LINES, 6, GL_UNSIGNED_INT, front);
glDrawRangeElements(GL_LINES, 2, 5, 4, GL_UNSIGNED_INT, front);
glFlush();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("");

init();
glutDisplayFunc(display);
glutMainLoop();

return 0;
}

MattS
10-21-2004, 02:16 AM
Your arguments are wrong for glDrawRangeElements.

The second parameter is the minimum index you use, not where you start from.
The third parameter is the maximum index you use.

The code you supplied will indeed render 0,1,2,3 but will also supply an incorrect range.

glDrawRangeElements will always start from the pointer you give it. It is used to tell the graphics card that you will not use indices outside the supplied range (potential for optimisation).

To render three lines you call:
glDrawRangeElements(GL_LINES, 0, 5, 6, front);

To render just the last two lines you use
glDrawRangeElements(GL_LINES, 2, 5, 4, &front[2]);

Matt

_student
10-21-2004, 03:22 AM
Thanks.