clearing loaded textures

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

clearing loaded textures

Postby rHalf » Sun Dec 20, 2009 2:11 am

Hi all, I'm new to all this android development as well as OpenGL.

I was going through some book code which has limited comments on certain aspects of openGL.

It's a cube creation demo and uses a method called

Bitmap bmp =...
GLUtils.texImage2d(GL10.GL_TEXTURE_2D, 0, bmp , 0);

It puts that same bitmap on all sides of the cube.

I modified the renderer to now have 2 Cubes and at first they both use the same bitmap as a texture.
I made a call to the loadTexture method with a different resource and now all the sides of the second cube have the new bitmap as their texture.

As far as I can tell this method has a single resource buffer that is almost used like a paint on a paintbrush. Not until you dip it into the second paint (Bitmap) does it paint differently. I was wondering if there was a method to unload that resource or to keep with the analogy wash the paintbrush clean.

Say I wanted to make a third cube with no textures.

I saw some tutorials that talk about some sort of resource id, but in my case there is no id that i can tell of.

Similar but not the same, does anyone know of a tutorial where a cube has different textures on different sides?

Thanks
rHalf
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sun Dec 20, 2009 1:54 am

Top

Postby rHalf » Mon Dec 21, 2009 7:54 pm

I may have answered my own question. Just required more reading.

I believe you can just add gl.glDisable(GL10.GL_TEXTURE_2D) to turn off texture rendering to surfaces.
rHalf
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sun Dec 20, 2009 1:54 am

Postby Skywhy » Sun Dec 27, 2009 4:19 pm

That's pretty much it :)

I thought I'd post a fair warning if you are new to OpenGL. The more you change OpenGL's internal states, the slower it behaves (ie. calling methods like gl.disable() or any other methods that change states inside OpenGL).

So, let's say you have number of cubes to render with texture1, number of cubes to render with texture2 and a number of cubes to render without any texturing, you should arrange the render calls in a way that there are only minimal amount of OpenGL state changes.

Don't just randomly hop from render call to another changing the OpenGL states. That's sure to kill any performance you have going on with OpenGL. Instead arrange objects/render calls this way (just ONE way of doing it):

- Call render on ALL objects that are rendered with texture1
- Call render on ALL objects that are rendered with texture2
- Call render on ALL objects that are rendered without texture

this way per one main loop the state changes are "minimized" (I believe there is going to be... hmm... one OpenGL state change per loop with this way. Changing texture coordinates do not change OpenGL state as far as I know) and OpenGL can keep functioning as fast as possible :) It's fast to render but it slows down like hell when you tinker with its states.


// SkyWhy
Skywhy
Developer
Developer
 
Posts: 35
Joined: Tue Oct 20, 2009 7:55 pm

Postby rHalf » Thu Dec 31, 2009 6:59 am

Thanks for the response.

I thought i saw something using different textures.
Do you have a short example of switching between the different textures?
and (I dont know if this is the correct terminology) Buffering these textures?

I assume it has to do with:
GLUtils.texImage2d(GL10.GL_TEXTURE_2D, 0, bmp , 0);
rHalf
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sun Dec 20, 2009 1:54 am

Postby Skywhy » Thu Dec 31, 2009 9:46 am

The thing is, that method again swithces OpenGL states. So "swapping" a new texture to OpenGL switches state and slows it down.

What you want to do is to build your sprites / textures in a way that you make Texture atlases out of them (collect all your sprites/textures into one bix texture (or more if required) and minimise the swapping of textures this way.

Instead of saying to OpenGL "use this as a new texture", you just tell OpenGL "ok, just move the texture coordinates around on the big texture atlas".

And if you have more than one big texture atlas, you want to minimise the texture changes to minimise slowdown.

Again requires a bit "tweaking" and knowing in which order stuff will be. Using the same approach as I told earlier, ordering render calls in a way that the state changes are minimised. Also I noticed a mistake there, when I was talking of "texture1" and "texture2", I made the assumption of having the texture on the same BIG texture -> no need to actually CHANGE texture but instead just use different texture coordinates.


Unfortunately for now I don't have any examples to offer to show how it's done.
Skywhy
Developer
Developer
 
Posts: 35
Joined: Tue Oct 20, 2009 7:55 pm

Top

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

Who is online

Users browsing this forum: No registered users and 1 guest