Jump to content

  • Log In with Google      Sign In   
  • Create Account

VBOs Crash When Using Textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 BlueSpud   Members   -  Reputation: 447

Like
0Likes
Like

Posted 10 August 2014 - 08:21 AM

Hey,

So I've tried to implement VBOs to see if they would be beneficial over display lists. I wanted to start out simple, so drawing a textured quad on the screen. Drawing a non-textured quad is fine. However as soon I try to put in texture coordinates, crash. I have absolutely no idea whats wrong. When I bind 0 to texture and shader, everything is fine, but the quad is white, as you would expect. The exact same code works just fine with display lists. Here is my code:

//create a vertex buffer object for the particles to use
        glGenBuffers(1, &VBO);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        
        //create the data, this is really sloppy
        float QuadVertextData[] = {0,0,0,1,0,0,1,1,0,0,1,0};
        float QuadTextureData[] = {0,1,1,1,1,0,0,0};
        
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*3, &QuadVertextData, GL_STATIC_DRAW);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        
        //generate another buffer for the texcoords
        glGenBuffers(1, &VBOT);
        glBindBuffer(GL_ARRAY_BUFFER, VBOT);
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*2, &QuadTextureData, GL_STATIC_DRAW);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);

render:

        glUseProgram(shader);
        
        glBindTexture(GL_TEXTURE_2D, texture);
        
        for (int i = 0; i < Quads.size(); i++)
        {
            Quads[i]->render(shader, cam);
        }

//the quad render
glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexPointer(3, GL_FLOAT, 0, 0);
        
        glBindBuffer(GL_ARRAY_BUFFER, VBOT);
        glTexCoordPointer(2, GL_FLOAT, 0, 0);
        
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    
        glDrawArrays(GL_QUADS, 0, 4);
        
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

 I really have no idea whats wrong with this. From everything I've looked at, this should absolutely fine. Id love some help or advice, anything. Thanks.



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 10 August 2014 - 05:29 PM

Your glBufferData calls are wrong.  Instead of "&QuadVertexData" you should use "QuadVertexData" (i.e without the "&") or "&QuadVertexData[0]".  Likewise for QuadTextureData.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 BlueSpud   Members   -  Reputation: 447

Like
0Likes
Like

Posted 10 August 2014 - 06:52 PM

Your glBufferData calls are wrong.  Instead of "&QuadVertexData" you should use "QuadVertexData" (i.e without the "&") or "&QuadVertexData[0]".  Likewise for QuadTextureData.

While you're right, it doesn't make a difference and still crashes.



#4 mgubisch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 11 August 2014 - 08:46 AM

The postet code looks fine so far (without testing it)

 

Can you post the part where you create the texture?

Also the exception which is thrown (i assume there is one if you mention a crash) would be interesting, together with the information where your code exactly crashes



#5 BlueSpud   Members   -  Reputation: 447

Like
0Likes
Like

Posted 11 August 2014 - 09:24 AM

The postet code looks fine so far (without testing it)

 

Can you post the part where you create the texture?

Also the exception which is thrown (i assume there is one if you mention a crash) would be interesting, together with the information where your code exactly crashes

I can't imagine that the texture is the problem because both display lists and immediate mode have no problem using it. It throws EXC_BAD_ACESS right on glDrawArrays. If I bind texture 0 and shader 0, everything works swimmingly, which is like the weirdest thing I've ever heard.



#6 Sponji   Members   -  Reputation: 1355

Like
0Likes
Like

Posted 11 August 2014 - 01:03 PM

It's hard to guess this kind of stuff, because the problem could be anywhere. Can you make a simple example program which causes that crash?


Derp

#7 Yaoyi   Members   -  Reputation: 108

Like
0Likes
Like

Posted 15 August 2014 - 07:22 AM

and try "QuadTextureData" instead of "&QuadTextureData" in glBufferData(...).


Edited by Yaoyi, 15 August 2014 - 07:24 AM.


#8 JohnnyCode   Members   -  Reputation: 294

Like
0Likes
Like

Posted 17 August 2014 - 02:40 PM

 

and shader 0

changing a shader to a bound VBO state can (or not) mean a different vertex buffer layout being needed by the shader program. Bad access can mean your vertex funtion input and bound VBO layout does not match.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS