glDrawElements question
if I have this variable
how would I use glDrawElements, I think the fact that it is a 3D array is what is screwing me up. Here i what I was trying
I checked the data in the quad array and vertex array, and it is good, so I think this is my problem.
PHP Code:
unsigned short theQuad[numberOfTextures][50000][4];
how would I use glDrawElements, I think the fact that it is a 3D array is what is screwing me up. Here i what I was trying
PHP Code:
for (i=0; i < numberOfTextures; i++)
{
if (theQuadCount[i] != 0) {
glBindTexture(GL_TEXTURE_2D, gv->texture[i]);
glDrawElements(GL_QUADS, theQuadCount[i]*4 - 4, GL_UNSIGNED_SHORT, quads[i]);
}
}
I checked the data in the quad array and vertex array, and it is good, so I think this is my problem.
<edit: oops! nevermind...>
The code you have there looks good to me... You're enabling the appropriate client states and setting all the array pointers correctly?
The code you have there looks good to me... You're enabling the appropriate client states and setting all the array pointers correctly?
Code:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(VERTEX_SIZE, GL_FLOAT, 0, MyVertexArray);
if (TheQuadCount > 0)
glDrawElements(GL_QUADS, TheQuadCount * 4, GL_UNSIGNED_INT, MyQuadIndexList);
glDisable(GL_VERTEX_ARRAY);
kberg Wrote:<edit: oops! nevermind...>
Wow, I just saw your original post, and it was correct! I don't know why you edited your post

After changing that, I got a screen of my terrain, followed by a sigsev error, so I will report back if I got it to work fully. Thanks!
Heh, sorry about that... its easy to get confused with all the various pointers to arrays
Glad that worked though!

Glad that worked though!
After reprogramming EVERYTHING that had to do with the display list, I have concluded that my data is 100% correct, because this works 100%
But when I use the vertex arrays, everything gets screwed up, there is always a general form, but each individual triangle is always screwed up. Here is the relevant Open GL Code. Please help, I have been stuck at this point for 6 days now, and I have spent hours re-reading the code and re-writing the code, with no success
. I even tried glDrawArray and making a triangle array instead!
PHP Code:
for (i=0; i < numberOfTextures; i++)
{
if (theQuadCount[i] != 0) {
glBindTexture(GL_TEXTURE_2D, gv->texture[i]);
glBegin( GL_QUADS );
for (j = 0; j < theQuadCount[i]; j++)
{
glTexCoord2f(0.0f,0.0f);
glVertex3f(theVertex[theQuad[ i ][ j ][ 0 ]],theVertex[1+theQuad[ i ][ j ][ 0 ]],theVertex[2+theQuad[ i ][ j ][ 0 ]]);
glTexCoord2f(1.0f,0.0f);
glVertex3f(theVertex[theQuad[ i ][ j ][ 1 ]],theVertex[1+theQuad[ i ][ j ][ 1 ]],theVertex[2+theQuad[ i ][ j ][ 1 ]]);
glTexCoord2f(1.0f,1.0f);
glVertex3f(theVertex[theQuad[ i ][ j ][ 2 ]],theVertex[1+theQuad[ i ][ j ][ 2 ]],theVertex[2+theQuad[ i ][ j ][ 2 ]]);
glTexCoord2f(0.0f,1.0f);
glVertex3f(theVertex[theQuad[ i ][ j ][ 3 ]],theVertex[1+theQuad[ i ][ j ][ 3 ]],theVertex[2+theQuad[ i ][ j ][ 3 ]]);
}
glEnd();
}
}
But when I use the vertex arrays, everything gets screwed up, there is always a general form, but each individual triangle is always screwed up. Here is the relevant Open GL Code. Please help, I have been stuck at this point for 6 days now, and I have spent hours re-reading the code and re-writing the code, with no success

