Hot questions for Using Lightweight Java Game Library in graphics

Question:

I am currently writing a small program using LWJGL to generate a low poly scene. I first rendered a house. Then I rendered the terrain. Lastly, I rendered the water. The water was originally a flat plane of vertices. I did some displacements in the vertex shader using the Perlin noise algorithm to generate some waves(i.e. I can't obtain the actual water level at a particular point). When I rendered the scene, I observed some serrated edges.

The situation is even worse when viewing from a larger distance.

What are they? How can I remove them? Sorry that I can't upload the code. Because the number of lines are too large.

Edit 1:

private float FOV = 70;
private float NEAR_PLANE = .1f;
private float FAR_PLANE = 1000f;

private void createProjectionMatrix() {

    float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
    float y_scale = (float) ( (1f/ Math.tan(FOV/2f))*aspectRatio );
    float x_scale = y_scale / aspectRatio;
    float frustum_length = FAR_PLANE - NEAR_PLANE;

    projectionMatrix = new Matrix4f();
    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2*NEAR_PLANE * FAR_PLANE) / frustum_length);
    projectionMatrix.m33 = 0;

}

Answer:

the problem is due to Z-buffer stored Z values of your fragments has low precision. Look at your values:

private float NEAR_PLANE = .1f;
private float FAR_PLANE = 1000f;

so visible depth range is z = < 0.1 , 1000.0 > this is normalized to < 0.0 , 1.0> range. Now if your pixelformat uses only 16 bit Z-buffer then (assuming linear Z-buffer which is not the case) you got precision ~(1000.0/0.1)/2^16 = 0.6 which is smallest possible Z-step. Now if you take into account that the Z-buffer values are mapped non linearly then the more far away from your Z_Near the precision will be even less.

To improve this you can:

  1. change pixelformat to 32bits for Depth buffer if supported by gfx
  2. lower Zfar/Znear ratio

    Znear is more significant (due to non linear Z values). The closer to the zero it is the worse this thing gets. If you are rendering objects with resolution in meters then there is no point to have z_near < 1.0

  3. stack up more frustrums

    In case you need to cover very high dynamic range you can render the scene in more then one pass. For more info see

    • Is it possible to make realistic n-body solar system simulation in matter of size and mass?

    Especially the bullet #1

  4. Use linear Z-buffer

    This can be done with shaders getting rid of the non linearity.

Question:

When I make a simple window it gives me an error and I have no idea why! I am on Linux Mint 64 bit. (Dell Inspiron 1764)

Here's the error:

org.lwjgl.LWJGLException: X Error - disp: 0x7f81187c9a20 serial: 93 error: GLXBadFBConfig request_code: 156 minor_code: 34
at org.lwjgl.opengl.LinuxDisplay.globalErrorHandler(LinuxDisplay.java:321)
at org.lwjgl.opengl.LinuxContextImplementation.nCreate(Native Method)
at org.lwjgl.opengl.LinuxContextImplementation.create(LinuxContextImplementation.java:51)
at org.lwjgl.opengl.ContextGL.<init>(ContextGL.java:132)
at org.lwjgl.opengl.Display.create(Display.java:850)
at org.lwjgl.opengl.Display.create(Display.java:797)
at renderEngine.DisplayManager.createDisplay(DisplayManager.java:27)
at engineTester.MainGameLoop.main(MainGameLoop.java:10)

Exception in thread "main" java.lang.IllegalStateException: Cannot determine close requested state of uncreated window
at org.lwjgl.opengl.Display.isCloseRequested(Display.java:549)
at engineTester.MainGameLoop.main(MainGameLoop.java:14)

Here's my code:

package engineTester;

import org.lwjgl.opengl.Display;

import renderEngine.DisplayManager;

public class MainGameLoop {

public static void main(String[] args) {
    DisplayManager.createDisplay();

        while(!Display.isCloseRequested()) {
            //game logic
            //render
            DisplayManager.updateDisplay();
        }

        DisplayManager.closeDisplay();
    }

}

And then the other class is:

package renderEngine;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;  
import org.lwjgl.test.applet.OpenGL;

