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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:12:15+00:00 2026-05-26T17:12:15+00:00

When I try to use my orthographic projection, I’m not getting the result I’m

  • 0

When I try to use my orthographic projection, I’m not getting the result I’m looking for.
I have a VBO containing the following 2D vertices and texcoords (every other line):

0, 0,
0.0, 0.0,
512, 0,
1.0, 0.0,
512, 512,
1.0, 1.0,
0, 512,
0.0, 1.0

At the moment, I draw them using glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
There doesn’t seem to be any problem with the VBO (I’ve checked it in gDEBugger), instead the problem seems to lie in the vertex shader.

This is the offending shader:

#version 420

uniform mat4 projection;
uniform mat4 modelview;

layout(location = 0) in vec2 vertex;
layout(location = 1) in vec2 texcoord;

out vec2 f_texcoord;

void main() {
    const float right = 800.0;
    const float bottom = 600.0;
    const float left = 0.0;
    const float top = 0.0;
    const float far = 1.0;
    const float near = -1.0;

    mat4 testmat = mat4(
        vec4(2.0 / (right - left), 0, 0, -(right + left) / (right - left)),
                    vec4(0, 2.0 / (top - bottom), 0, -(top + bottom) / (top - bottom)),
                    vec4(0, 0, -2.0 / (far - near), -(far + near) / (far - near)),
                    vec4(0, 0, 0, 1)
    );
    gl_Position = testmat * vec4(vertex, 0.0, 1.0);
    f_texcoord = texcoord;
}

I’m not overly familiar with transformation matrices so I’m learning right now, and from what I have read the matrix above is correct if I want orthographic projection, which makes me very confused as I can’t get it to work.

Here is an image to illustrate the problem: (Note that the texture has transparent parts.)

image

EDIT:
This is how it looks with the modified values:

image

  • 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-26T17:12:16+00:00Added an answer on May 26, 2026 at 5:12 pm

    Matrices in GLSL are column major. The first vec4 should be the first column, not the first row. The last coordinate should be zero.

    mat4 testmat = mat4(
        vec4(2.0 / (right - left), 0, 0, 0,
        vec4(0, 2.0 / (top - bottom), 0, 0),
        vec4(0, 0, -2.0 / (far - near), 0),
        vec4(-(right + left) / (right - left), -(top + bottom) / (top - bottom), -(far + near) / (far - near), 1)
    );
    

    This uses the standard OpenGL glOrtho transform. The origin will be at the bottom-left, with +X going right and +Y going up. That’s standard for OpenGL.

    If you want a top-left origin, with +Y going down, you’ll have to adjust the matrix accordingly.

    My code for doing so is as follows:

    Translate(-1.0f, 1.0f, (depthRange.x + depthRange.y) / 2.0f);
    Scale(2.0f / size.x, -2.0f / size.y, 1.0f);
    

    Where depthRange.x/y are the zNear/zFar values. size.x/y is the width/height of the window. Translate creates a translation matrix, and Scale creates a scale matrix (they are right-multiplied with each other).

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

Sidebar

Related Questions

i try to use TBXML and getting this error TBXML class method +tbXMLWithURL not
I try use string as a regular expression pattern but I've following errors PHP
i try to use jquery .text() but not really work : Before <a id=group_name
When i try use a webservice i get the following exception. My main question
I have a problem with Automapper when I try use custom resolver which uses
Hi i try use Nlog in with caliburn micro, I have use this tutorial
I have gotten some reports from users of crashes when try use my application
I need tree file at my asp.net site. For getting icons I try use
I have problems with PHP in Ubuntu 10.04. When I try use mysqli_result::fetch_all this
I try use a integer array in java with the code below: public static

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.