PDA

View Full Version : Texture Mapping Triangle Strip VBO?



WelshWonder
02-23-2011, 04:27 PM
Hi everyone,

I'm currently working on a game and am having problems working out how to texture a triangle strip.

I have a cube created using a VBO and triangle strips. I was wondering how I would go about texturing this. Would you create a new buffer object, create an array/vector of texture points (which are loaded into the buffer) and then somehow apply those points to the texture to the cube?

Thanks,

Gaz

McLeary
02-23-2011, 04:40 PM
I think you gonna need to create an array of texture coords (one for each vertex). But I can't figure out a way to automate this for any geometry you wanna texture. If the cube was the only object I have, I'll consider the use of a cube map.

WelshWonder
02-24-2011, 06:36 AM
I've created an array of texture coords but I can't work out how to apply this and texture. The texture I'm loading is a .tga file and I think its loaded file as my load file routine doesn't come up with any errors.

I create the buffer:


//Texture Setup
glGenTextures(1,&texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture.getWidth(), texture.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, texture.getImageData());


Then in my render class I try rendering the texture:



glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_TEXTURE_2D, texID);
glTexCoordPointer(2,GL_FLOAT,0,cube_text);
//Draw the triangles, we pass in the number of indices, the data type of the index array
// (GL_UNSIGNED_INT) and then the pointer to the start of the array
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 24);
//Finally disable the vertex array
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);


The cube renders fine as a 3D cube in red. Just the texture isn't applied.

_ShaderRookie_
02-24-2011, 08:38 PM
Textures are bound with glBindTexture, not glBindBuffer :).

McLeary
02-25-2011, 08:38 AM
Guess ShaderRookie found the problem. =)

WelshWonder
02-25-2011, 11:03 AM
Yeh thanks guys that and a few other things I'd done wrong!