For a game I am making each block is a 6 faced object. Its texture is a png image that is 16*96 pixels in size. Each face of the block has got its own vbo; set up in the following manner:
Vector3f[] right={
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(0.5f,0.5f,0.5f),
new Vector3f(0.5f,-0.5f,0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),};
int rightVerHandels = glGenBuffers(),
rightNormHandels = glGenBuffers(),
rightTexHandels = glGenBuffers();
FloatBuffer rightVec = reserveData(bottom.length*3);
FloatBuffer rightNorm= reserveData(bottom.length*3);
FloatBuffer rightTex = reserveData(8);
rightNorm.put(asFloats(new Vector3f(1,0,0)));
rightNorm.put(asFloats(new Vector3f(1,0,0)));
rightNorm.put(asFloats(new Vector3f(1,0,0)));
rightNorm.put(asFloats(new Vector3f(1,0,0)));
rightTex.put(new float[]{0,(float)(5.0/6.0)});
rightTex.put(new float[]{1,(float)(5.0/6.0)});
rightTex.put(new float[]{1,(float)(6.0/6.0)});
rightTex.put(new float[]{0,(float)(6.0/6.0)});
for(Vector3f v: right){
rightVec.put(asFloats(v));
}
rightVec.flip();
rightNorm.flip();
rightTex.flip();
glBindBuffer(GL_ARRAY_BUFFER, rightVerHandels);
glBufferData(GL_ARRAY_BUFFER, rightVec, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, rightNormHandels);
glBufferData(GL_ARRAY_BUFFER, rightNorm, GL_STATIC_DRAW);
glNormalPointer(GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, rightTexHandels);
glBufferData(GL_ARRAY_BUFFER,rightTex,GL_STATIC_DRAW);
glTexCoordPointer(2,GL_FLOAT,0,0);
They are then saved to a 2d array (int[][]) in the format of vbos = new int[][]{{topVerHandels,topNormHandels,topTexHandels},
{bottomVerHandels,bottomNormHandels,bottomTexHandels},
{nearVerHandels,nearNormHandels,nearTexHandels},
{farVerHandels,farNormHandels,farTexHandels},
{leftVerHandels,leftNormHandels,leftTexHandels},
{rightVerHandels,rightNormHandels,rightTexHandels}};
These are then called like so:
glBindBuffer(GL_ARRAY_BUFFER, vbos[side][0]);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vbos[side][1]);
glNormalPointer(GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER,vbos[side][2]);
glTexCoordPointer(2,GL_FLOAT,0,0);
But for some reason, the texture coord pointer is not taking effect. Each blocks face is just a squished version of the entire texture. What have I done wrong?
I'm having the exact same trouble. I thought it was my blender model, i re applied the material and texture to get the right uv coords, and it just made it worse. Anyone have any clue?
I just fixed mine. I don't know why yours isn't working though. My code is similar as far as loading the buffers and drawing with VBOs. But i'm using a model i made in blender
I suppose you have called glEnableClientState(GL_NORMAL_ARRAY);
?
Yes I have enabled all of the states