public class DisplayManager {

private static final int WIDTH = 1000;

private static final int HEIGHT = 700;

private static final int FPS_CAP = 120;

public static void createDisplay() {

    ContextAttribs attribs = new ContextAttribs(3,2);
        attribs.withForwardCompatible(true);
        attribs.withProfileCore(true);

        try {
            Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
            Display.create(new PixelFormat(), attribs);
            OpenGL opengl = new OpenGL();
            GL11.glViewport(0, 0, WIDTH, HEIGHT);
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
    }

    public static void updateDisplay() {
        Display.sync(FPS_CAP);
        Display.update();
    }

    public static void closeDisplay() {

        Display.destroy();

    }

}

Answer:

After much work at this, I finally decided to read Minecraft's source code and see how they created their OpenGL window. I put it in my code, and now the window opens perfectly!

To get it working if you have the problem, replace

Display.create(new PixelFormat(), attribs);

with

Display.create(new PixelFormat().withDepthBits(24));

Question:

I've been wondering if there's a class in LWJGL 3 similar to JComponent that I can import and use for a game character. I know that Blender models can be imported easily, but I'm wondering if there's a way for an class to extend some overarching LWJGL class, overriding some method in order to display as a 3D object (in the same way a class might extend JComponent and override paintComponent(Graphics)). LWJGL 3 doesn't yet support Swing/AWT, so I can't use actual JComponents like I used to. Thanks for the help!


Answer:

No. LWJGL is GLFW(for opening windows), OpenGL(for using the graphics card) and OpenAL(for sound) for Java. You'll have to learn OpenGL and write some GLSL shaders to get anything drawn.

Question:

I'm just beginning with OpenGL and LWJGL, but I have experience in Java and game development. My game I'm making is going to be a 2D Pixel Art Platformer, with most sprites being 16x16px.

I want to scale all the graphics being rendered up by 3. In regular Java, you would draw all the pixels to a BufferedImage, and then draw that image by doing something like this:

g.drawImage(image, 0, 0, WIDTH * SCALE, HEIGHT * SCALE, null);

I'm trying to do the same with glScalef(), but it makes the images blurry, can I fix that or is there a better way to do it? Here's my code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glScalef(SCALE, SCALE, SCALE);

Please let me know of any other information I may need to provide.

Thanks!


Answer:

Sounds like the texture is being filtered. This answer to a similar question changes the default value of GL_TEXTURE_MAG_FILTER from GL_LINEAR to GL_NEAREST with the following snippet:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

Question:

I'm starting work on a simple shape-batching system for my 3D engine that will enable me to draw lines and rectangles, etc... with a lower draw call count. I think I've got the basic ideas figured out for the most part, but I'm having problems when I try to draw multiple objects (currently just lines with a thickness you can specify).

Here's a screenshot to show you what I mean:

I'm using indexed rendering with glDrawElements, and two VBOs to represent the vertex data - one for positions, and one for colours. I construct a line for my shape-batcher by specifying start and end points, like so:

    shapeRenderer.begin();
    shapeRenderer.setViewMatrix(viewMatrix);
    shapeRenderer.setProjectionMatrix(projectionMatrix);

    shapeRenderer.setCurrentColour(0, 1f, 0);
    shapeRenderer.drawLine(2, 2, 5, 2);

