OpenGL ES Textures Start White

Member
Posts: 61
Joined: 2009.01
Post: #1
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.
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #2
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
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".
Quote this message in a reply
Member
Posts: 61
Joined: 2009.01
Post: #4
That did it. Thanks for the help. Smile
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.09
Post: #5
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Sprite white out markhula 5 5,856 May 29, 2011 11:47 AM
Last Post: markhula
  App launches, tab bar shows, but content is white and viewWillAppear not called funkboy 3 4,540 Oct 21, 2009 12:13 AM
Last Post: sthaqu
  opengl es font textures? cool mr croc 0 2,368 Aug 17, 2009 04:52 AM
Last Post: cool mr croc
  OpenGL ES Loading Textures soulstorm 5 6,758 May 25, 2009 07:21 AM
Last Post: soulstorm
  OpenGL textures upside down? orbian 1 9,293 Mar 13, 2009 02:53 PM
Last Post: ThemsAllTook