interleaved VBO and textures

Started by thalador, February 23, 2007, 14:26:10

Previous topic - Next topic

thalador

Hi there,

currently I want to render my geometry using VBOs. It already works if I put all the vertex, color and texture information in different buffers. But I don't get it working in interleaved mode. Please have a look at my rendering code, can you see what I'm doing wrong?
GL11.glEnable(GL11.GL_TEXTURE_2D);
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0));
                //GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
                //GL13.glActiveTexture(GL13.GL_TEXTURE0);
                data.clear();
                int j = 0;
                for(int i = 0; i < used.size(); i++){
                    Particle p = (Particle) used.get(i);
                    //Vertices first, then color, then texture
                    j = 4 * (3 + 4 + 2) * i;
                    dataArray[j] = p.pos[0] - p.size;
                    dataArray[j+1] = p.pos[1] - p.size;
                    dataArray[j+2] = p.pos[2];
                    dataArray[j+3] = p.col[0];
                    dataArray[j+4] = p.col[1];
                    dataArray[j+5] = p.col[2];
                    dataArray[j+6] = p.col[3];
                    dataArray[j+7] = 0.0f;
                    dataArray[j+8] = 0.0f;
                    
                    dataArray[j+9] = p.pos[0] + p.size;
                    dataArray[j+10] = p.pos[1] - p.size;
                    dataArray[j+11] = p.pos[2];
                    dataArray[j+12] = p.col[0];
                    dataArray[j+13] = p.col[1];
                    dataArray[j+14] = p.col[2];
                    dataArray[j+15] = p.col[3];
                    dataArray[j+16] = 1.0f;
                    dataArray[j+18] = 0.0f;
                    
                    dataArray[j+19] = p.pos[0] + p.size;
                    dataArray[j+20] = p.pos[1] + p.size;
                    dataArray[j+21] = p.pos[2];
                    dataArray[j+22] = p.col[0];
                    dataArray[j+23] = p.col[1];
                    dataArray[j+24] = p.col[2];
                    dataArray[j+25] = p.col[3];
                    dataArray[j+26] = 1.0f;
                    dataArray[j+27] = 1.0f;
                    
                    dataArray[j+28] = p.pos[0] - p.size;
                    dataArray[j+29] = p.pos[1] + p.size;
                    dataArray[j+30] = p.pos[2];
                    dataArray[j+31] = p.col[0];
                    dataArray[j+32] = p.col[1];
                    dataArray[j+33] = p.col[2];
                    dataArray[j+34] = p.col[3];
                    dataArray[j+35] = 0.0f;
                    dataArray[j+36] = 1.0f;
                }
                data.put(dataArray, 0, used.size() * 4 * (3 + 4 + 2));
                data.flip();
                //bufferData(dataBufferID, data);
                
                ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, dataBufferID);
                ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, data, ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
                
                int stride = (3 + 4 + 2) * 4; // 3 for vertex, 3 for normal, 4 for colour and 2 for texture coordinates. * 4 for bytes
                
                // vertices
                GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
                int offset = 0 * 4; // vertices go first, so no offset
                GL11.glVertexPointer(3, GL11.GL_FLOAT, stride, offset);
                
                // normals
                //GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
                //offset = 3 * 4; // 
                //GL11.glNormalPointer(GL11.GL_FLOAT, stride, offset);

                // colours
                GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
                offset = 3 * 4; // vertices take 3 * 4Bytes, so 12 is the offset for the color
                GL11.glColorPointer(4, GL11.GL_FLOAT, stride, offset);
                
                // texture coordinates
                GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
                offset = (3 + 4) * 4; //color and vertices need 7 floats a 4 bytes
                GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, offset);
                
                ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexBufferID);
                ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexes, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
                GL12.glDrawRangeElements(GL11.GL_QUADS, 0, used.size()*4, used.size()*4, GL11.GL_UNSIGNED_INT, 0);
                GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
                GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
                GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
                GL11.glDisable(GL11.GL_TEXTURE_2D);


The texture is created correctly and tested. It all works in immediate mode and with more than one VBO..

EDIT: This is what it looks like:

Fool Running

I don't see anything immediately wrong... What happens if you just have one particle? It looks almost like your indexes are wrong (possibly need something other than GL_UNSIGNED_INT).
Also, the values for glDrawRangeElements() look wrong (3rd and 4th params), but I don't think its causing the problem.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D