having problems with texture coordinate buffer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

having problems with texture coordinate buffer

Kalisme
Hello,

I started using jogl yesterday and decided to convert over a custom model format I wrote for an Android game. The actual mesh loads and displays fine, but the texture coordinates just don't seem to work.

I know that the texture coordinates are loaded into the floatbuffer because I checked them by looping through its capacity and using ".get(i)" to print out its contents, but I'm concerned something might be going wrong when I try to bind the data because I read on a forum that if you bind a texture coordinate buffer that is too big, it can cause problems (I hope this is not true, or that there is a work around).

This is the code I use to bind the texture coordinates:

        int[] buffer = new int[1];
        gl2.glGenBuffers(1, buffer, 0);
        textureBufferIndex = buffer[0];
        gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, textureBufferIndex);
        gl2.glBufferData(GL2.GL_ARRAY_BUFFER, _texBuffer.capacity()*4, _texBuffer, GL2.GL_STATIC_DRAW);
        error = gl2.glGetError();
        if(error != gl2.GL_NO_ERROR)
        {
        }

And the code I use to draw the model is:

                gl2.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
                gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, textureBufferIndex);
                gl2.glTexCoordPointer(2, GL2.GL_FLOAT, 0, 0);

                gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
                gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferIndex);
                gl2.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
                               
                gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferIndex);

                gl2.glDrawElements(GL2.GL_TRIANGLES, getIndexCount(), GL2.GL_UNSIGNED_SHORT, 0);
                       
                gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0);
                gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
                               
                gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
                gl2.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
                               
No errors appear and the model renders fine, but the texturing seems all wrong, like the coordinates all sit really close to <0,0> . I'm hoping I've just made a really obvious mistake. My model's texture coordinate floatbuffer capacity is 1034, so there's 517 verticies in the model. If that is too much using this method, is there a work around?

Thanks for reading and any help would be great.
Reply | Threaded
Open this post in threaded view
|

Re: having problems with texture coordinate buffer

Kalisme
Oh, I feel really silly. It turns out I didn't set the texture to repeat and the format that I wrote for my android game flips the Y axis for the texture coordinates.

Sorry about that, I was researching VBO's for JOGL for ages and it turns out I just forgot to set up the texture correctly.