I've been trying my best on porting my 3D game from Java to C++, but to no avail. I use only LWJGL with OpenGL but I cannot find any other library in C++ that supports as much as LWJGL does for Java. Especially on the math part.

For instance. I'm trying to port this TransformationMatrix maker to C++.

public static Matrix4f createTransformMatrix(Vector3f translation, float rx, float ry, float rz, float scale){

    Matrix4f newMatrix = new Matrix4f();
    Matrix4f.translate(translation, newMatrix, newMatrix);
    Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), newMatrix, newMatrix);
    Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), newMatrix, newMatrix);
    Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), newMatrix, newMatrix);
    Matrix4f.scale(new Vector3f(scale,scale,scale), newMatrix, newMatrix);

    return newMatrix;

I've tried using Eigen and GLM, but none of them work the same like LWJGL. Now I wouldn't mind this, but the lack of actual 3D tutorials on OpenGL in C++ is just abysmal.

Any tips or help with even converting this piece of code would be greatly appreciated.

  • \$\begingroup\$ Of course, it is not exactly the same as in java. glm is actually really simple, mutiplication is just mat1 * mat2, in java you had to do something like mat1.multiply(mat2) or something. opengl-tutorial.org is a good modern opengl tutorial. \$\endgroup\$
    – tkausl
    Feb 20, 2016 at 14:56

1 Answer 1


You should check out this site: http://learnopengl.com/ That is how i transitioned from LWJGL to C++ You just use GLEW for the OpenGL functions, GLFW as windowing system and GLM as math library which is awesome. Any chance you started out with ThinMatrix's tutorials? That code looks familiar.

I'm also using Microsoft Visual Studio Community Edition as editor btw (its free).

As for your function, this code should work:

glm::mat4 transformationMatrix;

transformationMatrix = glm::translate(transformationMatrix, entity.getPosition());
transformationMatrix = glm::rotate(transformationMatrix, glm::radians(entity.getRotation().x), 
            glm::vec3(1.0f, 0.0f, 0.0f));
transformationMatrix = glm::rotate(transformationMatrix, glm::radians(entity.getRotation().y),
            glm::vec3(0.0f, 1.0f, 0.0f));
transformationMatrix = glm::rotate(transformationMatrix, glm::radians(entity.getRotation().z),
            glm::vec3(0.0f, 0.0f, 1.0f));
transformationMatrix = glm::scale(transformationMatrix, entity.getScale());


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .