Mapping Multiple textures to a cube in Android OpenGL ES

Problems with Canvas, OpenGL, etc...

Mapping Multiple textures to a cube in Android OpenGL ES

Postby vengeance_mj » Sat Jun 26, 2010 12:28 am

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
vengeance_mj
Senior Developer
Senior Developer
 
Posts: 174
Joined: Thu Oct 29, 2009 2:32 am

Top

Re: Mapping Multiple textures to a cube in Android OpenGL ES

Postby impi » Sun Jun 27, 2010 6:09 pm

Pack your textures in one grouped TextureAtlas, and use different Texture Coordinates should do it
impi
Developer
Developer
 
Posts: 29
Joined: Wed Apr 28, 2010 11:17 pm

Re: Mapping Multiple textures to a cube in Android OpenGL ES

Postby vengeance_mj » Sun Jun 27, 2010 9:20 pm

Thanks, could you give me some examples or pointers as to how a texture atlas would be created
vengeance_mj
Senior Developer
Senior Developer
 
Posts: 174
Joined: Thu Oct 29, 2009 2:32 am

Re: Mapping Multiple textures to a cube in Android OpenGL ES

Postby impi » Sun Jun 27, 2010 10:11 pm

Automatically by code or simply with Paint and some definition file with the regions (in xml for example). You can also create an atlas fixed sizes and generate the coordinates.

For example an 512x512 atlas can contain 4 256x256 textures, and you generate the coordinates programatically. Then you store the information in an array and paste them right in an your texCoordBuffer.

vertices 1 -> texcoord 1, vertices 2 -> texCoord 2.. and so one, like you would normally do with 0 to 1 now with 0 to for example 0.5 from the texture. You just need to calculate where the coordinate start and end.
impi
Developer
Developer
 
Posts: 29
Joined: Wed Apr 28, 2010 11:17 pm

Re: Mapping Multiple textures to a cube in Android OpenGL ES

Postby Girish » Thu Oct 07, 2010 6:46 am

Hi impi,

Can you elaborate how to map six faces of cube 6 distinct images using texture atlas, even we are also facing the performance problem with the other approach.If you can share the code if you have it, it would be very helpful for us.

Awaiting for your response,

Regards
Girish
Girish
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 01, 2010 10:31 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests