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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:38:39+00:00 2026-05-23T07:38:39+00:00

I am implementing an application in opengl es2.0. I need to use pushmatrix() and

  • 0

I am implementing an application in opengl es2.0. I need to use pushmatrix() and popmatrix(). We all know that this function is no more available in opengl es 2.0. I have tried to follow and implement the method given here. However I ddnt find too much success. Also we need to implement some huge number of header files for the same. Has anybody implemented this as a part of their project? If possible, can someone post some code snippet which will guide me to save and restore states of current matrices?

  • 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-23T07:38:39+00:00Added an answer on May 23, 2026 at 7:38 am

    Say you have a simple linmath library, like this:

    typedef GLfloat vec4[4];
    inline void vec4_add(vec4 a, vec4 b)
    {
        int i;
        for(i=0; i<4; ++i)
            a[i] += b[i];
    }
    inline void vec4_sub(vec4 a, vec4 b)
    {
        int i;
        for(i=0; i<4; ++i)
            a[i] -= b[i];
    }
    inline void vec4_scale(vec4 v, GLfloat s)
    {
        int i;
        for(i=0; i<4; ++i)
            v[i] *= s;
    }
    inline GLfloat vec4_inner_product(vec4 a, vec4 b)
    {
        GLfloat p = 0.;
        int i;
        for(i=0; i<4; ++i)
            p += b[i]*a[i];
        return p;
    }
    inline GLfloat vec4_length(vec4 v)
    {
        return sqrtf(vec4_inner_product(v,v));
    }
    inline void vec4_normalize(vec4 v)
    {
        GLfloat k = 1.0 / vec4_length(v);
        vec4_scale(v, k);
    }
    inline void vec4_cross(vec4 a, vec4 b)
    {
        vec4 c;
        c[0] = a[1]*b[2] - a[2]*b[1];
        c[1] = a[2]*b[0] - a[0]*b[2];
        c[2] = a[0]*b[1] - a[1]*b[0];
        c[3] = 0.;
        memcpy(a, c, sizeof(a));
    }
    
    typedef vec4 mat4x4[4];
    inline void mat4x4_identity(mat4x4 M)
    {
        int i, j;
        M[0][0] = 1; M[1][0] = 0; M[2][0] = 0; M[3][0] = 0;
        M[0][1] = 0; M[1][1] = 1; M[2][1] = 0; M[3][1] = 0;
        M[0][2] = 0; M[1][2] = 0; M[2][2] = 1; M[3][2] = 0;
        M[0][3] = 0; M[1][3] = 0; M[2][3] = 0; M[3][3] = 1;
        /*for(j=0; j<4; ++j)
            for(i=0; i<4; ++i) {
                M[i][j] = i==j ? 1 : 0;
        }*/
    }
    inline void mat4x4_cpy(mat4x4 M, mat4x4 N)
    {
        int i, j;
        for(j=0; j<4; ++j) {
            for(i=0; i<4; ++i) {
                M[i][j] = N[i][j];
            }
        }
    }
    inline void mat4x4_mul(mat4x4 M, mat4x4 b)
    {
        mat4x4 a;
        int i, j, k;
        memcpy(a, M, sizeof(a));
        for(j=0; j<4; ++j) {
            for(i=0; i<4; ++i) {
                M[i][j] = 0;
                for(k=0; k<4; ++k) {
                    M[i][j] += a[i][k]*b[k][j];
                }
            }
        }
    }
    inline void mat4x4_trans(mat4x4 M, GLfloat x, GLfloat y, GLfloat z)
    {
        mat4x4 T; mat4x4_identity(T);
        T[3][0] = x;
        T[3][1] = y;
        T[3][2] = z;
        mat4x4_mul(M, T);
    }
    inline void mat4x4_rot_X(mat4x4 M, GLfloat angle)
    {
        GLfloat s = sinf(angle);
        GLfloat c = cosf(angle);
        mat4x4 R = {
            {1, 0, 0, 0},
            {0, c, s, 0},
            {0,-s, c, 0},
            {0, 0, 0, 1}
        };
        mat4x4_mul(M, R);
    }
    inline void mat4x4_rot_Y(mat4x4 M, GLfloat angle)
    {
        GLfloat s = sinf(angle);
        GLfloat c = cosf(angle);
        mat4x4 R = {
            {c, 0, s, 0},
            {0, 1, 0, 0},
            {-s, 0, c, 0},
            {0, 0, 0, 1}
        };
        mat4x4_mul(M, R);
    }
    inline void mat4x4_rot_Z(mat4x4 M, GLfloat angle)
    {
        GLfloat s = sinf(angle);
        GLfloat c = cosf(angle);
        mat4x4 R = {
            {c, s, 0, 0},
            {-s, c, 0, 0},
            {0, 0, 1, 0},
            {0, 0, 0, 1}
        };
        mat4x4_mul(M, R);
    }
    inline void mat4x4_row(vec4 r, mat4x4 M, int i)
    {
        int k;
        for(k=0; k<4; ++k)
            r[k] = M[k][i];
    }
    inline void mat4x4_col(vec4 r, mat4x4 M, int i)
    {
        int k;
        for(k=0; k<4; ++k)
            r[k] = M[i][k];
    }
    inline void mat4x4_cpy_T(mat4x4 M, mat4x4 N)
    {
        int i, j;
        for(j=0; j<4; ++j) {
            for(i=0; i<4; ++i) {
                M[i][j] = N[j][i];
            }
        }
    }
    

    Instead of pushing a matrix, you simply create a copy and continue work on and use that one. Poping then turns into deallocating the copy and switch back to the matrix you made the copy of.

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

Sidebar

Related Questions

I am implementing an iPhone application. In that I need to use a timer
I'm implementing this application where i need to pause it when the back key
I am implementing an application. In that I need to find out a way
I am implementing an application that launches iTunes from a 'music page'. This is
I need to run an application in an embedded system continuously. While implementing this
I need a help from you, That is I am implementing an application in
I'm implementing my own matrix math for an OpenGL application. So far, things are
Ok...... I'm implementing a simple OpenGL ES application on the iPhone and I recently
We are implementing an application with a webservice as component and decided to use
I am currently implementing the application that displays hierarchy using ListBoxes (please do not

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.