[android-developers] Re: Mapping Multiple textures to a cube in Android OpenGL ES

2010-06-27 Thread Robert Green
Forget about mipmapping for now - that's a different kind of
distortion.  I'm talking about taking an image that's 100x100 and
putting it into a space that's 150x100, then drawing it back out at
100x100.  The user will never know that it was stored at a different
aspect ratio because so long as you draw it how it should be, you're
good.

Here's a good exercise:

Create your texture in photoshop or your favorite image editor.  Make
the texture 1024x1024 and shove 6 different images onto it.  Now, drop
guidelines down to the edges of the images and switch your info to
percentages.  Write down all of the percentages that your guides are
at.  If you do 2 rows of 3, it will be 0, 50 and 100 for the y and 0,
33.3, 66.6, 100 for the x.  Those will then become your UVs.

Change your cube app to use those hardcoded UVs, eg:

// face 0 counterclockwise winding
0,0
0,.5f
.333f,.5f
.333f,0,
// face 1 ccw winding
...

Get that working with you manually entering all of the geometry and UV
data.  Once you figure out how to make that work, you can probably
come up with an automated way of doing what you want :)


On Jun 27, 3:48 pm, chaitanya  wrote:
> Thanks Robert, So in short you are stating that I use a texture atlas
> approach. The second approach is what I used right now, for every face
> of the cube construct that side and binding it to the texture which
> was really inefficient.
>   Well, you have said something about the distortion. I read at nehe's
> site that you can use mimaps to upload image of any size which will be
> scaled to the best aspect ratio and will minimize the distortion.
> Could I use that technique to create the texture atlas? Also, could
> you give me some pointers or articles which discuss the creation of a
> texture atlas since I'm fairly new at this.
>
> On Jun 26, 12:01 am, Robert Green  wrote:
>
>
>
> > No, that's not what cube maps are for.
>
> > You can only draw 1 texture at a time (unless multitexturing but
> > that's totally different and not what you want) so you have 2 options:
>
> > 1)  Combine all textures together into a single one and map the
> > coordinates to each side accordingly (will run much faster)
> > 2)  Draw side-at-a-time binding to the appropriate texture for each
> > side. (not usually the preferred method.)
>
> > A trick many of us use when doing something like... say you want to
> > have the user pick 6 photos from their SD card and then you want to
> > display those on a cube, one on each face.  At some point you must
> > load each photo up, clipping and scaling it to fit aspect ratio and a
> > power-of-two texture and then uploading it to vram.  Well, instead of
> > uploading each one as a separate texture, why not just create a
> > 1024x1024 bitmap and draw all 6 photos to it in different spots.  You
> > could use 50% of the texture vertically and 33% horizontally (for
> > example) to pack 6 photos onto it for 100% usage.  It's ok if they
> > distort going on to it so long as you draw them aspect-correct.  You
> > then keep track of which one is where (using UVs, so percentages from
> > 0 to 1).  Upload that texture atlas as a single texture and when you
> > draw your cube, you just bind to that atlas once and draw everything
> > in one shot.  It'll run fast and it's not really that hard to do.
>
> > On Jun 25, 6:26 pm, chaitanya  wrote:
>
> > > Hi,
> > >       I have just began opengl programming in android and i am fairly
> > > new to opengl as well. I've been using nehe's opengl tutorials as well
> > > as insanitydesign's android ports. I successfully managed to create a
> > > cube with a single texture mapped to all its 6 faces. I even mapped
> > > multiple textures to different faces of the cube.
> > >         But the way I did it was to create 6 faces seperately, have 6
> > > seperate index and texture buffers and then using glBindTexture() with
> > > the selected texture for each face and then calling glDrawElements.
> > > Isn't there an efficient way around this. Should i use a cube map
> > > texture instead of a GL_TEXTURE_2D?
>
> > >   Any suggestions would be appreciated?
> > > Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Mapping Multiple textures to a cube in Android OpenGL ES

2010-06-27 Thread chaitanya
Thanks Robert, So in short you are stating that I use a texture atlas
approach. The second approach is what I used right now, for every face
of the cube construct that side and binding it to the texture which
was really inefficient.
  Well, you have said something about the distortion. I read at nehe's
