PDA

View Full Version : glDrawElements problem



wh1sp3rik
11-11-2009, 01:50 PM
Hello :) i have strange problem with this command :) it just doesn't show anything and i really došn't know why.

this is filling buffer with data.


this->TerrainLOD1[0] = 0;
this->TerrainLOD1[1] = 0;
this->TerrainLOD1[2] = 0;

this->TerrainLOD1[3] = 2;
this->TerrainLOD1[4] = 0;
this->TerrainLOD1[5] = 0;

this->TerrainLOD1[6] = 2;
this->TerrainLOD1[7] = 0;
this->TerrainLOD1[8] = 2;

this->TerrainLOD1[9] = 0;
this->TerrainLOD1[10] = 0;
this->TerrainLOD1[11] = 2;


this->TerrainLOD1_INDICES[0] = 0;
this->TerrainLOD1_INDICES[1] = 1;
this->TerrainLOD1_INDICES[2] = 2;

this->TerrainLOD1_INDICES[3] = 0;
this->TerrainLOD1_INDICES[4] = 3;
this->TerrainLOD1_INDICES[5] = 2;

glGenBuffers(1, &this->VBO_BUFFER_ID1);
glBindBuffer(GL_ARRAY_BUFFER, this->VBO_BUFFER_ID1);
glBufferData(GL_ARRAY_BUFFER, sizeof(TerrainLOD1), TerrainLOD1, GL_STATIC_DRAW);


glGenBuffers(1, &this->VBO_BUFFER_ID1_INDICES);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->VBO_BUFFER_ID1_INDICES);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(TerrainLOD1_INDICES), TerrainLOD1_INDICES, GL_STATIC_DRAW);


This is drawing part. When i uncommend glBegin - glend .. it shows an triangle. i wanted to avoid bad camera angle or similar.


glPushMatrix();
//glTranslatef(x,y,z);


glBindBuffer(GL_ARRAY_BUFFER, TerrainManager::TERRAIN->VBO_BUFFER_ID1);
glVertexPointer(3, GL_FLOAT, 0 , 0);

glEnableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, TerrainManager::TERRAIN->VBO_BUFFER_ID1_INDICES);
glIndexPointer(GL_UNSIGNED_SHORT, 0, 0);

glEnableClientState(GL_INDEX_ARRAY);


glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);

/*
glBegin(GL_TRIANGLES);
glVertex3f(0,0,0);
glVertex3f(2,0,0);
glVertex3f(2,0,2);
glEnd();
*/

glPopMatrix();


What's bad on this code ? Thank yo uvery much

DmitryM
11-11-2009, 01:56 PM
You store indices as GL_UNSIGNED_SHORT (see glIndexPointer) while trying to draw them as GL_UNSIGNED_INT (see glDrawElements).

wh1sp3rik
11-11-2009, 04:09 PM
Thanks for reply.

I tried to set both to GL_UNSIGNED_SHORT or GL_UNSIGNED_INT .. but still, window is black as a hell :D

DmitryM
11-11-2009, 04:25 PM
Show your his->TerrainLOD1 and this->TerrainLOD1_INDICES declaration, please.

BTW, have you got the code from the sky or went into the problem iteratively? do you have a version that draws something? a line?

wh1sp3rik
11-12-2009, 03:39 AM
lol, i got it.

I filled index buffer with FLOATS, but i read it as INTs .. damn. Pretty stupid error.

Thanks for helping :)