OpenGL ES Textures Start White
Hey all -
I've got some OpenGL 2D textures that are loaded from image files using CGImage, and it all works fine except for one small problem.
In other environments where I've loaded textures into OpenGL once I call glGenTextures / glBindTexture / glTexImage2D then it'll be preloaded. However, I've done that on the iPhone and the image is never actually loaded until it is drawn on screen. So, I get an ugly white square drawn to the screen, a moment of lag as the texture is truly loaded, and then once that has happened it's loaded permanently. Is this iPhone or OpenGL ES behavior? Is there any way to actually preload a texture?
Thanks.
I've got some OpenGL 2D textures that are loaded from image files using CGImage, and it all works fine except for one small problem.
In other environments where I've loaded textures into OpenGL once I call glGenTextures / glBindTexture / glTexImage2D then it'll be preloaded. However, I've done that on the iPhone and the image is never actually loaded until it is drawn on screen. So, I get an ugly white square drawn to the screen, a moment of lag as the texture is truly loaded, and then once that has happened it's loaded permanently. Is this iPhone or OpenGL ES behavior? Is there any way to actually preload a texture?
Thanks.
Sounds like your OpenGL calls are in the wrong order. Do you call glEnable(GL_TEXTURE_2D) before rendering?
There's no such thing as preloading textures - when you tell OpenGL to load your texture, it's loaded in its entirety before the code continues. If you're getting a white square, the reason is probably because you didn't set the correct states for OpenGL to render the texture that was loaded correctly.
There's no such thing as preloading textures - when you tell OpenGL to load your texture, it's loaded in its entirety before the code continues. If you're getting a white square, the reason is probably because you didn't set the correct states for OpenGL to render the texture that was loaded correctly.
The most likely cause is that you haven't set GL_TEXTURE_MIN_FILTER correctly before you draw with the texture the first time. So the texture is treated as "incomplete".
That did it. Thanks for the help.
If you are loading textures from PNG or JPG files using UIImage, CGImage and CGContext, it is very important to set GL_TEXTURE_MIN_FILTER to GL_LINEAR or GL_NEAREST before creating textures, because if you don't do it, all your textures except the last bound will be set to blank white.
mcfrei Wrote:If you are loading textures from PNG or JPG files using UIImage, CGImage and CGContext, it is very important to set GL_TEXTURE_MIN_FILTER to GL_LINEAR or GL_NEAREST before creating textures, because if you don't do it, all your textures except the last bound will be set to blank white.
Slight correction to that. If you are loading textures at all, you need to set the filter.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Sprite white out | markhula | 5 | 4,883 |
May 29, 2011 11:47 AM Last Post: markhula |
|
| opengl es font textures? | cool mr croc | 0 | 2,099 |
Aug 17, 2009 04:52 AM Last Post: cool mr croc |
|
| OpenGL ES Loading Textures | soulstorm | 5 | 5,303 |
May 25, 2009 07:21 AM Last Post: soulstorm |
|
| OpenGL textures upside down? | orbian | 1 | 5,576 |
Mar 13, 2009 02:53 PM Last Post: ThemsAllTook |
|
| xcode NO COLOR (black & white !) | imaumac | 3 | 3,496 |
Jan 14, 2009 10:10 PM Last Post: longjumper |
|