    shapeRenderer.setCurrentColour(0, 1f, 1f);
    shapeRenderer.drawLine(2, 5, 5, 5);
    shapeRenderer.end();

The first line, represented in green in the screenshot, shows perfectly. If I draw only one line it's completely fine. If I were to draw only the second line it would show perfectly as well.

When I call drawLine the following code executes, which I use to compute directions and normals:

private Vector2f temp2fA = new Vector2f();
private Vector2f temp2fB = new Vector2f();
private Vector2f temp2fDir = new Vector2f();
private Vector2f temp2fNrm = new Vector2f();
private Vector2f temp2fTMP = new Vector2f();
private boolean flip = false;

public void drawLine(float xStart, float yStart, float xEnd, float yEnd){
    resetLineStates();

    temp2fA.set(xStart, yStart);
    temp2fB.set(xEnd, yEnd);

    v2fDirection(temp2fA, temp2fB, temp2fDir);
    v2fNormal(temp2fDir, temp2fNrm);

    float halfThickness = currentLineThickness / 2;

    //System.out.println("new line called");

    v2fScaleAndAdd(temp2fB, temp2fNrm, -halfThickness, temp2fTMP);
    pushVertex(temp2fTMP);

    v2fScaleAndAdd(temp2fB, temp2fNrm, halfThickness, temp2fTMP);
    pushVertex(temp2fTMP);

    v2fScaleAndAdd(temp2fA, temp2fNrm, halfThickness, temp2fTMP);
    pushVertex(temp2fTMP);

    v2fScaleAndAdd(temp2fA, temp2fNrm, -halfThickness, temp2fTMP);
    pushVertex(temp2fTMP);

    //System.out.println(indexCount + " before rendering.");

    int index = indexCount;

    pushIndices(index, index + 1, index + 3);
    pushIndices(index + 1, index + 2, index + 3);


    //System.out.println(indexCount + " after rendering.");
}
private void resetLineStates(){
    temp2fA.set(0);
    temp2fB.set(0);
    temp2fDir.set(0);
    temp2fNrm.set(0);
    temp2fTMP.set(0);
}

pushIndices is the following function:

private void pushIndices(int i1, int i2, int i3){
    shapeIndices.add(i1);
    shapeIndices.add(i2);
    shapeIndices.add(i3);
    indexCount += 3;
}

And pushVertex works like so:

private void pushVertex(float x, float y, float z){
    shapeVertexData[vertexDataOffset] = x;
    shapeColourData[vertexDataOffset] = currentShapeColour.x;

    shapeVertexData[vertexDataOffset + 1] = y;
    shapeColourData[vertexDataOffset + 1] = currentShapeColour.y;

    shapeVertexData[vertexDataOffset + 2] = z;
    shapeColourData[vertexDataOffset + 2] = currentShapeColour.z;

    //System.out.println("\tpushed vertex: " + data.x + ", " + data.y + ", 0");

    vertexDataOffset += 3;
}

I'm using the following fields to store vertex data and such - this is all sub-buffered to a VBO when I flush the batch. If the vertex data arrays have not had to grow in size, I will sub-buffer them to their respective VBO, likewise with the element buffer, otherwise if they have had to grow then I re-buffer the VBO to fit.

private float[] shapeVertexData;
private float[] shapeColourData;
private int vertexDataOffset;

private ArrayList<Integer> shapeIndices;
private int indexCount;

When I use my debugger in IDEA, the vertex data appears completely correct in the arrays I'm constructing, but when I explore it in RenderDoc, it's wrong. I don't understand what I'm doing wrong to get these results, and obviously the first two vertices appear completely fine even for the second rectangle, but the others are totally wrong.

I'm confident that my shaders are not the problem, as they're very simple, but here they are: shape_render.vs (vertex shader):

#version 330

layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aColour;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;

flat out vec3 shapeFill;

void main(){
    shapeFill = aColour;
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPosition.x, aPosition.y, 0.0, 1.0);
}

shape_render.fs (fragment shader):

#version 330
layout (location = 0) out vec4 fragColour;

in vec3 shapeFill;

void main(){
    fragColour = vec4(shapeFill, 1);
}

I think I've just about explained it to the best of my knowledge, any insight would be greatly appreciated. I've already checked and determined I'm enabling the necessary vertex arrays, etc... and rendering the correct amount of indices (12):

Thanks so much for having a look at this for me.


Answer:

I figured it out after thinking about it for a while longer. It was to do with how I was specifying the indices. I was using the correct amount of indices however specifying them incorrectly. For arguments sake to construct a triangle, the first one would have an index count of 0, and with four vertices, the indices would be 1,2,3 and 2,3,1 (for example). However for each new triangle I was starting the index count at the old count plus six, which makes sense for addressing an array, but because each rectangle only specified four vertices, I was pointing indices at data that didn’t exist. So instead of using indexCount += 3 each time I pushed indices, I’ll get the current count of vertices instead and build my indices from that.

Question:

Hello I have been trying to figure out why this triangle will not draw! Here is my code. It is just basic LWJGL OpenGL code using VBO's and VAO's and i can not figure out why it is not drawing. I have confirmed that the shaders are compiling properly

