11-15-2008, 05:25 PM
#1 (permalink )
Registered Member
Join Date: Aug 2008
Location: London/Peterborough
Posts: 534
OpenGL ES text rendering as a block
Hi, I am trying just to draw some text on the screen with opengl es, I always however end up with the text as a huge green box...any ideas?
code:
- (void)drawView {
[EAGLContext setCurrentContext:context];
_textures[0] = [[Texture2D alloc] initWithString:@"hello" dimensions:CGSizeMake(1, 1) alignment:UITextAlignmentLeft fontName:@"Arial" fontSize:14];
//Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
//Initialize OpenGL states
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClearDepthf(1.0f);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat line[] = {
-0.5f, -0.5f, //point A
0.5f, -0.5f, //point B
};
GLfloat xxx[] = {
-0.0f, -0.5f, //point A
-0.5f, -0.2f, //point B
};
GLfloat spinline[] = {
-0.5f, 0.0f, //point A
0.5f, 0.0f, //point B
};
glColor4f(0.0f,1.0f,0.0f,1.0f);//Change the object color to green
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[_textures[0] drawAtPoint:CGPointMake(0, 0)];
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f,0.0f,0.0f,1.0f);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glVertexPointer(2, GL_FLOAT, 0, line);
glDrawArrays(GL_LINES, 0, 2);
glVertexPointer(2, GL_FLOAT, 0, xxx);
glDrawArrays(GL_LINES, 0, 2);
glVertexPointer(2, GL_FLOAT, 0, spinline);
glDrawArrays(GL_LINES, 0, 2);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
11-19-2008, 02:40 PM
#2 (permalink )
Registered Member
Join Date: Aug 2008
Location: London/Peterborough
Posts: 534
*bump*
*bump* - anyone have any ideas?
11-19-2008, 04:43 PM
#3 (permalink )
New Member
Join Date: Apr 2008
Posts: 802
Try drawing a simple shape first to make sure your codes working as expect. Next load an image into a texture and use that. If you get those working then double check your usage of the text in texture calls.
12-20-2008, 06:36 PM
#4 (permalink )
New Member
Join Date: Dec 2008
Posts: 2
Did anyone solve this ? I'm stuck exactly with that green box, and no text showing ...
01-13-2009, 10:23 PM
#5 (permalink )
New Member
Join Date: Jan 2009
Posts: 1
Try adding:
Code:
glDisableClientState(GL_COLOR_ARRAY);
To Texture2D's drawAtRect and drawAtPoint functions, that ended up working for me.
04-23-2009, 03:11 PM
#6 (permalink )
New Member
Join Date: Apr 2009
Posts: 1
The thread is now a little bit old, but I came across it while searching to solve the same problem. No luck finding info but I did manage to solve it anyway.
For me I ended up fixing it by figuring out that the GL renderstate was wrong...basically, texturing and blending states were the issues and solved by the first three lines of the following...
Code:
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f( 0.0f, 1.0f, 0.5f, 1.0f );
[texture drawAtPoint:CGPointMake( 0, 0 )];
04-24-2009, 04:10 PM
#7 (permalink )
New Member
Join Date: Apr 2009
Posts: 1
Quote:
Originally Posted by
tophat02
Try adding:
Code:
glDisableClientState(GL_COLOR_ARRAY);
To Texture2D's drawAtRect and drawAtPoint functions, that ended up working for me.
I am having the same problem. My string texture is rendering as a solid color block.
I have the correct blend mode enabled (glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)) and I have added glDisableClientState(GL_COLOR_ARRAY); to my drawAtPoint function yet it continues to be a solid block of color
Any ideas on how to fix?
[EDIT]: hahahahahaha oh man, I was just missing glEnable(GL_BLEND); Thanks ME_IS, your post made me double check haha.
Last edited by Proxus; 04-24-2009 at 04:14 PM .
05-05-2009, 07:33 AM
#8 (permalink )
Registered Member
Join Date: Apr 2009
Location: Madurai
Posts: 111
How to Rotate the text!!!
lBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Texture2D *text=[[Texture2D alloc] initWithString:@"Hello" dimensions:CGSizeMake(256, 256) alignment:UITextAlignmentLeft fontName:@"Arial" fontSize:14];
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
To display the text above code is ok.Then how to rotate the text using the texture2d class!!!
Last edited by lokidil; 05-05-2009 at 07:40 AM .
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 329
21 members and 308 guests
@sandris , ADY , BrianSlick , dacapo , Dani77 , dre , HDshot , HemiMG , JasonR , MarkC , mer10 , nibeck , prchn4christ , ryandb2 , spiderguy84 , themathminister , timle8n1 , tomtom100 , vogueestylee , vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam