Login  Register

Need Help Solving OpenGL/GLSL 4.4 Issues

Posted by xghost on Jul 14, 2014; 8:57am
URL: https://forum.jogamp.org/Need-Help-Solving-OpenGL-GLSL-4-4-Issues-tp4032557.html

Hi Everyone,

I've run into a problem that I've not been able to figure out after over a week of searching around, including this forum.

I have a simple (i.e. draw-a-triangle -on-screen-type demo app) that has a vertex and a fragment shader (using version 4.4 core profile) that does not behave as intended in several details. The shaders compile and the program links just fine --i.e. OpenGL reports no errors when checking glGetError.

Some information about my system:

  * Ubuntu 14.04 LTS GNU/Linux 64-bit  (I've also tried in Windows 7 64-bit --using dual-boot desktop)
  * "java -version" command on shell shows:
     java version "1.7.0_55"
    OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
    OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
  * NVIDIA GTX 770 card with driver 331.79

I'm currently using JOGL 2.1.5 built on March 11, 2014 (http://jogamp.org/deployment/jogamp-current/archive/)

The sample code I'm trying to work with, as some of you might anticipate, is from the OpenGL Super Bible 6th Ed. (Yes, I know that is C++ and this is Java.. I've translated the code.) Please note that this is *not* the first time I use JOGL; I've used it before with the fixed pipeline (it was a legacy code-base). This is, however, the first time trying to use shaders with JOGL.

I've verified several things in my troubleshooting attempts, trying to rule out possible issues. A few of them include:

1. Re-checked that my graphics card does support OpenGL/GLSL features I'm trying to use (which it does)

2. Checked for errors calling glGetError() in loops after each gl* call, but no errors are reported.

3. Checked OpenGL information reported by the system/driver (it supports OpenGL 4.4 and GLSL 4.4)
    a. I even tried installing the proprietary driver to at least check if it was an issue with the open implementation, but I've found no noticeable difference

4. I've checked this info with glxinfo, nvidia-settings, and by querying the GLContext and GLProfile objects with JOGL itself:
        // [...]
        gl = (GL4) drawable.getGL();
        System.out.println("[debug] GL Profile    : " + gl.getGLProfile().toString());
        System.out.println("[debug] Version Number: " + gl.getContext().getGLSLVersionNumber().toString());
        System.out.println("[debug] Version String: " + gl.getContext().getGLSLVersionString().trim());
        //
        // -- shows the following output --
        //
        [debug] GL Profile    : GLProfile[GL4bc/GL4bc.hw]
        [debug] Version Number: 4.40.0
        [debug] Version String: #version 440

5. Checked different versions of JOGL, but the behavior was the same.
    a. Checked if the behavior was specific to GNU/Linux, but I noticed the same behavior on Windows 7)
    b. Checked that the shader source code that I think is being processed is the code that's actually being submitted to the pipeline (which it is))

6. Checked driver version 331.79 (OpenGL/GLSL 4.4 made available with 326.29 (see https://developer.nvidia.com/opengl-driver)

7. Verified that I'm sending expected arguments to the JVM (e.g.  -Dsun.java2d.d3d=false), though I'm not sure this would make a difference under GNU/Linux

I can build and run the C++ demos from the OpenGL SB 6 repository (check github). When I try to draw vertices, I can get a black pixel... but it's always centered and black regardless of what I hard-code into the shader itself. I cannot get the triangle to show up. You only see the color used to clear the background.

I've provided what seems to be the more important pieces of source code. Unfortunately, it seems there's no way to nicely format the code, so I'll try my best here.. the overriden init/display methods are up first, and the shaders being used are at the bottom. I have removed most print statements for your sake.

Expected Result:
A single white triangle with a blue-colored background.

Actual Result:
The blue-colored background only. There's no triangle.

Any and all help troubleshooting this will be appreciated. Please let me know if you need any additional information. I'll check back frequently, but in general it'll be after I return from work (evening US Pacific time zone).

Thanks in advance,
-xghost

PSone: As for IDEs, I've tried both Eclipse Kepler and NetBeans 8.0
PS2: If you'd like to see all the code, I can put it on pastebin or something similar --assuming I can't upload here.

-------- java code start --------
    @Override
    public void init(GLAutoDrawable drawable) {
        gl = (GL4) drawable.getGL();
        int vertexShader = gl.glCreateShader(GL4.GL_VERTEX_SHADER);
        gl.glShaderSource(vertexShader, 1, vertexShaderSource, null);
        gl.glCompileShader(vertexShader);
        if(gl.glGetError() != GL.GL_NO_ERROR)
            System.err.println("[error] Vertex shader compilation failed.");

        int fragmentShader = gl.glCreateShader(GL4.GL_FRAGMENT_SHADER);
        gl.glShaderSource(fragmentShader, 1, fragmentShaderSource, null);
        gl.glCompileShader(fragmentShader);
        if(gl.glGetError() != GL.GL_NO_ERROR)
            System.err.println("[error] Fragment shader compilation failed.");

        program = gl.glCreateProgram();
        gl.glAttachShader(program, vertexShader);
        gl.glAttachShader(program, fragmentShader);
        gl.glLinkProgram(program);
        if(gl.glGetError() != GL.GL_NO_ERROR)
            System.err.println("[error] Program linking failed.");

        gl.glGenVertexArrays(vertexArray.length, vertexArray, 0);
        gl.glBindVertexArray(vertexArray[0]);

        gl.glDeleteShader(vertexShader);
        gl.glDeleteShader(fragmentShader);
    }

    @Override
    public void display(GLAutoDrawable drawable) {
        gl = (GL4) drawable.getGL();
        gl.glClearBufferfv(GL4.GL_COLOR, 0, bufferClearColor);
        gl.glUseProgram(program);
        gl.glPointSize(30.0f);
        double value = System.currentTimeMillis()/300.0;
        vertexAttribute.put(0, (float)(Math.sin(value) * 0.5f));
        vertexAttribute.put(1, (float)(Math.cos(value) * 0.6f));
        gl.glVertexAttrib4fv(0, vertexAttribute);
        gl.glDrawArrays(GL4.GL_TRIANGLES, 0, 3);
    }
-------- java code end --------

-------- vertex shader start --------
	#version 440 core

	// input vertex attribute
	layout (location = 0) in vec4 offset;

	void main(void)
	{
		const vec4 v1 = vec4( 0.25,  0.25, 0.5, 1.0);
		const vec4 v2 = vec4(-0.25, -0.25, 0.5, 1.0);
		const vec4 v3 = vec4( 0.25, -0.25, 0.5, 1.0);
		const vec4 vertices[3] = vec4[3](v1, v2, v3);

		gl_Position = vertices[gl_VertexID] + offset;
	}
-------- vertex shader end --------

-------- fragment shader start --------
	#version 440 core

	out vec4 color;

	void main(void)
	{
		color = vec4(1.0, 1.0, 1.0, 1.0);
	}
-------- fragment shader end --------