Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-12-2009, 09:01 PM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 190
jeonghyunhan is on a distinguished road
Default 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.

Any help would be of great help.
Thanks.
__________________
Blockle:http://www.youtube.com/watch?v=vxEKDkpAfRU
jeonghyunhan is offline   Reply With Quote
Old 07-12-2009, 10:10 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by jeonghyunhan View Post
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.

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:

GLBenchmark Result Details of unknown

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.
__________________

Free Games!

Last edited by smasher; 07-12-2009 at 10:16 PM.
smasher is offline   Reply With Quote
Old 07-12-2009, 10:15 PM   #3 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 190
jeonghyunhan is on a distinguished road
Default

I see...
Do you by any chance have a sample code or can you point me in the right direction?
__________________
Blockle:http://www.youtube.com/watch?v=vxEKDkpAfRU
jeonghyunhan is offline   Reply With Quote
Old 07-13-2009, 02:28 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by jeonghyunhan View Post
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 07-13-2009, 04:48 PM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 190
jeonghyunhan is on a distinguished road
Default

Makes sense!
Thanks once again.
__________________
Blockle:http://www.youtube.com/watch?v=vxEKDkpAfRU
jeonghyunhan is offline   Reply With Quote
Old 02-19-2010, 02:21 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 84
sagimann is on a distinguished road
Default help on the same matter...

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

I'd appreciate the assistance..
tnx
sagimann is offline   Reply With Quote
Old 02-23-2010, 01:40 PM   #7 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

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.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 404
7 members and 397 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0