PHP Code:
// Setup
GLint *vertexPointer;
GLfloat *theVertex;
GLint *uvPointer;
GLfloat *theUV;
//QUADUS *theQuad;
unsigned int theQuad[numberOfTextures][50000][4];
unsigned short theQuads[numberOfTextures][50000][4];
int vertexCount;
int theQuadCount[numberOfTextures];
vertexPointer = (GLint*)malloc(90000 * sizeof(GLint));
theVertex = (GLfloat*)malloc(90000 * sizeof(GLfloat));
uvPointer = (GLint*)malloc(60000 * sizeof(GLint));
theUV = (GLfloat*)malloc(60000 * sizeof(GLfloat));
// Drawing code
realloc(theVertex,vertexCount*sizeof(GLfloat));
realloc(theUV,vertexCount/3*2*sizeof(GLfloat));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, theVertex);
glTexCoordPointer(2, GL_FLOAT, 0, theUV);
glLockArraysEXT(0, vertexCount/3);
for (i=0; i < numberOfTextures; i++)
{
if (theQuadCount[i] != 0) {
glBindTexture(GL_TEXTURE_2D, gv->texture[i]);
glDrawElements(GL_QUADS, theQuadCount[i]*4 - 4, GL_UNSIGNED_INT, theQuad[i]);
}
}
glUnlockArraysEXT();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
just checking:
you're setting your stride correctly right?
also
I'm not sure why you put -4 next to the count.
Code:
long stride = sizeof(GLfloat)*3;
glVertexPointer(3, GL_FLOAT, stride, &theVertex[0]);
also
Code:
glDrawElements(GL_QUADS, theQuadCount[i]*4, GL_UNSIGNED_INT, theQuad[i]);
---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Unrelated comment:
When you get it working, please post benchmarks between immediate and VAs for your hardware.
I found that glDrawElements is SLOWER than immediate mode on the Radeon 7000.
When you get it working, please post benchmarks between immediate and VAs for your hardware.
I found that glDrawElements is SLOWER than immediate mode on the Radeon 7000.
I was told that a stride of 0 is what you want.
The -4 is because the counter gets ++ed after I assign the current ones, so it should always be 1 to high
Thats odd... I have both set up (immediate working), so when I get them both I will tell you. I am switching to the immediate code now so I can get some new work done.
The -4 is because the counter gets ++ed after I assign the current ones, so it should always be 1 to high
arekkusu Wrote:Unrelated comment:
When you get it working, please post benchmarks between immediate and VAs for your hardware.
I found that glDrawElements is SLOWER than immediate mode on the Radeon 7000.
Thats odd... I have both set up (immediate working), so when I get them both I will tell you. I am switching to the immediate code now so I can get some new work done.
Does disabling the texture array help at all?
Also, remember that int this line:
realloc(theVertex,vertexCount*sizeof(GLfloat));
either your vertexCount is really 3 x the size of the number of vertices, or you're missing a factor of 3 in there and you are buffer overrunning quite badly; which could be the reason why immediate mode is not crashing while glDrawElements is.
So maybe you need to do this?
realloc(theVertex, vertexCount * 3 * sizeof(GLfloat));
Also, remember that int this line:
realloc(theVertex,vertexCount*sizeof(GLfloat));
either your vertexCount is really 3 x the size of the number of vertices, or you're missing a factor of 3 in there and you are buffer overrunning quite badly; which could be the reason why immediate mode is not crashing while glDrawElements is.
So maybe you need to do this?
realloc(theVertex, vertexCount * 3 * sizeof(GLfloat));
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
glDrawElements and Face indices | Ashford | 8 | 19,711 |
Nov 11, 2009 03:03 PM Last Post: Ashford |
|
Agh! glDrawElements kills my artwork | ferum | 2 | 5,554 |
Nov 23, 2006 09:05 AM Last Post: ferum |
|
glDrawElements question | Falcor | 20 | 18,971 |
Feb 2, 2006 02:50 PM Last Post: akb825 |
|
glDrawElements() some questions .. | NYGhost | 2 | 4,062 |
Nov 15, 2004 06:15 PM Last Post: NYGhost |
|
glDrawElements vs. glDrawArrays - The numbers are in! | inio | 22 | 30,766 |
Jul 19, 2003 10:00 AM Last Post: Josh |