#JOGL glUniform4fv issue

6 messages · Page 1 of 1 (latest)

deft widget
#

Here's my set uniform code:

    public static boolean setUniform(GL3 gl, String name, Object value) {
        if (shaderProgram == -1) {
            throw new IllegalStateException("Shaders not initialized yet");
        }

        gl.glUseProgram(shaderProgram);

        int location;

        if (!uniforms.containsKey(name)) {
            location = gl.glGetUniformLocation(shaderProgram, name);

            if (location == -1) {
                return false;
            }

            uniforms.put(name, location);
        } else {
            location = uniforms.get(name);
        }

                double[][] matrix = (double[][]) matrix;

        if (matrix.length != 4 || matrix[0].length != 4) {
            throw new UnsupportedOperationException("Unsupported matrix size " + matrix[0].length + "x" + matrix.length);
        }

        float[] fMat = new float[16];

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                fMat[j * 4 + i] = matrix[i][j];
            }
        }

        gl.glUniform4fv(location, 1, fMat, 0);

        return true;
    }

And here's the error:
com.jogamp.opengl.GLException: Thread[#39,AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glUniform4fv(<int> 0x0, <int> 0x1, <[F>, <int> 0x0): GL_INVALID_OPERATION ( 1282 0x502)
Why is there this issue? Shader init code in comment.

coral skyBOT
#

This post has been reserved for your question.

Hey @deft widget! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

deft widget
#
shaderProgram = gl.glCreateProgram();

if (shaderProgram < 1) {
    throw new IllegalStateException("program");
}

vertexId = gl.glCreateShader(gl.GL_VERTEX_SHADER);
gl.glShaderSource(vertexId, 1, new String[]{vertexCode}, new int[]{vertexCode.length()}, 0);
gl.glCompileShader(vertexId);

int[] compiled = new int[1];
gl.glGetShaderiv(vertexId, gl.GL_COMPILE_STATUS, compiled, 0);

if (compiled[0] == 0) {
    int[] logLength = new int[1];
    gl.glGetShaderiv(vertexId, gl.GL_INFO_LOG_LENGTH, logLength, 0);

    byte[] log = new byte[logLength[0]];

    gl.glGetShaderInfoLog(vertexId, logLength[0], null, 0, log, 0);

    throw new IllegalStateException("Vertex shader error: \n" + new String(log));
}

fragmentId = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);
gl.glShaderSource(fragmentId, 1, new String[]{fragmentCode}, new int[]{fragmentCode.length()}, 0);
gl.glCompileShader(fragmentId);

gl.glGetShaderiv(fragmentId, gl.GL_COMPILE_STATUS, compiled, 0);

if (compiled[0] == 0) {
    int[] logLength = new int[1];
    gl.glGetShaderiv(fragmentId, gl.GL_INFO_LOG_LENGTH, logLength, 0);

    byte[] log = new byte[logLength[0]];

    gl.glGetShaderInfoLog(fragmentId, logLength[0], null, 0, log, 0);

    throw new IllegalStateException("Fragment shader error: \n" + new String(log));
}

gl.glAttachShader(shaderProgram, vertexId);
gl.glAttachShader(shaderProgram, fragmentId);

gl.glLinkProgram(shaderProgram);
gl.glValidateProgram(shaderProgram);

gl.glUseProgram(shaderProgram);
#
public static int shaderProgram = -1, vertexId = -1, fragmentId = -1;

public static final String vertexCode = """
        #version 330 core

        layout (location = 0) in vec3 pos;
        layout (location = 1) in vec2 texCoord;
            
        out vec2 tex;

        uniform mat4 proj;
        uniform mat4 trans;

        void main()
        {
            gl_Position = proj * trans * vec4(pos, 1);
            tex = texCoord;
        }
        """, fragmentCode = """
        #version 330 core
            
        in vec2 tex;
        uniform sampler2D atlas;
            
        void main()
        {
            gl_FragColor = texture2D(atlas, tex);
        }
        """;
deft widget
#

I jiggled the handle a bit and got it working. Weird.