//bindings available for use.
    GL.createCapabilities();

    // Set the clear color
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    float vertices[] = {
             0.0f,  0.5f, // Vertex 1 (X, Y)
             0.5f, -0.5f, // Vertex 2 (X, Y)
            -0.5f, -0.5f  // Vertex 3 (X, Y)
        };
    int vbo;
    vbo = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    FloatBuffer vboBuff = BufferUtils.createFloatBuffer(vertices.length);
    vboBuff.put(vertices);
    vboBuff.flip();
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vboBuff, GL15.GL_STATIC_DRAW);
    int vertShade = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertShade,Reader.read("shaders/main.frag"));
    glCompileShader(vertShade);
    int fragShade = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragShade,Reader.read("shaders/main.frag"));
    glCompileShader(fragShade);
    String failed = glGetShaderInfoLog(fragShade);
    System.err.println(failed);
    int shaderprogram = glCreateProgram();
    glAttachShader(shaderprogram,vertShade);
    glAttachShader(shaderprogram,fragShade);
    glLinkProgram(shaderprogram);
    glUseProgram(shaderprogram);
    int posAttrib = glGetAttribLocation(shaderprogram,"position");
    glVertexAttribPointer(posAttrib,2,GL_FLOAT,false,0,0);
    glEnableVertexAttribArray(posAttrib);
    int vao;
    vao = glGenVertexArrays();
    // Run the rendering loop until the user has attempted to close
    // the window or has pressed the ESCAPE key.
    while ( glfwWindowShouldClose(window) == GL_FALSE ) {;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
     GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);

        glfwSwapBuffers(window); // swap the color buffers

        // Poll for window events. The key callback above will only be
        // invoked during this call.
        glfwPollEvents();
    }

SHADERS:///THESE ARE IN SEPARATE FILES Fragment shader:

#version 150

out vec4 outColor;

void main()
{
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}

Vertex

#version 150

in vec2 position;

void main()
{
    gl_Position = vec4(position, 0.0, 1.0);
}

EDIT the last few lines before the while loop now look like this:

    int shaderprogram = glCreateProgram();
    glAttachShader(shaderprogram,vertShade);
    glAttachShader(shaderprogram,fragShade);
    glLinkProgram(shaderprogram);
    glUseProgram(shaderprogram);
    int vao;
    vao = glGenVertexArrays();
    glBindVertexArray(vbo);
    int posAttrib = glGetAttribLocation(shaderprogram,"position");
    glVertexAttribPointer(posAttrib,2,GL_FLOAT,false,0,0);
    glEnableVertexAttribArray(posAttrib);

Answer:

Looking at your own code should make the problem fairly obvious:

int vertShade = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertShade,Reader.read("shaders/main.frag"));
glCompileShader(vertShade);
int fragShade = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragShade,Reader.read("shaders/main.frag"));
glCompileShader(fragShade);

Since you use the same file name when reading both shaders, you're using the fragment shader code for the vertex shader, and never load the vertex shader code.

If you fix the file name, things should start to work much better. Make sure that you always check the compile and link status after building shaders during development. Then you will be able to recognize these types of issues quickly.

Question:

(Assignment related question)

I'm attempting to implement shadow mapping, by following this tutorial, however, I am having a kinda strange problem - all of the objects in my scene are getting the same shadow applied to them, like this: (The light is at -3, 5, -3 (Bottom Right))

What have I done wrong? I think it is going to be matrix related, but I have no idea how to fix it...

Creating the view matrix:

viewMatrix = new Matrix4f();
Matrix4f.rotate(MathHelpers.degreesToRadians(verticalRotation), new Vector3f(1f, 0f, 0f), viewMatrix, viewMatrix);
Matrix4f.rotate(MathHelpers.degreesToRadians(horizontalRotation), new Vector3f(0f, 1f, 0f), viewMatrix, viewMatrix);
Matrix4f.translate(position, viewMatrix, viewMatrix);
viewMatrix.store(cameraMatrix);
cameraMatrix.flip();

Sending the data to the GPU:

Mat4 proj2 = Matrices.perspective(90, 1, 3f, 20f);
Mat4 view2 = = MathHelpers.Matrix4fToMat4(lights.get(i).getViewMatrix());
Mat4 model2 = Mat4.MAT4_IDENTITY;
Mat4 mvp = MathHelpers.biasMVP(proj2, view2, model2);
FloatBuffer matBuffer = org.lwjgl.BufferUtils.createFloatBuffer(16);
MathHelpers.Mat4ToMatrix4f(mvp).store(matBuffer);
matBuffer.flip();

Depth shaders: http://pastebin.com/SqFaBnSE http://pastebin.com/t5t35XNM

