3D Engine does not render model

Hello guys,

I am new to these forums, but not that entirely new to openGL. I am working on a 3D engine in java, following some tutorials, but also trying different stuff out. After refactoring my engine, however, I am unable to display any models in the scene. In fact what I get is the background color I set in a uniform in my fragment shader.

Main area of refactoring:
[li]I switched from using lwjgl classes for Matrix4f and Vertex3f and 2f to using my own classes.
[/li][li]I also added the Quaternion class and changed the way rotation is calculated.
[/li][li]due to points 1 and 2 I also had to modify the generation of transofrmation matrix, viewMatrix and projectionMatrix.

I set up a small test to check if it works and lo and behold it does not. The test initializes a model.
[li]Then I create a player object (which is controlled with wsad keys).
[/li][li]Then I create the camera object (which is ocntrolled by mouse and arrow keys).
[/li][li]Then I add the light.
[/li][li]Next I set up a renderer class and enter the main loop.
[/li][li]There I gather information about input
[/li][li]Update camera and player
[/li][li]Render player
[/li][li]Update display

Here is the test file with the main methods responsible for the logic. I would really appreciate any feedback.
The project can be also found here: https://github.com/TomaszNaglik/Another-attempt

public class MainGameLoop {
	public static void main(String[] args) {
		Loader loader = new Loader();

		Vector3f standardScale = new Vector3f(1, 1, 1);
		Quaternion standardRotation = new Quaternion(0, 0, 0, 1);

		TexturedModel dragonModel = new TexturedModel(OBJFileLoader.loadOBJ("dragon", loader),
				new ModelTexture(loader.loadTexture("white")));

		Player player = new Player(dragonModel, new Vector3f(0, 0, -20), standardRotation, standardScale); 	// problem could be here
		Camera camera = new Camera(new Vector3f(0, 0, 0), standardRotation, standardScale); 				// problem could be here

		Light light = new Light(new Vector3f(0, 2000000, 20), new Vector3f(1, 1, 1)); 						// problem could be here

		MasterRenderer renderer = new MasterRenderer(); // problem could be here

		while (DisplayManager.notClose() && !Input.GetKey(Input.KEY_Q)) {



			renderer.render(light, camera);

			// renderer.checkError();
public MasterRenderer() {
		this.renderer = new EntityRenderer(shader, projectionMatrix);
		this.terrainRenderer = new TerrainRenderer(terrainShader, projectionMatrix);


public void render(Light sun, Camera camera) {

		shader.loadSkyColour(new Vector3f(RED, GREEN, BLUE));
		shader.loadFogVariables(density, gradient);

		terrainShader.loadSkyColour(new Vector3f(RED, GREEN, BLUE));
		terrainShader.loadFogVariables(density, gradient);

private void createProjectionMatrix() {
		float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
		projectionMatrix = Maths.createPerspectiveMatrix(FOV, aspectRatio, NEAR_PLANE, FAR_PLANE);


public static Matrix4f createPerspectiveMatrix(float fov, float aspectRatio, float zNear, float zFar) {
		return new Matrix4f().InitPerspective(fov, aspectRatio, zNear, zFar);
public Matrix4f InitPerspective(float fov, float aspectRatio, float zNear, float zFar) {
		float tanHalfFOV = (float) Math.tan(fov / 2);
		float zRange = zNear - zFar;

		m[0][0] = 1.0f / (tanHalfFOV * aspectRatio);
		m[0][1] = 0;
		m[0][2] = 0;
		m[0][3] = 0;
		m[1][0] = 0;
		m[1][1] = 1.0f / tanHalfFOV;
		m[1][2] = 0;
		m[1][3] = 0;
		m[2][0] = 0;
		m[2][1] = 0;
		m[2][2] = (-zNear - zFar) / zRange;
		m[2][3] = 2 * zFar * zNear / zRange;
		m[3][0] = 0;
		m[3][1] = 0;
		m[3][2] = 1;
		m[3][3] = 0;

		return this;
public void loadViewMatrix(Camera camera) {
		Matrix4f viewMatrix = Maths.createViewMatrix(camera);
		super.loadMatrix(location_viewMatrix, viewMatrix);
public static Matrix4f createViewMatrix(Camera camera)
		Matrix4f viewMatrix = new Matrix4f();
		Matrix4f cameraRotation = camera.getTransform().GetTransformedRot().Conjugate().ToRotationMatrix();
		Vector3f cameraPos = camera.getTransform().GetTransformedPos().Mul(-1);

		Matrix4f cameraTranslation = new Matrix4f().InitTranslation(cameraPos);

		return viewMatrix.Mul(cameraRotation.Mul(cameraTranslation));

I would really appreciate any insight.

What is odd, is the fact that when I run the program and print out the state of every initialized object, all initializations are correct.

From your descriptions its save to assume that your matrix and vector implementations are just wrong. If it worked with the other version but doesnt with yours then you made a mistake somewhere. Instead of going through your code and doing your debugging work for you I would rather ask: Why do you try to roll your own version of matrix math? If the official versions worked, then why would you need to do it all again?

Well, the framework that I was using used three variables for rotation (yaw, pitch and roll). I found out that if I want to have freedom of movement in all directions this solution is not optimal (I would get strange effects where when the camera is pointing down and I roll, I actually yaw, because the the local grid system is always the same as the world grid system).

I wanted to implement quaternions to be able to have a seperate local coordinate system for the camera. The matrix calculations used are from a different framework. Plus when I compared both calculation versions, they seem to do the same thing (although one is working with yaw pitch variables and the other with quaternions).

What kind of Matrix package from LWJGL are you using? It sounds like you are not using the JOML packages as they definitely have support for quaternions. This is the current official matrix package to be used with LWJGL, it is tested and very efficient. Could it be that you are still using the old LWJGL2 packages?

By the way, the problem you were having is called Gimbal Lock. Link: https://en.wikipedia.org/wiki/Gimbal_lock

I used the Matrix4f class written by BennyBox for his tutorials, which works well for him, but I get your point. I could use the JOML package instead. I am using LWJGL 3 by the way.

I switched to JMOL and can now actually see the dragon, although it is flickering all over the place. I must have screwed up something in the process then. It is still an improvment. Thanks.