Jump to content
  • Advertisement
Sign in to follow this  
Ultimate Chicken

OpenGL Crash when attempting to wrap a VBO with a Display List

This topic is 3016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, before I start:
1. Yes, I know that display lists are deprecated, and will only be supported through manufacturer specific extensions in the future.

2. Yes, I know that some of you think this is completely unnecessary, and I agree to some extent, but this is school stuff, and I lost a small fraction of my grade because I couldn't do this, *YET OTHERS COULD*.

3. I use an object called "sdata", which contains:
- a VBO id "vertices" (already populated and working when I try to draw/construct the display list)
- an IBO id "indices" (already populated and working)
- a Display List id "vlist", which is where I want to put the result in.

As with the title, I'm trying to shove a VBO (with corresponding IBO) into a Display List. The following code works properly in my render step (AND does compile in my construction step):


//BEGIN RENDER CODE
//I need the following arrays:
glEnableClientState(GL_VERTEX_ARRAY);
//indices for the VBO, supplied as CORRECTION: an array of integer.
glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

int curr_indice_count = sdata.indice_count;
//I keep a count of my indices when I construct the geometry.
int curr_xtessel = sdata.tesselx;
//I'm drawing based on the number of stacks. I do keep slices around but my
//current implementation doesn't use that value to draw.
int index_offset = 0; //a buffer object starts from position 0, once bound.
int index_eachrow = (curr_xtessel +1) *2; //each row has this amount of vertices.

//bind my VBO and IBO.
glBindBuffer(GL_ARRAY_BUFFER, sdata.vertices);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,sdata.indices);

unsigned vertsize = sizeof(Vertex); //precalculated size of a Vertex struct.
unsigned elemsize = 3* sizeof(float); //precalculated size of each element of a vertex.

//set pointers. I should NOT need to set a pointer for my IBO, that's what
//Element_Array_Buffer does.
glVertexPointer(3, GL_FLOAT,
vertsize, 0);
glNormalPointer(GL_FLOAT,
vertsize,
(GLvoid*) elemsize);
glTexCoordPointer(2, GL_FLOAT,
vertsize,
(GLvoid*)(4 * elemsize));

unsigned usize = sizeof(unsigned); //precalculated size of unsigned.

//This is where I actually draw the geometry.
while (index_offset < curr_indice_count)
{
glDrawElements(GL_TRIANGLE_STRIP,
index_eachrow,
GL_UNSIGNED_INT,
((char*)0 + index_offset * usize));
index_offset += index_eachrow;
}

//unbind from VBO
glBindBuffer(GL_ARRAY_BUFFER,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);

//disable client states.
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//END RENDER CODE




However, the minute I try something like this in my construction step:


sdata.vlist = glGenLists(1);
glNewList(sdata.vlist, GL_COMPILE);

//BEGIN RENDER CODE
...
//END RENDER CODE

glEndList();




The application crashes with an access violation, on the VERY FIRST CALL to
glDrawElements().

This occurs no matter where I position my glGenList, glNewList and glEndList statements, or where I read the indices as a GL_UNSIGNED_INT or a GL_UNSIGNED_SHORT.

I have another Display List implementation in the program that uses non-VBO Vertex Arrays, and it works fine. So much so that currently I'm under the impression the Display List code is IGNORING my calls to glBindBuffer() and thinks I'm trying to use a Vertex Array.

I've already updated to the latest builds of GLEW, to no avail. My card is an Nvidia 9500GT, and the drivers are straight from the manufacturer (XFX) so there should be no issues with display list or basic openGL support.

I've tried looking at the implementations of my fellows and I can see nothing that I've missed (as far as I can tell). Is there anyone who has successfully pulled this stunt, who can point me in the right direction? I've been scratching my head over this for a few weeks now.

Thanks in advance.

Edit: Just a note that glGetError() at any point in this code returns 0 (absolutely nothing wrong).

[Edited by - Ultimate Chicken on July 18, 2010 3:04:27 AM]

Share this post


Link to post
Share on other sites
Advertisement
Can you draw the vertex arrays successfully without putting them in a display list?

It should be ignored in RGB color mode, but you enable the index color array but don't set it's pointer. The index color array is not for indexing vertices (that's what element buffer arrays are used for), but the glColorPointer equivalent for indexed color mode, as opposed to the RGB color mode. Even if it shoulnd't affect anything in this case, don't enable the index color array.

Share this post


Link to post
Share on other sites
Quote:

It should be ignored in RGB color mode, but you enable the index color array but don't set it's pointer. The index color array is not for indexing vertices (that's what element buffer arrays are used for), but the glColorPointer equivalent for indexed color mode, as opposed to the RGB color mode. Even if it shoulnd't affect anything in this case, don't enable the index color array.


Ok, that's one hell of a head slapping two weeks. I was under the impression that I needed GL_INDEX_ARRAY for the IBO - turns out that the call to glEnableClientState(GL_INDEX_ARRAY) was the problem all this time, because I misinterpreted its purpose. Silly noob mistake >.<

I don't have color attached to my Vertex struct (they're stored as separate Materials), so I didn't see the need to set a glColorPointer).

Yes, I am able to draw in Vertex Array mode with the same code I used for the Vertex Array part. Looks like I don't need it anymore, but I'll keep it for legacy systems support.

Thanks! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!