Login  Register

1282 Error after calling glUseProgram()

Posted by Felipe on Sep 05, 2019; 9:40pm
URL: https://forum.jogamp.org/1282-Error-after-calling-glUseProgram-tp4040040.html

Hello

Below is the full code of a program I'm trying to run in a macbook pro 2015. It is basically just trying to print
a single dot in the center. The problem is that right after calling glUseProgram() I get the 1282 error.
Can anybody help me spot any errors in the shader code?

package com.noatechnologies.tutorials.opengl3;
import static com.jogamp.opengl.GL.GL_NO_ERROR;
import static com.jogamp.opengl.GL.GL_VERSION;
import static com.jogamp.opengl.GL4.*;
import javax.swing.JFrame;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;

/**
 * Copied from the book: Computer Graphics Programming in OpenGL with Java, 1st
 * Edition Program 2.2
 *
 * @author Felipe
 * @version Sep 3, 2019 5:31:57 PM
 */
public class Code_Program2_2 extends JFrame implements GLEventListener {
        private GLCanvas myCanvas;
        private int rendering_program;
        private int vao[] = new int[1];

        public Code_Program2_2() {
                setTitle("Chapter2 - program2.2");
                setSize(600, 400);
                setLocation(200, 200);
                /*Following code I got it from: http://forum.jogamp.org/GL4-not-working-in-JOGL-macbook-pro-td4040031.html
                 * This is actually a question I made. Sept. 5, 2019 3:46PM
                 */
                final GLProfile profile = GLProfile.get(GLProfile.GL4);
            final GLCapabilities glcapabilities = new GLCapabilities(profile);
                myCanvas = new GLCanvas(glcapabilities);

                myCanvas.addGLEventListener(this);
                this.add(myCanvas);
                setVisible(true);
        }

        public void display(GLAutoDrawable drawable) {
                GL4 gl = (GL4) GLContext.getCurrentGL();
                checkGLError(gl);
                gl.glUseProgram(rendering_program);
                checkGLError(gl);
                gl.glDrawArrays(GL_POINTS, 0, 1);
                checkGLError(gl);
        }

        public static void main(String[] args) {
                new Code_Program2_2();
        }

        public void init(GLAutoDrawable drawable) {
                GL4 gl = (GL4) GLContext.getCurrentGL();
                String glVersion=gl.glGetString(GL_VERSION)  ;
                System.out.println("glVersion="+glVersion);

                checkGLError(gl);
                rendering_program = createShaderProgram();
                checkGLError(gl);
                gl.glGenVertexArrays(vao.length, vao, 0);
                checkGLError(gl);
                gl.glBindVertexArray(vao[0]);
                checkGLError(gl);
        }

        private int createShaderProgram() {
                GL4 gl = (GL4) GLContext.getCurrentGL();
                String vshaderSource[] = { "#version 430 \n", "void main(void) \n",
                                "{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); } \n", };
                String fshaderSource[] = { "#version 430 \n", "out vec4 color; \n",
                                "void main(void) \n",
                                "{ color = vec4(0, 0.0, 1, 1.0); } \n", };
               
                int vShader = gl.glCreateShader(GL_VERTEX_SHADER);
                checkGLError(gl);
                gl.glShaderSource(vShader, 3, vshaderSource, null, 0);
                checkGLError(gl);
                gl.glCompileShader(vShader);
                checkGLError(gl);
                int fShader = gl.glCreateShader(GL_FRAGMENT_SHADER);
                checkGLError(gl);
                gl.glShaderSource(fShader, 4, fshaderSource, null, 0);
                checkGLError(gl);
                gl.glCompileShader(fShader);
                checkGLError(gl);
                int vfprogram = gl.glCreateProgram();
                checkGLError(gl);
                gl.glAttachShader(vfprogram, vShader);
                checkGLError(gl);
                gl.glAttachShader(vfprogram, fShader);
                checkGLError(gl);
                gl.glLinkProgram(vfprogram);
                checkGLError(gl);
                gl.glDeleteShader(vShader);
                checkGLError(gl);
                gl.glDeleteShader(fShader);
                checkGLError(gl);
               
               
               

                return vfprogram;
        }

       
        /**
         *
         * @throws Exception
         * @author Felipe
         * @version Sep 4, 2019 9:36:30 PM
         */
        public void checkGLError(GL gl)throws Error
        {
                int glError=gl.glGetError();
                if(glError!=GL_NO_ERROR)
                {
                        throw new Error("Invalid: GL error="+glError+" found");
                }

        }
        public void reshape(GLAutoDrawable drawable, int x, int y, int width,
                        int height) {
        }

        public void dispose(GLAutoDrawable drawable) {
        }
}