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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:24:07+00:00 2026-05-24T23:24:07+00:00

Im trying to implement my own glOtho function from the opengles docs http://www.khronos.org/opengles/documentation/opengles1_0/html/glOrtho.html to

  • 0

Im trying to implement my own glOtho function from the opengles docs http://www.khronos.org/opengles/documentation/opengles1_0/html/glOrtho.html
to modify a Projection matrix in my vertex shader. It’s currently not working properly as I see my simple triangles vertices out of place. Can you please check the code below and see if i’m doing things wrong.

I’ve tried setting tx,ty and tz to 0 and that seems to make it render properly. Any ideas why would this be so?

void ES2Renderer::_applyOrtho(float left, float right,float bottom, float top,float near, float far) const{ 

        float a = 2.0f / (right - left);
        float b = 2.0f / (top - bottom);
        float c = -2.0f / (far - near);

        float tx = - (right + left)/(right - left);
        float ty = - (top + bottom)/(top - bottom);
        float tz = - (far + near)/(far - near);

        float ortho[16] = {
            a, 0, 0, tx,
            0, b, 0, ty,
            0, 0, c, tz,
            0, 0, 0, 1
        };


        GLint projectionUniform = glGetUniformLocation(_shaderProgram, "Projection");
        glUniformMatrix4fv(projectionUniform, 1, 0, &ortho[0]);

}

void ES2Renderer::_renderScene()const{
    GLfloat vVertices[] = {
        0.0f,  5.0f, 0.0f,  
        -5.0f, -5.0f, 0.0f,
        5.0f, -5.0f,  0.0f};

    GLuint positionAttribute = glGetAttribLocation(_shaderProgram, "Position");

    glEnableVertexAttribArray(positionAttribute);


    glVertexAttribPointer(positionAttribute, 3, GL_FLOAT, GL_FALSE, 0, vVertices);  
    glDrawArrays(GL_TRIANGLES, 0, 3);       


    glDisableVertexAttribArray(positionAttribute);

}

Vert shader

attribute vec4 Position;
uniform mat4 Projection;
void main(void){
    gl_Position = Projection*Position;
}

Solution
From Nicols answer below I modifed my matrix as so and it seemed render properly

float ortho[16] = {
    a, 0, 0, 0,
    0, b, 0, 0,
    0, 0, c, 0,
    tx, ty, tz, 1
};

Important note
You cannot use GL_TRUE for transpose argument for glUniform as below. opengles does not support it. it must be GL_FALSE

glUniformMatrix4fv(projectionUniform, 1, GL_TRUE, &ortho[0]);

From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml

transpose
Specifies whether to transpose the matrix as the values are loaded into the uniform variable. Must be GL_FALSE.

  • 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-24T23:24:08+00:00Added an answer on May 24, 2026 at 11:24 pm

    Matrices in OpenGL are column major. Unless you pass GL_TRUE as the third parameter to glUniformMatrix4fv, the matrix will effectively be transposed relative to what you would intend.

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

Sidebar

Related Questions

I'm trying to implement my own autocomplemention system (result is pull from an sqlite
I'm trying to implement my own serialization / var_dump style function in PHP. It
I am trying to implement my own File class, which extends from the java.io.File
I'm trying to implement my own List system in Java. the List class file
I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
I am trying to implement my own authentication method for AuthKit and am trying
I'm trying to implement my own version of the 'cd' command that presents the
For all those ligthning fast shop users. I'm trying to implement my own first
Am trying to implement a generic way for reading sections from a config file.
Im trying to implement my own Huffman Coding algorithm and the priority queue for

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.