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 857395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:23:34+00:00 2026-05-15T08:23:34+00:00

XCode’s OpenGL template seems to be cheating to solve this stretched viewport problem I’ve

  • 0

XCode’s OpenGL template seems to be cheating to solve this “stretched” viewport problem I’ve been trying to understand for the last 3 hours.

In the iphone “OpenGL ES Application” template, the colorful square that bounces up and down on the screen is not really a square at all!

ES1Renderer.m (the ES2 file as well)

static const GLfloat squareVertices[] = {
    -0.5f,  -0.33f,
     0.5f,  -0.33f,
    -0.5f,   0.33f,
     0.5f,   0.33f,
};

But it comes out looking square on the device/simulator due to the stretching/squashing effect of a non-square viewport. I tried to fix it by fiddling with glFrustumf() but that doesn’t seem to change the aspect ratio.

I was able to get things looking good (not-stretched) when I fed glViewport() with a 1:1 widht:height.. But this doesn’t seem like the answer because it offsets the viewport placement.

What’s the right way to correct for this stretching and why doesn’t XCode do it that way?

  • 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-15T08:23:35+00:00Added an answer on May 15, 2026 at 8:23 am

    I think the answer is:

    XCode is cheating like this to avoid confusing us with the extra code required to setup a frustum.

    Here’s the code I’m using to set one up, and it fixed the squashing/stretching I was getting:

    const GLfloat zNear = 0.0001, zFar = 1000.0, fieldOfView = 45.0; 
    GLfloat size;
    
    size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
    
    aspectRatio = (GLfloat) backingWidth / backingHeight;
    
    
    glFrustumf(-size,//left
               size,//right
               (GLfloat)-size / aspectRatio,//bottom 
               (GLfloat)size / aspectRatio,//top 
               zNear,//zNear 
               zFar);//zFar     
    
    glViewport(0, 0, backingWidth, backingHeight); 
    

    Hope that helps someone.

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

Sidebar

Related Questions

XCode: This template provides a starting point for an application that uses a single
I've been using Xcode for the usual C/C++/ObjC development. I'm wondering what are practical
Xcode with GCC 4.2 it seems it's possible to deactivate thumbmode for the whole
Xcode gives me this warning when I build the app for release. Application failed
Xcode keeps picking my developer provision. This is even if I pick Don't Code
Xcode seems to split the code window and show the file name in the
Xcode is giving me this warning: ld: warning: duplicate dylib /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/system/libSystem.host.dylib There's an SO
Xcode 4 completely changed the (project) template system. There's a lot more you can
In Xcode, I can use CMD - R to run (or CMD - Y
Does Xcode support anything akin to Visual Studio style #region directives for arbitrary code

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.