PDA

View Full Version : Problem with glDrawRangeElements



swethasharma
12-29-2011, 01:32 AM
Hello,

This is my code


#include <stdio.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/freeglut.h>


void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);


static GLint vertices[]={200.0,350.0,0.0,
230.0,300.0,0.0,
200.0,250.0,0.0,
170.0,300.0,0.0,
230.0,200.0,0.0,
200.0,150.0,0.0,
170.0,200.0,0.0,
250.0,280.0,0.0,
300.0,250.0,0.0,
250.0,220.0,0.0,
150.0,280.0,0.0,
100.0,250.0,0.0,
150.0,220.0,0.0};



static GLuint index1[]={0,1,2,3};
static GLuint index2[]={2,4,5,6};
static GLuint index3[]={2,7,8,9};
static GLuint index4[]={2,10,11,12};
static GLuint* indices[4]={index1,index2,index3,index4};

GLsizei count[]={4,4,4,4};

glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3,GL_INT,0,vertices);


glDrawRangeElements(GL_QUADS,1,3,12,GL_UNSIGNED_IN T,indices);



glFlush();
}

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 init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
/* glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1.0,0.0,1.0,1-1.0,1.0);*/

}

int main(int argc,char** argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,600);
glutInitWindowPosition(100,100);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}


I am getting a blank screen when i run the code. Where is the mistake? Thanks in advance
-swetha

Alfonse Reinheart
12-29-2011, 02:06 AM
glDrawRangeElements(GL_QUADS,1,3,12,GL_UNSIGNED_IN T,indices);

This line of code says to draw QUADS using 12 indices taken from `indices`, of unsigned integer type. But it also promises that all of the indices pulled from `indices` will be between 1 and 3 in value.

The range specifies the range of index values in the index region being rendered from. Since your index list seems to use indices outside the [1,3] range, you need to work on your range for drawing.

Now granted, using a proper range (or just using `glDrawElements`) won't solve your problem. And that's because `indices` is not a GLuint pointer. It is an array of GLuint pointers. The `glDrawElements` functions do not take arrays of arrays; they take arrays, period. They take an ordered list of types. And you're not passing that.

`index1` is an array of GLuint's. As is `index2` and so forth. But `indices` itself is not; it is an array of pointers, not an array of GLuints.

You need to put those different arrays in the same array. You need one long array of indices, not four short arrays.

swethasharma
12-29-2011, 05:20 AM
Hi Alfonse,

Thankyou very much for your help .i understood the mistake and i have got the output.
-swetha