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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:09:25+00:00 2026-06-12T17:09:25+00:00

[SOLVED – See answer in bottom] I’m trying to draw a cube with perspective,

  • 0

[SOLVED – See answer in bottom]

I’m trying to draw a cube with perspective, using OpenGL ES 2.0 on iOS (iPhone), but it’s appearing as a rectangular shape.

From what I’ve gathered searching the web it seems to be related to the viewport / projection matrix, but I can’t seem to put the finger on the actual cause.

If I set the viewport to a square measure (width == height) it draws perfectly well (a cube), but if I set it correctly (width = screen_width, height = screen_height) then the cube is drawn as a rectangular shape.

Should setting the Projection matrix accordingly with the Viewport make the cube stay a cube?!

My code (please let me know if more info is needed):

Render method:

// viewportSize is SCREEN_WIDTH and SCREEN_HEIGHT
// viewportLowerLeft is 0.0 and 0.0
ivec2 size = this->viewportSize;
ivec2 lowerLeft = this->viewportLowerLeft;
glViewport(lowerLeft.x, lowerLeft.y, size.x, size.y); // if I put size.x, size.x it draws well


mat4 projectionMatrix = mat4::FOVFrustum(45.0, 0.1, 100.0, size.x / size.y);

glUniformMatrix4fv(uniforms.Projection, 1, 0, projectionMatrix.Pointer());

Matrix operations:

static Matrix4<T> Frustum(T left, T right, T bottom, T top, T near, T far)
{
    T a = 2 * near / (right - left);
    T b = 2 * near / (top - bottom);
    T c = (right + left) / (right - left);
    T d = (top + bottom) / (top - bottom);
    T e = - (far + near) / (far - near);
    T f = -2 * far * near / (far - near);
    Matrix4 m;
    m.x.x = a; m.x.y = 0; m.x.z = 0; m.x.w = 0;
    m.y.x = 0; m.y.y = b; m.y.z = 0; m.y.w = 0;
    m.z.x = c; m.z.y = d; m.z.z = e; m.z.w = -1;
    m.w.x = 0; m.w.y = 0; m.w.z = f; m.w.w = 1;
    return m;
}
static Matrix4<T> FOVFrustum(T fieldOfView, T near, T far, T aspectRatio)
{
    T size = near * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
    return Frustum(-size, size, -size / aspectRatio, size / aspectRatio, near, far);
}
  • 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-06-12T17:09:26+00:00Added an answer on June 12, 2026 at 5:09 pm

    Ok I found out the problem, size.x and size.y are int, so the division returns an int.

    1.0 * size.x / size.y
    

    Solves the problem.
    facepalm

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

Sidebar

Related Questions

[SOLVED] See my answer below. I am trying to use stringstream (named ss) to
[SOLVED (see answer below)] I am using SpreadsheetWorker API to make working with Open
SOLVED! See my self-answer below. I'm building two Metro-style apps using Javascript and HTML,
SOLVED: View the answer below marked SOLVED. Thanks. I am trying to download a
SOLVED See my answer below. Question left unchanged for anyone else who has trouble
[SOLVED: See solution below.] I'm having a problem writing a RewriteMap program (using Python).
Solved: The problem was: wrong version of Java. See my comments. Hi all, using
solved, see my FINAL ANSWER post for complete details on what worked for me
Solved: see answer below I am sub-classing Dialog to create a dialog with a
SOLVED: See my answer below I'm experiencing the same issue that Austin Hyde experienced

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.