[SOLVED] Strange error - LWJGL game working on one computer but not on another

Like in topic. I am developing game in team of two people - I am programming on Windows, official JDK while second programmer is working on Linux, OpenJDK. We are using the same LWJGL version. Code is working for me, but my teammate sees this message:

Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL20.glUniform4f(GL20.java:365)
at Lib.Graphics.RenderEngine.renderShift(RenderEngine.java:210)
at Objects.Ships.PlayerShip.draw(PlayerShip.java:51)
at Core.Graphics.Graphics.update(Graphics.java:48)
at Core.Core.<init>(Core.java:44)
at Core.Core.main(Core.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 13 seconds)

What can cause this problem? I am sure that everything is set right on both computers, game was running without problems until the engine upgrade.

Here is the RenderEngine class (most important fragments):

package Lib.Graphics;

import Core.Graphics.Graphics;
import Lib.Graphics.Shaders.ShaderInput;
import Lib.Graphics.Textures.Tex;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class RenderEngine {
    
    private int activeProgram = 0;
    private int activeTexture = 0;
    
    private int vaoId = 0;
    private int vboId = 0;
    private int vboiId = 0;
    private int indicesCount = 0;
    private Vertex[] vertices = null;
    private ByteBuffer verticesByteBuffer = null;
    
    private int textureBeginID = 0;
    private int textureTranslationsID = 0;
    private int projectionMatrixLocation = 0;
    private int viewMatrixLocation = 0;
    private int modelMatrixLocation = 0;
    private Matrix4f projectionMatrix = null;
    private Matrix4f viewMatrix = null;
    private Matrix4f modelMatrix = null;
    private Vector3f modelPos = null;
    private Vector3f modelShift = null;
    private Vector3f modelAngle = null;
    private Vector3f modelScale = null;
    private Vector3f cameraPos = null;
    private FloatBuffer matrix44Buffer = null;
    
    public RenderEngine() {}
    
    public void initialize(int width, int height) {
        setupMatrices(width, height);
        setupQuad();
    }
    
    public void startDrawing() {
        GL20.glUseProgram(activeProgram);
        
        GL30.glBindVertexArray(vaoId);
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        
        setCamera(0, 0);
    }
    
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
        
        modelScale.x = scalex;
        modelScale.y = scaley;
        
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
        
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
        
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
        
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]);
                        break;
                }
            }
        }
        
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
        
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
    
    public void endRendering() {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);
        GL30.glBindVertexArray(0);

        GL20.glUseProgram(0);
    }
    
    private void setupMatrices(int width, int height) {
        projectionMatrix = GCore.matrix.orthoMatrix(width, height, -0.1f, 1.1f);
        
        viewMatrix = new Matrix4f();

        modelMatrix = new Matrix4f();

        matrix44Buffer = BufferUtils.createFloatBuffer(16);
    }
    
    private void setupQuad() {
        Vertex v0 = new Vertex(); 
        v0.setXYZ(-0.5f, 0.5f, 0); v0.setRGB(1, 1, 1); v0.setST(0, 0);
        Vertex v1 = new Vertex(); 
        v1.setXYZ(-0.5f, -0.5f, 0); v1.setRGB(1, 1, 1); v1.setST(0, 1);
        Vertex v2 = new Vertex(); 
        v2.setXYZ(0.5f, -0.5f, 0); v2.setRGB(1, 1, 1); v2.setST(1, 1);
        Vertex v3 = new Vertex(); 
        v3.setXYZ(0.5f, 0.5f, 0); v3.setRGB(1, 1, 1); v3.setST(1, 0);

        vertices = new Vertex[] {v0, v1, v2, v3};
        
        verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * Vertex.stride);				
        FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
        for (int i = 0; i < vertices.length; i++) {
                verticesFloatBuffer.put(vertices[i].getElements());
        }
        verticesFloatBuffer.flip();

        byte[] indices = {
                        0, 1, 2,
                        2, 3, 0
        };
        indicesCount = indices.length;
        ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
        indicesBuffer.put(indices);
        indicesBuffer.flip();

        vaoId = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(vaoId);

        vboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STATIC_DRAW);

        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.positionByteOffset);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.colorByteOffset);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.textureByteOffset);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL30.glBindVertexArray(0);

        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        modelPos = new Vector3f(0, 0, 0);
        modelShift = new Vector3f(0, 0, 0);
        modelAngle = new Vector3f(0, 0, 0);
        modelScale = new Vector3f(1, 1, 1);
        cameraPos = new Vector3f(0, 0, 0);
    }
    
}

I am using this code like this:

GCore.renderer.render(TL.blankHex, SL.coloredShader, x, y, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1));

ShaderInput class:

