Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:41:37+00:00 2026-05-29T07:41:37+00:00

I am beginning to learn OpenGL ES 1.1 for iPhone and would like to

  • 0

I am beginning to learn OpenGL ES 1.1 for iPhone and would like to draw a 2D image in orthographic projection behind a few 3D objects. Using Jeff Lamarche’s tutorials and the book Pro OpenGL ES for iPhone and I’ve come up with the following couple methods to attempt to do this. If I disable the call to drawSunInRect the 3D objects are rendered just fine and I can move them with touch controls etc. If I uncomment that call and try to draw the sun image, the image appears in the CGRect I supply, but I cannot see any of my other 3D objects – the rest of the screen is black. I’ve tried to disable/enable depth testing in various places, pass different parameters to glOrthof(), and move around the rectangle but I keep getting the sun image only when the drawSunInRect method is called. I’m assuming it is covering my 3D objects.

// Draw Sun in Rect and with Depth
- (void)drawSunInRect:(CGRect)rect withDepth:(float)depth {

    // Get screen bounds
    CGRect frame = [[UIScreen mainScreen] bounds];

    // Calculate vertices from passed CGRect and depth
    GLfloat  vertices[] = 
    {
        rect.origin.x, rect.origin.y, depth,

        rect.origin.x + rect.size.width , rect.origin.y, depth,

        rect.origin.x, rect.size.height+rect.origin.y , depth,

        rect.origin.x + rect.size.width , rect.size.height+rect.origin.y ,depth
    };

    // Map the texture coords - no repeating
    static  GLfloat textureCoords[] = 
    {               
        0.0, 0.0,
        1.0, 0.0,
        0.0, 1.0,
        1.0, 1.0
    };

    // Disable DEPTH test and setup Ortho
    glDisable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrthof(0,frame.size.width,frame.size.height,0,0.1f,1000.0); 

    // Enable blending and configure
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

    // Enable VERTEX and TEXTURE client states
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    // Enable Textures
    glEnable(GL_TEXTURE_2D); 

    // Projection Matrix Mode for ortho and reset
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();     
    glLoadIdentity();      

    // No lighting or Depth Mask for 2D - no Culling
    glDisable(GL_LIGHTING);                                                                                          
    glDepthMask(GL_FALSE);
    glDisable(GL_CULL_FACE);
    glDisableClientState(GL_COLOR_ARRAY);   

    // Define ortho
    glOrthof(0,frame.size.width,frame.size.height,0,0.1f,1000); 

     // From Jeff Lamarche Tutorials
     // glOrthof(-1.0,                                          // Left
     // 1.0,                                                    // Right
     // -1.0 / (rect.size.width / rect.size.height),            // Bottom
     // 1.0 / (rect.size.width / rect.size.height),             // Top
     // 0.01,                                                   // Near
     // 10000.0);                                               // Far

    // Setup Model View Matrix
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    // Bind and draw the Texture
    glBindTexture(GL_TEXTURE_2D,sunInt);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT,0,textureCoords);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    glMatrixMode(GL_MODELVIEW); 
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    // Re-enable lighting 
    glEnable(GL_LIGHTING);  
    glDisable(GL_TEXTURE_2D);   
    glDisable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDepthMask(GL_TRUE);

}


// Override the draw in rect function
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{

    // Initialize and init the rotation stuff for the object
    // Identity Matrix
    glLoadIdentity();
    static GLfloat rot = 0.0;

    // Clear any remnants in the drawing buffers
    // and fill the background with black
    glClearColor(0.0f,0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Render the Sun - 2D Sun Image in CGRect
    //[self drawSunInRect:CGRectMake(100, 100, 50, 50) withDepth:-30.0]; // 2D Sun Image

    // Render the BattleCruiser - 3D Battlecruiser
    [self renderTheBattleCruiser];

    // Calculate a time interval to use to rotate the cruiser lives
    static NSTimeInterval lastDrawTime;
    if (lastDrawTime)
    {
        NSTimeInterval timeSinceLastDraw = [NSDate timeIntervalSinceReferenceDate] - lastDrawTime;
        rot += 75 * timeSinceLastDraw;                
    }
    lastDrawTime = [NSDate timeIntervalSinceReferenceDate];

}

UPDATE

I modified the draw sun method to have only 1 push and 1 pop for the GL_PROJECTION. I am still having the same issue. The sun image appears but I cannot see my 3D Objects. I have tried to re-arrange the calls to the render methods so the 3D objects are rendered first but I get the same results. I would appreciate other ideas on how to see my orthographic texture and 3D objects together.

// Draw Sun in Rect and with Depth
- (void)drawSunInRect:(CGRect)rect withDepth:(float)depth {

    // Get screen bounds
    CGRect frame = [[UIScreen mainScreen] bounds];

    // Calculate vertices from passed CGRect and depth
    GLfloat  vertices[] = 
    {
        rect.origin.x, rect.origin.y, depth,

        rect.origin.x + rect.size.width , rect.origin.y, depth,

        rect.origin.x, rect.size.height+rect.origin.y , depth,

        rect.origin.x + rect.size.width , rect.size.height+rect.origin.y ,depth
    };

    // Map the texture coords - no repeating
    static  GLfloat textureCoords[] = 
    {               
        0.0, 0.0,
        1.0, 0.0,
        0.0, 1.0,
        1.0, 1.0
    };

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D); 

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();     
    glLoadIdentity();      

    glDisable(GL_LIGHTING);                                                                                          
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glDisableClientState(GL_COLOR_ARRAY);   

    glOrthof(0,frame.size.width,frame.size.height,0,0,1000);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glColor4f(1,1,1,1);

    glBindTexture(GL_TEXTURE_2D,sunInt);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT,0,textureCoords);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    glMatrixMode(GL_MODELVIEW); 
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glEnable(GL_LIGHTING);  
    glDisable(GL_TEXTURE_2D);   
    glDisable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:41:38+00:00Added an answer on May 29, 2026 at 7:41 am

    I realized I was calling setClipping only once in my viewController viewDidLoad. I moved it to my glkView method and now I get my Sun image and my 3d object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just beginning to learn OpenCV and I would like to ask about how
I'm beginning to learn perl and I'm writing a simple bubble sort using regular
We are beginning to learn Android, converting our iPhone apps over. There is a
I am new to linux, and just beginning to learn bash. I am using
I’m just beginning to learn Django and I like the automatic listing in Django
I would like to learn all the techniques related to UIScrollView about tiling and
Just beginning to learn about structs, I thought I understood how they work, using
I'm just beginning to learn about proper releasing of objects for memory management in
I am beginning to learn css and html programming, I am currently using notepad
We are just beginning to learn and evaluate Mercurial, due to an increasing number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.