[SOLVED]Texture with VBOs and Slick library

Is it possible to use Textures from the Slick2D library in conjunction with VBOs from GL15? I’ve got everything working, the image is loaded etc. I’m just not quite sure how to bind the image to openGL.

I’m currently using only 1 float buffer with position vertices, colors, and texture coordinates.

My FloatBuffer is as follows:

FloatBuffer buffer = BufferHelper.reserveData(32);
		buffer.put(new float[]{
			//position vertices
			x - width, y - height, 0,
			x + width, y - height, 0,
			x + width, y + height, 0,
			x - width, y + height, 0,
			//color vertices
			1, 1, 1,
			1, 1, 1,
			1, 1, 1,
			1, 1, 1,
			//texture vertices
			0, 0,
			1, 0,
			1, 1,
			0, 1
		});

My drawing method is as follows:

public void draw() {
		texture.bind();
		glBindBuffer(GL_ARRAY_BUFFER, vboHandle);
        glVertexPointer(3, GL_FLOAT, 0, 0L);
        glColorPointer(3, GL_FLOAT, 0, 48L);
        glTexCoordPointer(2, GL_FLOAT, 0, 96L);
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glDrawArrays(GL_QUADS, 0, 4);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

Is there a client state that needs to be enabled?
Am I binding the texture correctly?
Should I be using GL_TEXTURE_2D instead of slick?

Any input would be appreciated, even pointing out bad coding practices! (please do!)

P.S. - if anybody could explain to me why 48L is the correct offset for the colors, that would be great! :slight_smile:

Edit: Sorry, guess I should have brushed up on basic openGL texturing first. Fixed it by enabling GL_TEXTURE_2D and GL_BLEND. (using a .png)

48L is correct because you have 12 floats of vertices. Each float is made up of 4 bytes. 12*4=48.

I figured it had to do with something like that, I just couldn’t get a solid answer out of google as to how much memory a floating point number actually takes up.

Thanks for the reply! :slight_smile:

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

I found that client state prior to creating this post and when I tried including it with the code supplied in the OP, it crashed the IDE. Ive never experienced that type of crash before and am not sure how to debug it. I can post the crash log when I get home if that will help?