package Lib.Graphics.Shaders;

public class ShaderInput {
    public int location;
    
    public float[] values;
    public String name;
    
    public ShaderInput(String name, float value1, float value2, float value3, float value4) {
        this.name = name;
        this.values = new float[4];
        this.values[0] = value1;
        this.values[1] = value2;
        this.values[2] = value3;
        this.values[3] = value3;
    }
    
    public ShaderInput(String name, float value1, float value2, float value3) {
        this.name = name;
        this.values = new float[3];
        this.values[0] = value1;
        this.values[1] = value2;
        this.values[2] = value3;
    }
    
    public ShaderInput(String name, float value1, float value2) {
        this.name = name;
        this.values = new float[2];
        this.values[0] = value1;
        this.values[1] = value2;
    }
    
    public ShaderInput(String name, float value1) {
        this.name = name;
        this.values = new float[1];
        this.values[0] = value1;
    }
}

This is SL.coloredShader fragment shader (I am sure that vector shader don’t contain any errors):

#version 150 core

uniform sampler2D texture_diffuse;
uniform vec2 beginTexture;
uniform vec2 translateTexture;
uniform vec4 color;

in vec4 pass_Color;
in vec2 pass_TextureCoord;

out vec4 out_Color;

void main(void) {
    out_Color = texture2D(texture_diffuse, pass_TextureCoord*translateTexture+beginTexture)*(pass_Color*color);
}

We have tried many changes in code, but still can’t find out why code is not working. I apologize for the amount of code in this thread, but we can’t figure out where is the cause of the problem.

Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL20.glUniform4f(GL20.java:365)
at Lib.Graphics.RenderEngine.renderShift(RenderEngine.java:210)
at Objects.Ships.PlayerShip.draw(PlayerShip.java:51)
at Core.Graphics.Graphics.update(Graphics.java:48)
at Core.Core.<init>(Core.java:44)
at Core.Core.main(Core.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 13 seconds)

See this?

NONE of the methods in this stack trace are available to us. The error is caused by this chain of methods, but you haven’t shown any of them. Please show all the appropriate methods. :slight_smile:

Can we also see your shader creation code.

The problem is caused by glUniform4f()


 if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]);
                        break;
                }
            }
        }

Naturally.

About the chain of methods: here it is, starting from Core.Core.main:

    public static void main(String[] args) {
            new Core(); //<-this line
    }
    public Core() {
        logic = new Logic();
        physics = new Physics();
        graphics = new Graphics();
        audio = new Audio();
        input = new In();
        
        logic.initialize();
        physics.initialize();
        graphics.initialize();
        audio.initialize();
        input.initialize();
        
        graphics.setLogic(logic);
        
        while(!Display.isCloseRequested()) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            
            input.update();
            logic.update();
            physics.update();
            graphics.update(); //<-this line
            audio.update();
            
            Display.update();
            Display.sync(60);
        }
        Display.destroy();
    }
    private int time = 0;
    
    public void update() {
        time++;
        GCore.renderer.startDrawing();
            logic.ship.draw(); //<-this line
            if (In.keyboard.hold.one) {
                GCore.renderer.render(TL.black, SL.postProcess, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT, 0, new ShaderInput("time", time)); //this line is working even though it is using ShaderInput - its shader is using uniform float time.
            }
        
        GCore.renderer.endRendering();
        time%=60;
    }
    public void draw() {
        //To kick from draw() - from there...
        float centerX = 0;
        float centerY = 0;
        
        int first = 10;
        int second = 6;
        boolean[][] shipArray = new boolean[first][second];
      
        for(int count = 0; count<first; count++){
            for(int countInside = 0; countInside<second; countInside++){
                shipArray[count][countInside] = true;
            } 
        }
        //...to there
        
        for(int count = 0; count<first; count++){
            for(int countInside = 0; countInside<second; countInside++){
                if(shipArray[count][countInside]==true){
                    switch(countInside%2) {
                        case 0:
                            GCore.renderer.renderShift(TL.blankHex, SL.coloredShader, x, y, (scaleX*(count*2))-centerX, (scaleY*(countInside*1.5f))-centerY, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1)); //<-this line
                            // /\ line above
                            break;
                        case 1:
                            GCore.renderer.renderShift(TL.blankHex, SL.coloredShader, x, y, (scaleX*(count*2)-scaleX)-centerX, (scaleY*(countInside*1.5f))-centerY, scaleX, scaleY, rotate, new ShaderInput("color", 0, 1, 1, 1));
                            break;
                    }
                    
                }
            }
        }
    }

And, the whole RendererEngine class:

package Lib.Graphics;

