Texture mapping with one spritesheet onto one object with one draw call?
Hi!
I'm in need of a little help.
I cannot seem to find a way to texture map different images to a single 3D cube from one sprite sheet without more than one glDrawArrays call.
I'm trying to optimize my code by using just one draw call and this is where I am stuck.
I can get this working fine with 6 draw calls for each side of the cube but am unable to do this with one call.
I cannot seem to find a way to texture map different images to a single 3D cube from one sprite sheet without more than one glDrawArrays call.
I'm trying to optimize my code by using just one draw call and this is where I am stuck.
I can get this working fine with 6 draw calls for each side of the cube but am unable to do this with one call.
Any help would be of great help.
Thanks.
I haven't tried this, so I defer to anyone with more experience. However, this page lists the value of GL_MAX_TEXTURE_UNITS as "2" on the iPhone 3G:
Two texture units is not enough to paint 6 different faces on your cube with multitexturing, so you'll have to combine the 6 images into a single texture if you want to draw it in one call.
EDIT: I re-read your headline, are you saying you already have a single image (single texture) with all 6 faces in it, and you want to use that? If you set the texture coordinates for each face you will be able to draw it in one call.
I see...
Do you by any chance have a sample code or can you point me in the right direction?
Sample code is tough because your OpenGL setup may be different than mine. This should help, though. I'll assume that you have an array of vertices that draws the cube in one drawArrays or drawElements call, and you have all 6 face images in one texture, like so:
[A][b]
[C][D]
[E][F]
The textures coordinates for part "A" will be (0,0) , (1.0/2, 0) , (0,1.0/3) , (1.0/2, 1.0/3) - that's the coordinates for the NW, NE, SW, SE corners. I may have the middle set reversed; it should match the order of the vertices in your cube.
If you draw this out on a sheet of paper, you should see how to calculate the texture coordinates for each face of your cube. Put them in a big array and use that as your array of texture coordinates.
Hi,
I have have a similar issue, I can't seem to get the cube texture coordinates correct using the suggestion above. Can you show the overall texture you used and the tex coords?
Each vertex is shared by 3 faces, so how is it possible to arrange 6 faces on a 2x3 block??? When constructing a cube from a piece of paper, the "texture" of the cube cannot be a square, it needs to be something like cross,etc, for example:
Code:
|T|
|L|F|R|
|B|
|K|
where t=top, l/r=left/right, f=front, b=bottom, k=back
In this case your texture does not need the shape of a cross, because you do not need to share vertices between the faces of the cube. You're simply drawing six squares (meaning 12 triangles, or 36 vertices) oriented in a particular way, not a cube.
Trying to do a triangle strip with some degenerate triangles would be more efficient, but for now I would just use a triangle list until you understand how it works.