OpenGL Shader Problem

Hi @svan,

gave your code a try and if I changed a bit, it worked like a charm on my box (Win64).

Cheers
— mnse

import javax.swing.*;
import processing.opengl.PGraphicsOpenGL;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator; 

GLAutoDrawable drawable;
GLCanvas myCanvas;

final int GL_COLOR_BUFFER_BIT = 0x00004000;
final int GL_POINTS = 0x0000;
final int GL_VERTEX_SHADER = 35633;
final int GL_FRAGMENT_SHADER = 35632;

String[] vshaderSource = new String[3];
String[] fshaderSource = new String[4];

class Wnd implements GLEventListener {

  public int renderingProgram = -1;
  int vao[] = new int[1];

  Wnd() {
    JFrame frame = new JFrame("OpenGL Demo");
    frame.setBounds(200, 200, 600, 400);
    myCanvas = new GLCanvas();
    myCanvas.addGLEventListener(this);    
    frame.add(myCanvas);
    frame.setVisible(true);
  }

  void display(GLAutoDrawable drawable) {
    GL4 gl = (GL4)GLContext.getCurrentGL();
    gl.glUseProgram(renderingProgram);

    // just to see if it loops
    int uniformLocation = gl.glGetUniformLocation(renderingProgram, "mytime");
    if (uniformLocation == -1)
      println("nouniform");
    else 
    gl.glUniform1f(uniformLocation, millis()/250.);

    gl.glDrawArrays(GL_POINTS, 0, 1);      
    //gl.glClearColor(1.0, 0.0, 0.0, 1.0);
    //gl.glClear(GL_COLOR_BUFFER_BIT);
    gl.glPointSize(30.0f);
  }

  void init(GLAutoDrawable drawable) {
    GL4 gl = (GL4)GLContext.getCurrentGL();   
    renderingProgram = createShaderProgram();    
    gl.glGenVertexArrays(vao.length, vao, 0);
    gl.glBindVertexArray(vao[0]);

    // Automatically init redraw 60fps synced 
    new FPSAnimator(myCanvas, 60, true).start();     
    println("initialized!");
  }
  void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
  }
  void dispose(GLAutoDrawable drawable) {
  }

  int createShaderProgram() {
    GL4 gl = (GL4)GLContext.getCurrentGL();

    String vshaderSource[] = {
      "#version 410   \n", 
      "void main(void)  \n", 
      "{gl_Position = vec4(0.0,0.0,0.0,1.0);} \n", 
    };

    String fshaderSource[] = {
      "#version 410   \n", 
      "out vec4 color;  \n", 
      "uniform float mytime;  \n", 
      "void main(void)  \n", 
      "{\n", 
      "float t = sin(mytime)*0.5+0.5;  \n", 
      "color = vec4(1.0-t,0.0,t,1.0);  \n", 
      "} \n", 
    };

    int vShader = gl.glCreateShader(GL_VERTEX_SHADER);
    gl.glShaderSource(vShader, vshaderSource.length, vshaderSource, null, 0);
    gl.glCompileShader(vShader);
    int fShader = gl.glCreateShader(GL_FRAGMENT_SHADER);
    gl.glShaderSource(fShader, fshaderSource.length, fshaderSource, null, 0);
    gl.glCompileShader(fShader);

    int vfProgram = gl.glCreateProgram();
    gl.glAttachShader(vfProgram, vShader);
    gl.glAttachShader(vfProgram, fShader);
    gl.glLinkProgram(vfProgram);

    gl.glDeleteShader(vShader);
    gl.glDeleteShader(fShader);

    return vfProgram;
  }
}

void setup() {
  surface.setVisible(false);
  javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      new Wnd();
      // no need to call disply as automatically called
      // if you call it here before init it will throw "No OpenGL context current on this thread"
      //wnd.display(drawable); // Builds components on EventDispatchThread
    }
  }
  );
}

PS: For P4 (resp. java 9+) regarding your InaccessibleObjectException above, you need to set the following java run.options in your preferences file to get it to run.

run.options=--add-exports java.base/java.lang=ALL-UNNAMED --add-exports java.desktop/sun.awt=ALL-UNNAMED --add-exports java.desktop/sun.java2d=ALL-UNNAMED

relates to: 1317 – JOGL AWT sample crashes on Java 9

ezgif.com-gif-maker (2)