import Core.Graphics.Graphics;
import Lib.Graphics.Shaders.ShaderInput;
import Lib.Graphics.Textures.Tex;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class RenderEngine {
    
    private int activeProgram = 0;
    private int activeTexture = 0;
    
    private int vaoId = 0;
    private int vboId = 0;
    private int vboiId = 0;
    private int indicesCount = 0;
    private Vertex[] vertices = null;
    private ByteBuffer verticesByteBuffer = null;
    
    private int textureBeginID = 0;
    private int textureTranslationsID = 0;
    private int projectionMatrixLocation = 0;
    private int viewMatrixLocation = 0;
    private int modelMatrixLocation = 0;
    private Matrix4f projectionMatrix = null;
    private Matrix4f viewMatrix = null;
    private Matrix4f modelMatrix = null;
    private Vector3f modelPos = null;
    private Vector3f modelShift = null;
    private Vector3f modelAngle = null;
    private Vector3f modelScale = null;
    private Vector3f cameraPos = null;
    private FloatBuffer matrix44Buffer = null;
    
    public RenderEngine() {}
    
    public void initialize(int width, int height) {
        setupMatrices(width, height);
        setupQuad();
    }
    
    public void startDrawing() {
        GL20.glUseProgram(activeProgram);
        
        GL30.glBindVertexArray(vaoId);
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        
        setCamera(0, 0);
    }
    
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, ShaderInput...in) {
        render(texture, shader, x, y, scalex, scaley, 0, in);
    }
    
    public void render(Tex texture, int shader, float x, float y, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
        
        modelScale.x = scalex;
        modelScale.y = scaley;
        
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
        
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix, modelMatrix);
        Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
        
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
        
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]);
                        break;
                }
            }
        }
        
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
        
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
    
    public void renderShift(Tex texture, int shader, float x, float y, float shiftx, float shifty, float scalex, float scaley, ShaderInput...in) {
        renderShift(texture, shader, x, y, shiftx, shifty, scalex, scaley, 0, in);
    }
    
    public void renderShift(Tex texture, int shader, float x, float y, float shiftx, float shifty, float scalex, float scaley, float angle, ShaderInput...in) {
        x = (x*2)-Graphics.WIDTH;
        y = (y*2)-Graphics.HEIGHT;
        scalex*=2;
        scaley*=2;
        if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

        modelAngle.z = angle;
        modelPos.x = x;
        modelPos.y = y;
        
        modelScale.x = scalex;
        modelScale.y = scaley;
        
        modelShift.x = shiftx;
        modelShift.y = shifty;
        
        viewMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();

        Matrix4f.translate(cameraPos, viewMatrix, viewMatrix);
        
        Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
        Matrix4f.rotate(modelAngle.z, new Vector3f(0, 0, 1), modelMatrix, modelMatrix);
        Matrix4f.translate(modelShift, modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix, modelMatrix);
        //Matrix4f.rotate(this.degreesToRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix, modelMatrix);
        Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
        
        projectionMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);
        viewMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
        modelMatrix.store(matrix44Buffer); matrix44Buffer.flip();
        GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
        
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                switch (in[i].values.length) {
                    case 1:
                        GL20.glUniform1f(in[i].location, in[i].values[0]);
                        break;
                    case 2:
                        GL20.glUniform2f(in[i].location, in[i].values[0], in[i].values[1]);
                        break;
                    case 3:
                        GL20.glUniform3f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2]);
                        break;
                    case 4:
                        GL20.glUniform4f(in[i].location, in[i].values[0], in[i].values[1], in[i].values[2], in[i].values[3]); //<-this line
                        break;
                }
            }
        }
        
        GL20.glUniform2f(textureBeginID, texture.drawBeginX, texture.drawBeginY);
        GL20.glUniform2f(textureTranslationsID, texture.drawSizeX, texture.drawSizeY);
        
        if (texture.ID!=activeTexture) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.ID);
            activeTexture = texture.ID;
        }

        GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
    }
    
    public void setCamera(float x, float y) {
        cameraPos.x = x;
        cameraPos.y = y;
    }
    
    public void endRendering() {
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);
        GL30.glBindVertexArray(0);

        GL20.glUseProgram(0);
    }
    
    private void setupMatrices(int width, int height) {
        projectionMatrix = GCore.matrix.orthoMatrix(width, height, -0.1f, 1.1f);
        
        viewMatrix = new Matrix4f();

        modelMatrix = new Matrix4f();

        matrix44Buffer = BufferUtils.createFloatBuffer(16);
    }
    
    private void setupQuad() {
        Vertex v0 = new Vertex(); 
        v0.setXYZ(-0.5f, 0.5f, 0); v0.setRGB(1, 1, 1); v0.setST(0, 0);
        Vertex v1 = new Vertex(); 
        v1.setXYZ(-0.5f, -0.5f, 0); v1.setRGB(1, 1, 1); v1.setST(0, 1);
        Vertex v2 = new Vertex(); 
        v2.setXYZ(0.5f, -0.5f, 0); v2.setRGB(1, 1, 1); v2.setST(1, 1);
        Vertex v3 = new Vertex(); 
        v3.setXYZ(0.5f, 0.5f, 0); v3.setRGB(1, 1, 1); v3.setST(1, 0);

        vertices = new Vertex[] {v0, v1, v2, v3};
        
        verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * Vertex.stride);				
        FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
        for (int i = 0; i < vertices.length; i++) {
                verticesFloatBuffer.put(vertices[i].getElements());
        }
        verticesFloatBuffer.flip();

        byte[] indices = {
                        0, 1, 2,
                        2, 3, 0
        };
        indicesCount = indices.length;
        ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
        indicesBuffer.put(indices);
        indicesBuffer.flip();

        vaoId = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(vaoId);

        vboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STATIC_DRAW);

        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.positionByteOffset);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.colorByteOffset);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride, Vertex.textureByteOffset);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL30.glBindVertexArray(0);

        vboiId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        modelPos = new Vector3f(0, 0, 0);
        modelShift = new Vector3f(0, 0, 0);
        modelAngle = new Vector3f(0, 0, 0);
        modelScale = new Vector3f(1, 1, 1);
        cameraPos = new Vector3f(0, 0, 0);
    }
    
}