Normal shaders: http://pastebin.com/yQhqyAWc http://pastebin.com/2C2sXByz


Answer:

When you sample the shadow map you should first transform the world position of the fragment (before you apply the camera transform and perspective matrix) to the

in the vertex shader this will be:

attribute vec3 pos;

uniform mat4 shadowTransform;//the MVP you used to create the shadowmap
uniform mat4 MVP;

varying vec4 shadowPos;//you can use the xy/w to sample the shadow map and compare against z/w

main(){
   gl_position = MVP*vec4(pos,1);
   shadowPos = shadowTransform*vec4(pos, 1);
}

Question:

Im coding a Game with lwjgl3. I initially used lwjgl 2. but of major chanllenges, i switched to lwjgl3.

I walked through a couple tutorials and put together a gameloop with a window class and tried to implement the code i already had.

I had to change multiple things, had challenges like the slick util textureloader, but now im stuck:

Basically what i see is the Window, but nothing is displayed on it. My Engine is fairly big by now, but i will try to implement the important methods. When you need more, i can post more.

I will post the Shaderfiles for entity and skybox (what im trying to display currently) too

And all i see is a Window with nothing displayed

MAIN CLASS

     package main;

import static org.lwjgl.glfw.GLFW.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;

import entities.Camera;
import entities.Light;
import entities.Player;
import graphics.Window;
import graphics.models.RawModel;
import graphics.models.TexturedModel;
import graphics.renderEngine.Loader;
import graphics.renderEngine.MasterRenderer;
import graphics.renderEngine.OBJLoader;
import graphics.textures.ModelTexture;
import toolbox.Vector3f;


public class Main 
{

    private GLFWErrorCallback errorCallback = GLFWErrorCallback.createPrint(System.err);

    private Window window;
    private MasterRenderer renderer;
    private Loader loader;

    private int Width;
    private int Height;
    private boolean running = false;
    private double delta;

    List<Light> lights = new ArrayList<Light>();
    Camera camera = null;
    private Player player;
    public Main()
    {


        init();

    }

    private void input()
    {
        glfwPollEvents();
        if(window.shouldClose()) stop();
    }

    private void update()
    {
        renderer.setHeight(Height);
        renderer.setWidth(Width);
        renderer.setDelta(delta);
    }

    private  void render()
    {
        renderer.processEntity(player);
        renderer.render(lights, camera);
        window.render();
    }

    private void run()
    {

        long lastTime = System.nanoTime();
        long currentTime = lastTime;
        long diff = 0;

        long timer = System.currentTimeMillis();

        double ns = 1000000000 / 60.0;
        delta = 0.0;

        double dfps = 1000000000 / 60.0;
        double d = 0.0;

        int fps = 0;
        int ups = 0;

        while(running)
        {
            currentTime = System.nanoTime();
            diff = currentTime - lastTime;
            delta += (diff)/ ns;
            d += diff/dfps;
            lastTime = currentTime;
            while(delta >= 1.0)
            {
                input();
                update();
                ups++;
                delta--;
            }

            if(d >- 1.0)
            {
                render();
                fps++;
                d = 0.0;
            }

            if(System.currentTimeMillis() > timer + 1000)
            {
                window.setTitle("Junker.5 | ups: "+ups+"| fps: "+fps+"");
                ups = 0;
                fps = 0;
                timer += 1000;
            }
        }

        cleanUp();
    }



    public void start()
    {
        if(running) return;
        running = true;
        run();
    }

    public void stop()
    {
        if(!running) return;
        running = false;
    }


    private void init()
    {

        Width = 1280;
        Height = 720;
        glfwSetErrorCallback(errorCallback);
        glfwInit();



        window = new Window(Width, Height, "Junker.5");
        GL.createCapabilities();

        loader = new Loader();
        renderer = new MasterRenderer(loader);
        renderer.setHeight(Height);
        renderer.setWidth(Width);
        renderer.setDelta(delta);


        RawModel playerShip = OBJLoader.loadObjModel("Puddle Jumper", loader);
        TexturedModel playership = new TexturedModel(playerShip, ModelTexture.loadTexture("white"));

        player = new Player(playership, new Vector3f(0, 0, -50),0,0,0,1);

        lights.add(new Light(new Vector3f(0,1000,-5000), new Vector3f(0f,0.4f,5f)));
        lights.add(new Light(new Vector3f(0,0,-10), new Vector3f(1,0,1), new Vector3f(1, 0.01f, 0.002f)));

        try 
        {
            camera = new Camera(player);
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }

    private void cleanUp()
    {
        window.hide();
        //guiRenderer.cleanUp();
        renderer.cleanUp();
        loader.cleanUp();
        window.dispose();
    }


    public static void main(String[] args) 
    {

        Main main = new Main();
        main.start();

    }

    public int getWidth()
    {
        return window.getWidth();
    }

    public int getheight()
    {
        return window.getHeight();
    }

    public double getDelta()
    {
        return delta;
    }

}

MASTER RENDERER CLASS

