PDA

View Full Version : Problem with multiple glTexCoordPointer() arrays



bmcclint
08-31-2001, 08:03 AM
I am seeing a strange problem with glTexCoordPointer() but can't seem to determine what is going on. I think I have some GL wrong but its acting like a compiler problem not addressing the arrays correctly. This is being built on a Linux system.

I have a cube texture mapped with a textute that spins, just to text mipmapping. The vertexes are in one array of 8 vertexes.

One versiopn that works correctly has the texture verts in a single array, one per vertex. This produces some interesting patterns but I know why. (one per vertex = not good). The indicies are in a single array, 24 long, to draw the object.

This all works well.

NOW...

Break up the texture verts into six arrays each with an s/t for each vertex.
Break up the INDICES into six arrays each with 4 values.

Then instead of one call to glTexCoordPointer & glDrawElements...

I call the each six times in sucession, (glTexCoordPointer & glDrawElements), to draw the model. The first panel texture is placed OK...All other panels have textures coordinates all messed up.

I'm sure the data is ok because if I expand to a loop and use (glBegin(),glTexCoord2f(),glVertex3i(),glEnd()) the model draws correctly.

Anyone seen this???


BTW...Vertex array is funky incase anyone catches it (int)(id,x,y,z)
----CODE SNIPPET FOR ARRAYS----
void Draw(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(Model.location.x, Model.location.y, -Model.location.z);
glRotated(Model.angle.z, 0.0, 0.0, 1.0);
glRotated(Model.angle.x, 1.0, 0.0, 0.0);
glRotated(Model.angle.y, 0.0, 1.0, 0.0);

glVertexPointer(3, GL_INT, 16, (GLvoid*)((int)g_cube_vertices + sizeof(int)));

/* Draw model using single call to arrays */
// glTexCoordPointer(2, GL_SHORT, 0, g_cube_texverts);
// glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, g_cube_indices);

/* Draw model using multiple calls to arrays */
glTexCoordPointer(2, GL_SHORT, 0, sidea_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sidea_indices);
glTexCoordPointer(2, GL_SHORT, 0, sideb_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sideb_indices);
glTexCoordPointer(2, GL_SHORT, 0, sidec_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sidec_indices);
glTexCoordPointer(2, GL_SHORT, 0, sided_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sided_indices);
glTexCoordPointer(2, GL_SHORT, 0, sidee_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sidee_indices);
glTexCoordPointer(2, GL_SHORT, 0, sidef_txverts);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, sidef_indices);

glFlush();
glutSwapBuffers();
}

bmcclint
08-31-2001, 12:59 PM
Followup...Could this have anything to do with locking the arrays?

yzubkov
09-15-2010, 12:27 PM
Same issue here, I am struggling with multiple glTexCoordPointer() arrays. Only the initial pointer seems to work. All subsequent calls produce (0,0) coordinate calls. Does anyone know how to fix this?
/************************************************** **
INITIALIZATION CODE:
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY );
int txtRef1=loadTexture(.....);
int txtRef2=loadTexture(.....);
IntBuffer verBuff=getIntBuffer(.......);
IntBuffer txtCoord1=getIntBuffer(......);
IntBuffer txtCoord2=getIntBuffer(.......);
PER-FRAME CODE:
gl.glVertexPointer(3, GL10.GL_FIXED, 0, verBuff);
gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, txtCoord1);
gl.glBindTexture(GL10.GL_TEXTURE_2D, txtRef1);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, txtCoord2);
gl.glBindTexture(GL10.GL_TEXTURE_2D, txtRef2);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
************************************************** ***/
Any help would be highly appreciated

yzubkov
09-15-2010, 12:59 PM
I found my problem. The code above works just fine. The problem was that IntBuffer txtCoord2=getIntBuffer(.......); was not defined correctly. The right way was:

int one=(int)(1.0f*65536);
int[] texture = {one,0, one,one, 0,0, 0,one,one,0, one,one, 0,0, 0,one};
ByteBuffer byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
IntBuffer txtCoord2 = byteBuf.asIntBuffer();
txtCoord2.put(data);
txtCoord2.position(0);