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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:58:07+00:00 2026-05-26T02:58:07+00:00

I’m writing a 3D OpenGL app and I’m having problems with my vertex translation

  • 0

I’m writing a 3D OpenGL app and I’m having problems with my vertex translation matrix.

Here’s my vertex shader:

attribute vec4     vInPos;

uniform mat4    kWorld;
uniform mat4    kProj;

void main( void )
{
    vec4 world_pos = kWorld * vInPos;
    gl_Position = kProj * world_pos;
}

All my matrices are stored row major and I’m using a left handed perspective matrix as my projection matrix.

The problem is, when I translate a vertex by my matrix, it moves in the wrong direction on both the X and Y axes, and is flipped. So translating by (100.0f,100.0f,100.0f) moves my vertex the correct way on the Z axis (away from the camera), but to the left on the X axis (backwards) and down on the Y axis (backwards).

Here’s what it currently looks like: screenshot

The FPS counter should be up and to the right, instead of down to the left. It should also obviously not be mirrored. Based on what I’ve read, this is happening because OpenGL by default uses the right-handed coordinate system, but I’m not sure what I can do to fix this.

I found a few articles that try to explain it, but I couldn’t find any solutions for what to do. This question mentions that the OpenGL spec shows what the coordinate system expected, but after looking, I didn’t see how that helped me.

EDIT:
For reference, my projection matrix code is based on the DirectX SDK.

EDIT:
Per Nicol Bolas’ suggestion, I’m now using the matrix from gluPerspective, but I’m getting the same results.


Here’s the code I’m using to set my matrices:

/* Vertex data for reference
float vertices[] =
{
    {0.0f,0.0f,0.0f},
    {5.0f,0.0f,0.0f},
    {0.0f,5.0f,0.0f},
    {5.0f,5.0f,0.0f},
}; */    
float worldf[16];
float projf[16];
float fov       = 60.0f;
float aspect    = 1280.0f/720.0f;
float near      = 1.0f;
float far       = 1000.0f;
float f         = 1.0f/tanf( (fov*6.2831f/360.0f)/2.0f );

/* Build world matrix */
memset(worldf, 0, sizeof(worldf));
worldf[0] = worldf[5] = worldf[10] = worldf[15] = 1.0f;
worldf[12] = 100.0f;
worldf[13] = 100.0f;
worldf[14] = -100.0f;

/* Build perspective matrix */
memset(projf, 0, sizeof(projf));
projf[0] = f/aspect;
projf[5] = f;
projf[10] = (far+near)/(near-far);
projf[14] = (2.0f*far*near)/(near-far);
projf[11] = -1.0f;

glUniformMatrix4fv(proj_uniform, 1, GL_FALSE, projf);
glUniformMatrix4fv(world_uniform, 1, GL_FALSE, worldf);

Using this code, my text doesn’t show up at all.

EDIT: Not sure if it’s relevant, but I’m using OpenGL 2.0 on OS X Snow Leopard.

  • 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-26T02:58:07+00:00Added an answer on May 26, 2026 at 2:58 am

    I’m using a left-handed perspective matrix

    Stop doing that.

    Equally importantly, the output of the projection matrix (clip-space) is different for OpenGL and D3D. You can’t just take a D3D projection matrix, transpose it, and expect that GLSL will accept the output just fine.

    So again, look up gluPerspective and use that matrix.


    Per Nicol Bolas’ suggestion, I’m now using the matrix from gluPerspective, but I’m getting the same results.

    You’re likely also using a bunch of other left-handed matrices. Your model-to-camera matrix needs to be right-handed. Also, your vertex data needs to be right-handed as well. Alternatively, you can try to convert from left-handed space to right-handed, but I wouldn’t advise it unless you had no other choice.


    float f = 1.0f/tanf(fov/2.0f);
    

    fov is an angle in degrees. tanf takes an angle in radians. The tanf of 30.0f is a negative number, which means your frustum scale in your perspective matrix is negative. That effectively inverts the X and Y axes of your view.

    What you really need is this:

    float f = 1.0f/tanf((fov * 6.2831f / 360.0f ) / 2.0f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.