Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2009, 03:09 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Poland
Age: 30
Posts: 6
Question Text with OpenGL

Hi,

I've created a project from default iPhone OpenGL project template. I'd like to place text on the view, so I'm trying to use Texture2D class provided by Apple.

In initWithCoder method I've added line:

Code:
testText = [[Texture2D alloc] initWithString:@"Test" dimensions:CGSizeMake(100, 100) alignment:UITextAlignmentLeft fontName:@"Helvetica" fontSize:30];
I've modified drawView method - it looks like this:

Code:
- (void)drawView {
    // Replace the implementation of this method to do your own custom drawing
    const GLfloat squareVertices[] = {
        -0.5f, -0.5f,
        0.5f,  -0.5f,
        -0.5f,  0.5f,
        0.5f,   0.5f,
    };
    const GLubyte squareColors[] = {
        255, 255,   0, 255,
        0,   255, 255, 255,
        0,     0,   0,   0,
        255,   0, 255, 255,
    };

    [EAGLContext setCurrentContext:context];

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

/*    
    glViewport(0, 0, backingWidth, backingHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glRotatef(3.0f, 0.0f, 0.0f, 1.0f);

    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glVertexPointer(2, GL_FLOAT, 0, squareVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

*/

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    [testText drawAtPoint:CGPointMake(0.0f, 0.0f)];
         glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);


    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

}
Could you help? I'm developing with OS 3.0. I've searched this forum for solution but everything I've found doesn't work for me. What am I doing wrong?

Thx

Krzychu
krisix is offline   Reply With Quote
Old 09-09-2009, 04:04 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Default

What is happening wrong? Is it compiling? Does it display anything? Does it crash when it start running?

Is the commented out part yours or the default stuff?


Also, I am not sure if you have already found it or not but if you are starting out OpenGL on iphone Simon Maurices Blog is really good: iPhone OpenGL ES Tutorial Series ?
Jamvert is offline   Reply With Quote
Old 09-10-2009, 01:28 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Poland
Age: 30
Posts: 6
Default

Commented out part is default stuff - I've just removed it. The project is compiling fine but none text is displaying.

Thanks for the link - it's really useful!

Dou you have any idea what I'm doing wrong?
krisix is offline   Reply With Quote
Old 09-10-2009, 01:33 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: currently AZ
Posts: 112
Send a message via MSN to kingbombs
Default

yeah you need to give information on what is going wrong
although calling the glBlendfunc twice won't help, although don't think it will really effect anything but remove them both and see what happens (not sure what the 2nd blendFunc is doing?)
kingbombs is offline   Reply With Quote
Old 09-10-2009, 02:09 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Default

It might be just cause I am not that good at openGL but I think it is very difficult to tell what you are doing wrong just from that.

For starters, some of the commented out code, starting with the glViewPort, do you have equivalent code somewhere else in your code or did you just eliminate it all together? You can throw away some of that stuff but some of it you need to do before you draw.

I don't know about the Texture2D class though, I can't find the documentation for it.
Jamvert is offline   Reply With Quote
Old 09-10-2009, 02:44 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Default

What might be easier is if you first just try to draw your text on top of Apples starting shape, then once you have you text drawing start removing apples stuff. That way you can break it down into smaller parts and have a better idea where things start going wrong.
Jamvert is offline   Reply With Quote
Old 09-12-2009, 12:49 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Poland
Age: 30
Posts: 6
Thumbs up

Hi,

I've found solution Please check this page. You can download source code there.

Please take a look at setupView method and gluPerspective method. When I've implemented both methods in my code the text is on the screen!

Thx for help!
krisix is offline   Reply With Quote
Old 09-13-2009, 05:27 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: currently AZ
Posts: 112
Send a message via MSN to kingbombs
Default

Quote:
Originally Posted by kingbombs View Post
yeah you need to give information on what is going wrong
although calling the glBlendfunc twice won't help, although don't think it will really effect anything but remove them both and see what happens (not sure what the 2nd blendFunc is doing?)


Quote:
Originally Posted by gotorightway123 View Post
you need to give information on what is going wrong
although calling the glBlendfunc twice won't help, although don't think it will really effect anything but remove them both and see what happens (not sure what the 2nd blendFunc is doing?)
You quoted me directly without the quote tags? and didn't say anything else? (and without the 'yeah' at the start)
kingbombs is offline   Reply With Quote
Old 09-13-2009, 06:45 PM   #9 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Quote:
Originally Posted by kingbombs View Post
You quoted me directly without the quote tags? and didn't say anything else? (and without the 'yeah' at the start)
I think gotorightway123 is a spambot pretending to be human. All his posts are quotes of previous posts.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
opengl, opengl es, texture2d

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 259
23 members and 236 guests
@sandris, ADY, Dani77, diyora, FAED, fredidf, F_Bryant, GHuebner, HDshot, iDifferent, JasonR, mer10, Oral B, prchn4christ, Rudy, Speed, spiderguy84, stekki, tgjorgoski, Thompson22, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,753
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0