Game Development Reference
In-Depth Information
Loading Textures
Loading textures is performed in both GL and GL ES with a call to glTexImage2D . However,
there are differences in the way the image data needs to be handled. In GL ES, all textures
must have dimensions in powers of 2. This is not necessarily the case in traditional GL. To
overcome this, you could
ļ®
Resize the image assets of your game to be powers of 2. This should
make startup times faster but can consume time depending on the
number of assets.
ļ®
Resize images on the fly when loading. This may increase loading
times but you won't have to manually resize those images. I would
recommend resizing the files to speed up loading times.
When loading textures with glTexImage2D , the only supported formats are GL_ALPHA , GL_
RGB , GL_RGBA , GL_LUMINANCE , or GL_LUMINANCE_ALPHA (traditional GL supports many more).
Arguments for internal format and format (arguments 3 and 7) must be the same. This is not
necessarily the case in GL and is often a common mistake made when porting between both
platforms. Thus the correct way of loading pixels in GL ES is
glTexImage2D( target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
The bottom line when using glTexImage2D is to make sure the pixel format is correct and that
it matches the format defined by arguments 3 and 7 of the call.
Display Lists, Server Attributes, and Others
When it comes to display lists and server attributes, there is some bad news: they are not
supported by GL ES in any way or form, and there is no easy workaround.
Display lists are sequences of precompiled GL statements that can be called again and
again to increase performance. They are commonly used when rendering fonts or repetitive
shapes or objects (the pieces of a 3D chess game are commonly rendered using display
lists). Fortunately, a display list is not something you will find in every 3D engine out there
(3D chess, checkers, and so on. are the most common culprits). If they are used in your
code, you must remove them manually.
Server attributes are handled by two calls: glPushAttrib and glPopAttrib . They don't exist
in GL ES; therefore you'll have to manage these states yourself.
Another minor issue is that GL ES only supports float. GLdouble doesn't exist, so any
GLdouble should be converted to GLfloat ; plus all GL function calls ending with a ā€œdā€ should
have the d replaced with f. You can easily do this with
#define GLdouble GLfloat
#define GL_CLAMP GL_CLAMP_TO_EDGE
#define glClearDepth glClearDepthf
#define glOrtho glOrthof
 
Search WWH ::




Custom Search