Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to draw texture with OpenGL ES?

I saw this Google IO session: http://code.google.com/intl/iw/events/io/2009/sessions/WritingRealTimeGamesAndroid.html
He says that the draw_texture function is the fastest and VBO is 2nd faster.
But I don't understand how to use it(the draw_texture method or the VBO way).

Any suggestion?

like image 418
Adir Avatar asked Feb 06 '10 18:02

Adir


2 Answers

The source code for the sprite method test mentioned in the video is available here:
http://code.google.com/p/apps-for-android/source/browse/#svn/trunk/SpriteMethodTest

Here is an example from that where a VBO is used:
http://code.google.com/p/apps-for-android/source/browse/SpriteMethodTest/src/com/android/spritemethodtest/Grid.java#237

Here is an example from that where the draw texture extension is used:
http://code.google.com/p/apps-for-android/source/browse/SpriteMethodTest/src/com/android/spritemethodtest/GLSprite.java

One thing to watch out for, however, is that the draw texture extension is actually not the fastest for all games using sprites. Many games have groups of sprites that all share the same render state, for example. In that case it is much faster to put all sprites with the same render state in the same buffer and draw them with the same draw command. The draw texture command doesn't allow this. With the draw texture command you have to call it once per sprite.

This is the reason that atlas textures are often used. An atlas texture is a single bound texture object that has many different images in it. You can draw sprites with different images that way without having to bind to a different texture object. All you do is have them use different texture coordinates into the atlas texture. If the other render state is the same as well, such as the blending function needed, then you can draw the sprites together for better performance.

like image 175
Lance Nanek Avatar answered Sep 23 '22 21:09

Lance Nanek


Here are some great Android OpenGL ES working examples.

http://code.google.com/p/android-gl/

like image 38
Patrick Kafka Avatar answered Sep 23 '22 21:09

Patrick Kafka