LWJGL Forum

Programming => OpenGL => Topic started by: poo2thegeek on January 03, 2014, 12:10:48

Title: VBOs not working for no reason I can see
Post by: poo2thegeek on January 03, 2014, 12:10:48
Quite simple, I'm trying to draw some stuff with a vbo. Here is the code that creates the vbos:
sides_[ABOVE][0] = glGenBuffers();
sides_[ABOVE][1] = glGenBuffers();

float[] top_ = {-r,r,r,    r,r,r,     r,r,-r,    -r,r,-r};
float[] toptex_ = {0,0,    64*pix,0,    64*pix,1,    0,1};

FloatBuffer top_buff = BufferTools.asFlippedFloatBuffer(top_);
FloatBuffer toptext_buff = BufferTools.asFlippedFloatBuffer(toptex_);
System.out.println(sides_[0][1]);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER,sides_[0][0]);
glBufferData(GL_ARRAY_BUFFER,top_buff,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);

glBindBuffer(GL_ARRAY_BUFFER,sides_[ABOVE][1]);
glBufferData(GL_ARRAY_BUFFER,toptext_buff,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);


The 'BufferTools.asFlippedFloatBuffer(..);' leads to this method:
public static FloatBuffer asFlippedFloatBuffer(float... values) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(values.length);
        buffer.put(values);
        buffer.flip();
        return buffer;
    }


All of this should work as far as I can see.
I then draw the vbos at a later date in this method:
glBindBuffer(GL_ARRAY_BUFFER,sides_[0][0]);
glVertexPointer(3,GL_FLOAT,0,0);
glBindBuffer(GL_ARRAY_BUFFER,sides_[0][1]);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_QUADS,0,3);


This should work, but for some reason it doesn't. Any help is useful!
Thanks in advance.
Title: Re: VBOs not working for no reason I can see
Post by: quew8 on January 03, 2014, 14:41:20
Well the final call you make is glDrawArrays(GL_QUADS, 0, 3); When I was in school (and that is right now) there were 4 vertices in a quad.

The thing with VBOs is that there are so many stupid mistakes to make, that when you make one you always manage to consistently miss it.
Title: Re: VBOs not working for no reason I can see
Post by: poo2thegeek on January 03, 2014, 16:55:00
Damn... I always thought that the final parameter was similar to that used in glVertexPointer, where the number is the amount of floats for each bit.
Thanks very much!!!!
Title: Re: VBOs not working for no reason I can see
Post by: quew8 on January 03, 2014, 16:58:27
Glad to help. And as it turns out I actually taught you something new. Great.