glDrawElements question

Member
Posts: 509
Joined: 2002.05
Post: #1
if I have this variable

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=0numberOfTexturesi++)
    {
        if (
theQuadCount[i] != 0) {
            
glBindTexture(GL_TEXTURE_2Dgv->texture[i]);
            
glDrawElements(GL_QUADStheQuadCount[i]*4GL_UNSIGNED_SHORTquads[i]);
        }
    } 

I checked the data in the quad array and vertex array, and it is good, so I think this is my problem.
Quote this message in a reply
kberg
Unregistered
 
Post: #2
<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?

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);
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #3
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 Rasp

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!
Quote this message in a reply
kberg
Unregistered
 
Post: #4
Heh, sorry about that... its easy to get confused with all the various pointers to arrays Rasp

Glad that worked though!
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #5
After reprogramming EVERYTHING that had to do with the display list, I have concluded that my data is 100% correct, because this works 100%

PHP Code:
for (i=0numberOfTexturesi++)
    {
        if (
theQuadCount[i] != 0) {
            
glBindTexture(GL_TEXTURE_2Dgv->texture[i]);
            
glBeginGL_QUADS ); 
            for (
0theQuadCount[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 Sad. I even tried glDrawArray and making a triangle array instead!

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(3GL_FLOAT0theVertex);
    
glTexCoordPointer(2GL_FLOAT0theUV);
    
    
glLockArraysEXT(0vertexCount/3);
    
    for (
i=0numberOfTexturesi++)
    {
        if (
theQuadCount[i] != 0) {
            
glBindTexture(GL_TEXTURE_2Dgv->texture[i]);
            
glDrawElements(GL_QUADStheQuadCount[i]*4GL_UNSIGNED_INTtheQuad[i]);
        }
    }
    
    
glUnlockArraysEXT();
    
glDisableClientState(GL_VERTEX_ARRAY);
    
glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #6
just checking:
Code:
long stride = sizeof(GLfloat)*3;
glVertexPointer(3, GL_FLOAT, stride, &theVertex[0]);
you're setting your stride correctly right?

also
Code:
glDrawElements(GL_QUADS, theQuadCount[i]*4, GL_UNSIGNED_INT, theQuad[i]);
I'm not sure why you put -4 next to the count.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
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.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #8
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


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.
Quote this message in a reply
kberg
Unregistered
 
Post: #9
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));
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #10
the vertex-count incremented by 3 each time, sorry Sad.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glDrawElements and Face indices Ashford 8 12,388 Nov 11, 2009 03:03 PM
Last Post: Ashford
  Agh! glDrawElements kills my artwork ferum 2 3,519 Nov 23, 2006 09:05 AM
Last Post: ferum
  glDrawElements question Falcor 20 11,666 Feb 2, 2006 02:50 PM
Last Post: akb825
  glDrawElements() some questions .. NYGhost 2 2,844 Nov 15, 2004 06:15 PM
Last Post: NYGhost
  glDrawElements vs. glDrawArrays - The numbers are in! inio 22 19,934 Jul 19, 2003 10:00 AM
Last Post: Josh