site that you can use mimaps to upload image of any size which will be
scaled to the best aspect ratio and will minimize the distortion.
Could I use that technique to create the texture atlas? Also, could
you give me some pointers or articles which discuss the creation of a
texture atlas since I'm fairly new at this.

On Jun 26, 12:01 am, Robert Green  wrote:
> No, that's not what cube maps are for.
>
> You can only draw 1 texture at a time (unless multitexturing but
> that's totally different and not what you want) so you have 2 options:
>
> 1)  Combine all textures together into a single one and map the
> coordinates to each side accordingly (will run much faster)
> 2)  Draw side-at-a-time binding to the appropriate texture for each
> side. (not usually the preferred method.)
>
> A trick many of us use when doing something like... say you want to
> have the user pick 6 photos from their SD card and then you want to
> display those on a cube, one on each face.  At some point you must
> load each photo up, clipping and scaling it to fit aspect ratio and a
> power-of-two texture and then uploading it to vram.  Well, instead of
> uploading each one as a separate texture, why not just create a
> 1024x1024 bitmap and draw all 6 photos to it in different spots.  You
> could use 50% of the texture vertically and 33% horizontally (for
> example) to pack 6 photos onto it for 100% usage.  It's ok if they
> distort going on to it so long as you draw them aspect-correct.  You
> then keep track of which one is where (using UVs, so percentages from
> 0 to 1).  Upload that texture atlas as a single texture and when you
> draw your cube, you just bind to that atlas once and draw everything
> in one shot.  It'll run fast and it's not really that hard to do.
>
> On Jun 25, 6:26 pm, chaitanya  wrote:
>
> > Hi,
> >       I have just began opengl programming in android and i am fairly
> > new to opengl as well. I've been using nehe's opengl tutorials as well
> > as insanitydesign's android ports. I successfully managed to create a
> > cube with a single texture mapped to all its 6 faces. I even mapped
> > multiple textures to different faces of the cube.
> >         But the way I did it was to create 6 faces seperately, have 6
> > seperate index and texture buffers and then using glBindTexture() with
> > the selected texture for each face and then calling glDrawElements.
> > Isn't there an efficient way around this. Should i use a cube map
> > texture instead of a GL_TEXTURE_2D?
>
> >   Any suggestions would be appreciated?
> > Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Mapping Multiple textures to a cube in Android OpenGL ES

2010-06-26 Thread Robert Green
No, that's not what cube maps are for.

You can only draw 1 texture at a time (unless multitexturing but
that's totally different and not what you want) so you have 2 options:

1)  Combine all textures together into a single one and map the
coordinates to each side accordingly (will run much faster)
2)  Draw side-at-a-time binding to the appropriate texture for each
side. (not usually the preferred method.)

A trick many of us use when doing something like... say you want to
have the user pick 6 photos from their SD card and then you want to
display those on a cube, one on each face.  At some point you must
load each photo up, clipping and scaling it to fit aspect ratio and a
power-of-two texture and then uploading it to vram.  Well, instead of
uploading each one as a separate texture, why not just create a
1024x1024 bitmap and draw all 6 photos to it in different spots.  You
could use 50% of the texture vertically and 33% horizontally (for
example) to pack 6 photos onto it for 100% usage.  It's ok if they
distort going on to it so long as you draw them aspect-correct.  You
then keep track of which one is where (using UVs, so percentages from
0 to 1).  Upload that texture atlas as a single texture and when you
draw your cube, you just bind to that atlas once and draw everything
in one shot.  It'll run fast and it's not really that hard to do.

On Jun 25, 6:26 pm, chaitanya  wrote:
> Hi,
>       I have just began opengl programming in android and i am fairly
> new to opengl as well. I've been using nehe's opengl tutorials as well
> as insanitydesign's android ports. I successfully managed to create a
> cube with a single texture mapped to all its 6 faces. I even mapped
> multiple textures to different faces of the cube.
>         But the way I did it was to create 6 faces seperately, have 6
> seperate index and texture buffers and then using glBindTexture() with
> the selected texture for each face and then calling glDrawElements.
> Isn't there an efficient way around this. Should i use a cube map
> texture instead of a GL_TEXTURE_2D?
>
>   Any suggestions would be appreciated?
> Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en