Edit: Shader creation code:

public class ShaderLoader {
    
    public int loadProgram(String vertexShader, String fragmentShader) {		
        int vsId = loadShader(vertexShader, GL20.GL_VERTEX_SHADER);
        int fsId = loadShader(fragmentShader, GL20.GL_FRAGMENT_SHADER);

        int pId = GL20.glCreateProgram();
        GL20.glAttachShader(pId, vsId);
        GL20.glAttachShader(pId, fsId);
        GL20.glLinkProgram(pId);

        GL20.glBindAttribLocation(pId, 0, "in_Position");
        GL20.glBindAttribLocation(pId, 1, "in_Color");
        GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

        GL20.glValidateProgram(pId);
        
        return pId;
    }
    
    private int loadShader(String filename, int type) {
        int shaderID = 0;
        String shaderSource="";
        try {
                InputStream in = this.getClass().getResourceAsStream(filename);
                while (in.available()>0) {
                    shaderSource = shaderSource.concat(String.valueOf((char)in.read()));
                }
        } catch (IOException e) {
                System.err.println("Cannot read shader: "+filename);
                e.printStackTrace();
                System.exit(-1);
        }

        shaderID = GL20.glCreateShader(type);
        GL20.glShaderSource(shaderID, shaderSource);
        GL20.glCompileShader(shaderID);

        return shaderID;
    }
    
}
        SL.defaultShader = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/defaultShader.vert", "/Core/Graphics/Shaders/defaultShader.frag");
        SL.coloredShader = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/defaultShader.vert", "/Core/Graphics/Shaders/coloredShader.frag");
        SL.postProcess = GCore.shaderLoader.loadProgram("/Core/Graphics/Shaders/postProcess.vert", "/Core/Graphics/Shaders/postProcess.frag");

From the GL spec, the only reasons related to this could be:

The one most likely is that “location” is invalid. After line 160 of RenderEngine, make sure in[i[b][/b]].location is a valid value (not -1).

I was just about to ask where the location variable is set.

@OP: ^^ Where is it set?

Have you followed the line number I mentioned? ::slight_smile:

Nope. Didn’t see that.

Maybe shader == activeProgram?

It seems that I found error, I had to change this:

if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            if (in!=null) {
                for (int i=0; i<in.length; i++) {
                    in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
                }
            }
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }

into this:

if (shader!=activeProgram) {
            GL20.glUseProgram(shader);
            projectionMatrixLocation = GL20.glGetUniformLocation(shader, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(shader, "viewMatrix");
            modelMatrixLocation = GL20.glGetUniformLocation(shader, "modelMatrix");
            textureBeginID = GL20.glGetUniformLocation(shader, "beginTexture");
            textureTranslationsID = GL20.glGetUniformLocation(shader, "translateTexture");
            activeProgram = shader;
        }
        
        if (in!=null) {
            for (int i=0; i<in.length; i++) {
                in[i].location = GL20.glGetUniformLocation(shader, in[i].name);
            }
        }

Ah yup, seems like you’re supplying new objects of ShaderInputs ever time. If the shader is constantly active, you are not getting their locations every time.

Don’t uniforms and attributes stay in the same location unless the shader is reloaded?
You only need to get locations once when you create the shader, then store them.