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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:11:17+00:00 2026-05-29T15:11:17+00:00

I have a small open GL application I’m writing in Java using JOGL. I’m

  • 0

I have a small open GL application I’m writing in Java using JOGL.

I’m bashing my head against the wall trying to find the CURRENT way of applying transformations

Essentially what I’m trying to accomplish is to have two objects next to each other. Basically I create objects (methods that calculate all the triangles – i know this is working because both objects show up, they’re just overlapping each other), then in display I put them in VBO and call drawElements. My issue is that I can’t see to find any examples or tutorials online that DON’T use glTranslatef, glRotatef, and glScalef, which I’ve been informed is outdated and used to be part of the fixed function aspect of old open GL.

EDIT: (previous code removed)

Epic fail on my behalf. When he said his shader code, i thought he meant the .java file that loads and compiles the shader. It just hit me that he meant the SHADER CODE, which was in a glsl file. I see now where he has 3 mat4 variables which hold rx, ry, and rz. Weird thing is that even if I SET UP a scale and translate matrix, my shapes no longer appear. The rotation matrices are set up as one would assume, and the last line is “glPosition = rz * ry * rx * vPosition;” I tried declaring translation and scale matrices as well and then doing “= s * t * rz * ry * rx * vPosition”, but no dice.

Here is the current shader code:

attribute vec4 vPosition;
uniform vec3 theta;
uniform vec3 trans;
uniform vec3 scale;

void main()
{
// Compute the sines and cosines of each rotation
// about each axis
vec3 angles = radians (theta);
vec3 c = cos (angles);
vec3 s = sin (angles);

// rotation matricies
mat4 rx = mat4 (1.0,  0.0,  0.0,  0.0, 
                0.0,  c.x,  s.x,  0.0,
                0.0, -s.x,  c.x,  0.0,
                0.0,  0.0,  0.0,  1.0);

mat4 ry = mat4 (c.y,  0.0, -s.y,  0.0, 
                0.0,  1.0,  0.0,  0.0,
                s.y,  0.0,  c.y,  0.0,
                0.0,  0.0,  0.0,  1.0);

mat4 rz = mat4 (c.z, -s.z,  0.0,  0.0, 
                s.z,  c.z,  0.0,  0.0,
                0.0,  0.0,  1.0,  0.0,
                0.0,  0.0,  0.0,  1.0);

//mat4 t = mat4 (1.0, 0.0, 0.0, trans.x, 
//               0.0, 1.0, 0.0, trans.y,
//               0.0, 0.0, 1.0, trans.z,
//               0.0, 0.0, 0.0, 1.0);

//mat4 s = mat4 (scale.x, 0.0, 0.0, 0.0, 
//               0.0, scale.y, 0.0, 0.0,
//               0.0, 0.0, scale.z, 0.0,
//               0.0, 0.0, 0.0, 1.0);

gl_Position = rz * ry * rx * vPosition;
//gl_Position = s * t * rz * ry * rx * vPosition;
}

So essentially, if I uncomment the bottom two matrices, but leave the glPosition statement the same, nothing appears. Also the commented out glPosition statement didn’t work (though I’m not surprised, I’m not too great at matrix multiplication). I also tried doing just s * vPosition just to try and only scale, but again nothing is visible.

  • 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-29T15:11:18+00:00Added an answer on May 29, 2026 at 3:11 pm

    Between datenwolf’s link and a few other resources I found, I was able to write a (rather barebones) column-major order matrix class for use in my assignment. I’m posting the source here in case any one else finds it useful.

    import java.nio.FloatBuffer;

    public class CGMatrix {
    
    public CGMatrix() {
    }
    
    public static float[][] identity() {
        return new float[][]{{1.0f, 0, 0, 0}, 
                {0, 1.0f, 0, 0},
                {0, 0, 1.0f, 0},
                {0, 0, 0, 1.0f}};
    }
    
    public static float[][] rotateX(float angle) {
        double r = angle * (Math.PI / 180);
        float s = (float)Math.sin(r);
        float c = (float)Math.cos(r);
        return new float[][] {{1, 0, 0, 0},
                            {0, c, s, 0},
                            {0, -s, c, 0},
                            {0, 0, 0, 1}};
    }
    
    public static float[][] rotateY(float angle) {
        double r = angle * (Math.PI / 180);
        float s = (float)Math.sin(r);
        float c = (float)Math.cos(r);
        return new float[][] {{c, 0, s, 0},
                            {0, 1, 0, 0},
                            {-s, 0, c, 0},
                            {0, 0, 0, 1}};
    }
    
    public static float[][] rotateZ(float angle) {
        double r = angle * (Math.PI / 180);
        float s = (float)Math.sin(r);
        float c = (float)Math.cos(r);
        return new float[][] {{c, s, 0, 0},
                            {-s, c, 0, 0},
                            {0, 0, 1, 0},
                            {0, 0, 0, 1}};
    }
    
    public static float[][] scale(float sx, float sy, float sz) {
        float[][] m = identity();
        m[0][0] *= sx;
        m[1][1] *= sy;
        m[2][2] *= sz;
        return m;
    }
    
    public static float[][] translate(float tx, float ty, float tz) {
        float[][] m = identity();
        m[3][0] = tx;
        m[3][1] = ty;
        m[3][2] = tz;
        return m;
    }
    
    public static float[][] multiply(float [][] a, float[][] b) {
        float[][] m = identity();
        for(int j = 0; j < 4; ++j){
            for(int i = 0; i < 4; ++i) {
                m[i][j] = 0;
                for(int k = 0; k < 4; ++k) {
                    m[i][j] += a[i][k]*b[k][j];
                }
            }
        }
        return m;
    }
    
    public static FloatBuffer buffer(float[][] m) {
        float[] n = new float[16];
        int k = 0;
        for(int j = 0; j < 4; ++j) {
            for(int i = 0; i < 4; ++i) {
                n[k] = m[j][i];
                k++;
            }
        }
        return FloatBuffer.wrap(n);
    
    }
    
    }
    

    So in my case I set up individual matrices for translation, scale, and rotations.

    so if, for example, I wanted to translate along z, then rotate along y, then scale, I could do:

        cgMatrix = gl2.glGetUniformLocation(shaderProgID, "cgMatrix");
        float[][] t = CGMatrix.translate(0, 0, 0.5f);
        float[][] s = CGMatrix.scale(1, 0.75f, 1);
        FloatBuffer m = CGMatrix.buffer(CGMatrix.multiply(t, CGMatrix.multiply(ry, s)));
        gl2.glUniformMatrix4fv(cgMatrix, 1, false, m);
    

    Where the transformations happen left to right (i.e. first it’s translated, then rotated, then scaled)

    Anyway, I hope that can be helpful to anyone else!

    Thanks for all the responses.

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

Sidebar

Related Questions

I have a small application to open the door using a relay controller. I
I have several small open-source projects that I wrote. All my attempts to find
We have a small application we built in our spare time using the latest
i have develop a small mvc3 application using Telerik Extension for asp.net mvc3 in
I've build a small java application that uses selenium 2 to open a web
I'm writing a small client application to communicate with a server. I open a
I have this small code library that I'm considering releasing into Open Source. I
I have small problem with my .net 2.0 winforms application. I want to embed
I have small database of business and their addresses. Using the Google Geocode API
I have small web app that generate PDF files as a report. I'm trying

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.