    package graphics.renderEngine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.lwjgl.opengl.GL11;


import entities.Camera;
import entities.Entity;
import entities.Light;
import entities.Player;
import graphics.models.RawModel;
import graphics.models.TexturedModel;
import graphics.shaders.StaticShader;
import graphics.shaders.TerrainShader;
import graphics.skybox.SkyboxRenderer;
import graphics.terrains.Terrain;
import graphics.textures.ModelTexture;
import toolbox.Matrix4f;
import toolbox.Vector3f;

public class MasterRenderer 
{
    private static final float FOV = 70;
    private static final float NEAR_PLANE = 0.01f;
    private static final float FAR_PLANE = 1000;

    public int Width;
    public double delta;
    public int Height;

    private Matrix4f projectionMatrix;

    private StaticShader shader = new StaticShader();
    private TerrainRenderer terrainRenderer;
    private TerrainShader terrainShader = new TerrainShader();

    private EntityRenderer renderer;

    private Map<TexturedModel, List<Entity>> entities = new HashMap<TexturedModel, List<Entity>>();
    private List<Terrain> terrains = new ArrayList<Terrain>();

    private SkyboxRenderer skyboxRenderer ;

    public MasterRenderer(Loader loader)
    {
        enableCulling();

        createProjectionMatrix();
        renderer = new EntityRenderer(shader, projectionMatrix);
        terrainRenderer = new TerrainRenderer(terrainShader, projectionMatrix);
        skyboxRenderer = new SkyboxRenderer(loader, projectionMatrix);


    }

    public static void enableCulling()
    {
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glCullFace(GL11.GL_BACK);
    }

    public static void disableCullig()
    {
        GL11.glDisable(GL11.GL_CULL_FACE);
    }

    public void render(List<Light> lights, Camera camera)
    {
        prepare();
        shader.start();
        shader.loadLights(lights);
        shader.loadViewMatrix(camera);
        renderer.render(entities);
        shader.stop();
        terrainShader.start();
        terrainShader.loadLights(lights);
        terrainShader.loadViewMatrix(camera);
        terrainRenderer.render(terrains);
        terrainShader.stop();
        skyboxRenderer.render(camera);
        terrains.clear();
        entities.clear();
    }

    public void processTerrain(Terrain terrain)
    {
        terrains.add(terrain);
    }

    public void processEntity(Entity entity)
    {
        TexturedModel entityModel = entity.getModel();
        List<Entity> batch = entities.get(entityModel);
        if(batch != null)
        {
            batch.add(entity);
        }
        else
        {
            List<Entity> newBatch = new ArrayList<Entity>();
            newBatch.add(entity);
            entities.put(entityModel, newBatch);
        }
    }

    private void createProjectionMatrix()
    {
        float aspectRatio = (float) Width / (float) Height;
        float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);
        float x_scale = y_scale / aspectRatio;
        float frustum_length = FAR_PLANE - NEAR_PLANE;

        projectionMatrix = new Matrix4f();
        projectionMatrix.m00 = x_scale;
        projectionMatrix.m11 = y_scale;
        projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
        projectionMatrix.m23 = -1;
        projectionMatrix.m32 = -((2 * FAR_PLANE + NEAR_PLANE) / frustum_length);
        projectionMatrix.m33 = 0;   
    }

    public void prepare()
    {
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glClearColor(0.03f, 0f, 0.0f, 1);
    }

    public void cleanUp()
    {
        shader.cleanUp();
        terrainShader.cleanUp();
    }

    public void setWidth(int width) 
    {
        Width = width;
    }

    public void setHeight(int height) 
    {
        Height = height;
    }

