Texture2D initWithString background

Apprentice
Posts: 9
Joined: 2008.12
Post: #1
Im using the Texture2D functions from Touchfighter sample app.
I want to place a string on my OpenGL view, and have created one using the initWithString initializer.
Although i can change the foreground color easily enough using glColor4f, i always get a black background. The Touch example is transparent, and i've hacked my code to mimic the touch implementation but still cant seem to get the background transparent. All my other textures seem to have a perfectly working alpha channel. I've even tried different blend functions for the text.

Any ideas?
texture = [[Texture2D alloc] initWithString:@"Hello" dimensions:CGSizeMake(32., 16.) alignment:UITextAlignmentLeft font:[UIFont systemFontOfSize:14.0]];

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_BLEND);
[texture drawAtPoint:CGPointMake(0,0)];
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.12
Post: #2
I made some progress, but still can't get this right.

I've found that with a blendfunction of (GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
and with a glColor4f(1,1,1,1) i get nice white text with a transparant background.
However, I want black text and as I reduce the glColor4f RGB values the text trends towards transparant rather than Black.
I'm guess its using black as its transparant color so i would not be able to get to black text.
My own black textures are working fine however.
Any advice appreciated.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #3
As it says in the Texture2D header, you need to use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for text.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.12
Post: #4
I tried using that blend function based on your example in an earlier thread.
However, when using (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) i get a fix black background to the text box rather than transparancy.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #5
Could be a bunch of different things. Did you check out this FAQ, in particular the section on how to debug?

Without seeing more of your code it is a little difficult to come up with many suggestions. You're saying that my example is giving a black background too?

[edit] my other crazy ideas removed because of silliness Wink
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #6
Hang on, I think I might know what's up, I'll be back in a few...
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #7
Aiight, I think I got it. I'm using the Texture2D from **CrashLanding**, which uses alpha textures for font textures. In the initWithString method in Texture2D.m, make sure it says this for the initWithData call:

Code:
self = [self initWithData:data pixelFormat:kTexture2DPixelFormat_A8 pixelsWide:width pixelsHigh:height contentSize:dimensions];

Specifically, make sure it is using kTexture2DPixelFormat_A8 for the pixelFormat.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.12
Post: #8
Holy cow, your a genius...I was using the Texture2D from TouchFighter which used a kTexture2DPixelFormat_L8

Changed it to A8 and all is good.

A thousand thanks!
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #9
Definitely not genius, just luck and reasoning.

You said you got a black background with my example in that other thread, and I know that should not have happened. So I reasoned it must have been either: 1) somehow rendered wrong before it was handed over to the GL -- OR-- 2) somehow handed over to the GL with the wrong settings

So I ran with number 2, did some testing, and here we are!

Glad you got it working Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture2d crash lander ajrs84 0 2,748 Apr 1, 2012 08:54 AM
Last Post: ajrs84
  Problem using Texture2D sub-section bendell 0 2,420 Mar 20, 2010 02:06 AM
Last Post: bendell
  Create a texture2d with contents of other textures godexsoft 6 4,476 Nov 12, 2009 10:24 PM
Last Post: godexsoft
  OpenGL ES and Texture2D Talyn 37 31,066 Jul 30, 2009 09:34 AM
Last Post: Splat21
  Texture2d with strings kendric 10 5,315 Jul 14, 2009 09:28 PM
Last Post: warmi