VBO's and glDrawElements [Solved]

Started by MWulf, November 26, 2010, 13:41:58

Previous topic - Next topic

MWulf

I am having trouble getting index buffers going. I've searched through looking at all different examples, but can't seem to get anything going.

Setting up the buffers
       buffers = BufferUtils.createIntBuffer(NUM_BUFFERS);
        glGenBuffers(buffers);
        buffers.get(bufferHandle);
        
        float vertexInfo[] = {        // Defines vertices for triangle based pyramid
        		0.0f, 1.0f, 0.0f,
        		-1.0f, -1.0f, 1.0f,
        		1.0f, -1.0f, 1.0f,
        		0.0f, -1.0f, -1.0f
        };        int indexInfo[] = {		// Defines the index to make it
        		0, 2, 1,
        		0, 3, 2,
        		0, 1, 3,
        		1, 2, 3
        };
    	// Convert to passable types
        vertexBuffer = addBufferData(bufferHandle[VERTEX_BUFFER], vertexInfo);
        indexBuffer = addBufferData(bufferHandle[INDEX_BUFFER], indexInfo);
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, 0);


How I try to feed the buffers, with an IntBuffer version for the index array done the same...
   private FloatBuffer addBufferData(int bufferHandle, float[] data) {
        FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
        buffer.put(data);
        buffer.rewind();
        glBindBuffer(GL_ARRAY_BUFFER, bufferHandle);
        glBufferData(GL_ARRAY_BUFFER, data.length, GL_STATIC_DRAW);
        
        return buffer;
    }


The render part
   	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    	
    	glLoadIdentity();
        glTranslatef(0.0f, 0.0f, -6.0f);

        glDrawElements(GL_TRIANGLES, 12, GL_INT, 0);


I've tried everything I can think of. I assume I am just plain getting the idea wrong?

Edit: There is a mistake in that I had data.length in my glBufferData call instead of the buffer holding the data and that the call to DrawElements should be GL_UNISIGNED_INT not GL_INT. Thanks!

Matthias

your addBufferData() method does not upload any data.

ryanm

Yeah, call glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW) instead of         glBufferData(GL_ARRAY_BUFFER, data.length, GL_STATIC_DRAW).

Incidentally, what does glBufferData( target, dataSize, usage ) actually do?

Matthias

It allocates an uninitialized BO which can then be mapped to client memory using glMapBuffer or glMapBufferRange