    public void setDelta(double delta) 
    {
        this.delta = delta;
    }
}

STATIC SHADER CLASS

 package graphics.shaders;

import java.util.List;

import entities.Camera;
import entities.Light;
import toolbox.Maths;
import toolbox.Matrix4f;
import toolbox.Vector3f;



public class StaticShader extends ShaderProgram
{

    public static final String VERTEX_FILE = "./Ressources/Shaders/VertexShader.shd";
    public static final String FRAGMENT_FILE = "./Ressources/Shaders/FragmentShader.shd";
    public static final int MAX_LIGHTS = 4;

    private int location_transformationMatrix;
    private int location_projectionMatrix;
    private int location_viewMatrix;
    private int location_lightPosition[];
    private int location_lightColour[];
    private int location_attenuation[];
    private int location_shineDamper;
    private int location_reflectivity;
    private int location_useFakeLighting;

    public StaticShader() 
    {
        super(VERTEX_FILE, FRAGMENT_FILE);
    }

    @Override
    protected void bindAttributes() 
    {
        super.bindAttribute(0, "position");
        super.bindAttribute(1, "textureCoords");
        super.bindAttribute(2, "normal");
    }

    protected void getAllUniformLocations()
    {
        location_transformationMatrix = super.getUniformLocation("transformationMatrix");
        location_projectionMatrix = super.getUniformLocation("projectionMatrix");
        location_viewMatrix = super.getUniformLocation("viewMatrix");
        location_shineDamper = super.getUniformLocation("shineDamper");
        location_reflectivity = super.getUniformLocation("reflectivity");
        location_useFakeLighting = super.getUniformLocation("useFakeLighting");


        location_lightPosition = new int[MAX_LIGHTS];
        location_attenuation = new int[MAX_LIGHTS];
        location_lightColour = new int[MAX_LIGHTS];
        for(int i = 0;i<MAX_LIGHTS;i++)
        {
            location_lightPosition[i] = super.getUniformLocation("lightPosition["+i+"]");
            location_lightColour[i] = super.getUniformLocation("lightColour["+i+"]");   
            location_attenuation[i] = super.getUniformLocation("attenuation["+i+"]");   
        }
    }

    public void loadFakeLightingVariable(boolean useFake)
    {
        super.loadBoolean(location_useFakeLighting, useFake);
    }

    public void loadShineVariables(float damper, float reflectivity)
    {
        super.LoadFloat(location_shineDamper, damper);
        super.LoadFloat(location_reflectivity, reflectivity);
    }

    public void loadTreansformationMatrix(Matrix4f matrix)
    {
        super.loadMatrix(location_transformationMatrix, matrix);
    }

    public void loadLights(List<Light> lights)
    {
        for(int i = 0;i<MAX_LIGHTS;i++)
        {
            if(i<lights.size())
            {
                super.LoadVector(location_lightPosition[i], lights.get(i).getPosition());
                super.LoadVector(location_lightColour[i], lights.get(i).getColour());
                super.LoadVector(location_attenuation[i], lights.get(i).getAttenuation());
            }
            else
            {
                super.LoadVector(location_lightPosition[i], new Vector3f(0,0,0));
                super.LoadVector(location_lightColour[i], new Vector3f(0,0,0));
                super.LoadVector(location_attenuation[i], new Vector3f(1,0,0));
            }
        }
    }

    public void loadViewMatrix(Camera camera)
    {
        Matrix4f viewMatrix = Maths.createViewMatrix(camera);
        super.loadMatrix(location_viewMatrix, viewMatrix);
    }

    public void loadProjectionMatrix(Matrix4f projection)
    {
        super.loadMatrix(location_projectionMatrix, projection);
    }

}

SHADERFILES:

FRAGMENT SHADER

#version 400 core

in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[4];
in vec3 toCameraVector;

out vec4 out_Color;

uniform sampler2D textureSampler;
uniform vec3 lightColour[4];
uniform float shineDamper;
uniform float reflectivity;
uniform vec3 attenuation[4];

