LWJGL Forum

Programming => OpenGL => Topic started by: beaucoralk on May 27, 2013, 19:25:08

Title: [SOLVED] VBO texturing don't work correctly LWJGL
Post by: beaucoralk on May 27, 2013, 19:25:08
I'm a young developer and I try to use VBO to render my 3d objects.
I've created this class :

   public class Object3DTexturedRendered {
   
   private TextureRendered texture;
   private int vboId = 0;
   private int vboiId = 0;
   private int vbotId = 0;
   private int verticesTexCoords[][];
   private int verticesIndex[];
   private FloatBuffer verticesBuffer;
   private FloatBuffer texturesBuffer;
   private IntBuffer indexBuffer;
   
   public Object3DTexturedRendered() {
       
   }
   
   public Object3DTexturedRendered(TextureRendered _texture) {
       texture = _texture;
   }
   
   public void renderVBO() {
       glEnable(GL_TEXTURE_2D);
       
       if (texture.getTexture() != null) {
           texture.getTexture().bind();
       }
       
       ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
       glVertexPointer(3, GL_FLOAT, 0, 0L);
       
       ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbotId);
       glTexCoordPointer(2, GL_FLOAT, 0, 0L);
       
       glEnableClientState(GL_VERTEX_ARRAY);
       glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, vboiId);
       glDrawRangeElements(GL_TRIANGLES, 0, (verticesIndex.length - 1), verticesIndex.length,
                                             GL_UNSIGNED_INT, 0L);
       glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       glDisableClientState(GL_VERTEX_ARRAY);
       
       ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);
       ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
       
       glDisable(GL_TEXTURE_2D);
   }
   
   public void initRenderVBO(FloatPointRendered[] listPointsRendered, int _verticesTexCoords[][], int _verticesIndex[]) {
       verticesTexCoords = _verticesTexCoords;
       verticesIndex = _verticesIndex;
       
       verticesBuffer = BufferUtils.createFloatBuffer(verticesTexCoords.length * 3);
       texturesBuffer = BufferUtils.createFloatBuffer(verticesTexCoords.length * 2);
       for (int[] _ipoint : verticesTexCoords) {
           FloatPointRendered _point = listPointsRendered[_ipoint[0]];
           float[] uv = texture.getXYtoFloat(_ipoint[1], _ipoint[2]);
           verticesBuffer.put(_point.positionToFloatArray());
           texturesBuffer.put(uv);
       }
       verticesBuffer.flip();
       texturesBuffer.flip();
       
       indexBuffer = BufferUtils.createIntBuffer(verticesIndex.length);
       indexBuffer.put(verticesIndex);
       indexBuffer.flip();
       
       if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
           IntBuffer vboID = BufferUtils.createIntBuffer(3);
           ARBVertexBufferObject.glGenBuffersARB(vboID);
           vboId = vboID.get(0);
           ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboId);
           ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticesBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
           
           vbotId = vboID.get(1);
           ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbotId);
           ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, texturesBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);

           vboiId = vboID.get(2);
           ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, vboiId);
           ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexBuffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
       }
   }


My object are all rendered correctly, but I've a problem with the texture.
My texture are strided. Look at this image... why my texture are like that, and how I can fixe this bugs.
(http://i.stack.imgur.com/wZbaI.png)

Thanks in advance for your help.
Title: Re: VBO texturing don't work correctly LWJGL
Post by: Fool Running on May 28, 2013, 17:02:30
It looks to me like a problem in the texture loading (maybe more bytes per pixel then you think?). Can you post your texture loading code?
Title: Re: VBO texturing don't work correctly LWJGL
Post by: beaucoralk on May 28, 2013, 19:30:53
If I use my texture not with VBO, my texture is correctly rendered !

And to load and bind texture I use a library Slick-Util (http://www.lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Introduction)
Title: Re: VBO texturing don't work correctly LWJGL
Post by: beaucoralk on May 29, 2013, 21:02:59
Resolved !

In fact, I cut not correctly my texture into my GL_TRIANGLES rendered !