void main(void)
{
    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitVectorToCamera = normalize(toCameraVector);

    vec3 totalDiffuse = vec3(0.0);
    vec3 totalSpecular = vec3(0.0);

    for(int i=0;i<4;i++)
    {
    float distance = length(toLightVector[i]);
    float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance);
        vec3 unitLightVector = normalize(toLightVector[i]);
        float nDot1 = dot(unitNormal, unitLightVector);
        float brightness = max(nDot1,0.0);
        vec3 lightDirection = -unitLightVector;
        vec3 reflectedLightDirection = reflect(lightDirection,unitNormal);
        float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
        specularFactor = max(specularFactor,0.0);
        float dampedFactor = pow(specularFactor,shineDamper);
        totalSpecular = totalSpecular + (dampedFactor * reflectivity * lightColour[i])/attFactor;
        totalDiffuse = totalDiffuse  + (brightness * lightColour[i])/attFactor;

    }

    totalDiffuse = max(totalDiffuse, 0.2);

    vec4 textureColour = texture(textureSampler, pass_textureCoords);
    if(textureColour.a<0.5)
    {
        discard;
    }

    out_Color = vec4(totalDiffuse,1.0) * texture(textureSampler, pass_textureCoords) + vec4(totalSpecular,1.0);
}

VERTEX SHADER

#version 400 core

in vec3 position;
in vec2 textureCoords;
in vec3 normal;


out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector[4];
out vec3 toCameraVector;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition[4];

uniform float useFakeLighting;

void main(void)
{
    vec4 worldPosition = transformationMatrix * vec4(position,1.0);
    gl_Position = projectionMatrix * viewMatrix * worldPosition;
    pass_textureCoords = textureCoords;

    vec3 actualNormal = normal;
    if(useFakeLighting > 0.5)
    {
        actualNormal = vec3(0.0,1.0,0.0);
    }

    surfaceNormal = (transformationMatrix * vec4(actualNormal,0.0)).xyz;
    for(int i=0;i<4;i++)
    {
        toLightVector[i] = lightPosition[i] - worldPosition.xyz;
    }
    toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;

}

I have absolutely no idea what im doing wrong. If anyone wants to really help me more personal on this problem, feel free to contact me too.

Thank you soo much!

EDIT:

Yes, the Clearcolor works, thats part of why i am confused. And before i worked ofer my lwjgl2 code to my new lwjgl3 code, the lwjgl3 window DID display simple graphics such as a 3d cube

Here is my window class

WINDOW

package graphics;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryUtil;


public class Window 
{

    private long window;
    private int Width;
    private int Height;

    public Window(int width, int height, String title)
    {

        this.Width = width;
        this.Height = height;
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
        glfwWindowHint(GLFW_VISIBLE, GL11.GL_TRUE);
        //DECORATION
        glfwWindowHint(GLFW_DECORATED, GL11.GL_TRUE);
        glfwWindowHint(GLFW_FOCUSED, GL11.GL_TRUE);
        window = glfwCreateWindow(Width,Height,"Junker.5",NULL,NULL);

        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());

        glfwSetWindowPos(
                window,
                 (vidmode.width() - width) / 2,
                (vidmode.height() - height) / 2
            ); 

        glfwMakeContextCurrent(window);
    }

    public void dispose()
    {
        glfwDestroyWindow(window);
    }

    public void hide()
    {
        glfwHideWindow(window);
    }

    public void render()
    {
        glfwSwapBuffers(window);
    }

    public void show()
    {
        glfwShowWindow(window);
    }

    public void setTitle(String title)
    {
        glfwSetWindowTitle(window, title);
    }

    public boolean shouldClose() 
    {
          if(!glfwWindowShouldClose(window)) 
          {
           return false;
          }
          else
          {
              return true;
          }
    }



    public int getWidth() 
    {
        return Width;
    }

    public void setWidth(int width) 
    {
        Width = width;
    }

    public int getHeight() 
    {
        return Height;
    }

    public void setHeight(int height) 
    {
        Height = height;
    }

    public void changecursor()
    {
        // Create the cursor object
        //long cursor = GLFW.glfwCreateCursor(imageBuffer, 0, 0);

        /*if (cursor == MemoryUtil.NULL)
            throw new RuntimeException("Error creating cursor");

        // Set the cursor on a window
        GLFW.glfwSetCursor(window, cursor);*/
    }

}

Answer:

I did manage to fix the problem myself, atleast its displaying stuff now :)

I just hardcoded the Width and height right now. The method of doing a setHeight() in the Main class must have angried the gods of my createProjectionMatrix() function. However, id would be awesome to know how to do this dynamic for future purposes