I'm trying to run the program in a 2015 Macbook pro.
The GL version is: glVersion=4.1 INTEL-12.8.38 And the gl error code that I'm getting right after executing the line gl.glUseProgram(rendering_program); is: 1282 It supposedly stands for "Invalid Operation". No idea what I'm doing wrong to be honest. If anybody could offer some hints on how to debug it I would be much greateful. 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.GL3.*; import javax.swing.JFrame; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL3; import com.jogamp.opengl.GL4; //import com.jogamp.opengl.GL3; 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; import com.noatechnologies.j2se.Log; /** * Copied from the book: Computer Graphics Programming in OpenGL with Java, 1st * Edition Program 2.2 * * @author * @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.GL3); final GLCapabilities glcapabilities = new GLCapabilities(profile); myCanvas = new GLCanvas(glcapabilities); myCanvas.addGLEventListener(this); this.add(myCanvas); setVisible(true); } public static void main(String[] args) { new Code_Program2_2(); } public void display(GLAutoDrawable drawable) { GL3 gl = (GL3) GLContext.getCurrentGL(); checkGLError(gl); gl.glUseProgram(rendering_program); checkGLError(gl); gl.glDrawArrays(GL_POINTS, 0, 1); checkGLError(gl); } public void init(GLAutoDrawable drawable) { GL3 gl = (GL3) 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() { GL3 gl = (GL3) GLContext.getCurrentGL(); String vshaderSource[ ] = { "#version 430 \n", "void main(void) \n", "{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); } \n", }; printArray(vshaderSource); String fshaderSource[ ] = { "#version 430 \n", "out vec4 color; \n", "void main(void) \n", "{ color = vec4(0.0, 0.0, 1.0, 1.0); } \n", }; printArray(fshaderSource); checkGLError(gl); int vShader = gl.glCreateShader(GL_VERTEX_SHADER); 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; } /** * * @param array * @author Mora * @version Feb 21, 2022 9:17:12 AM */ public void printArray(String[] array) { for(int i=0;i<array.length;i++) { Log.printDebugMsg(array[i]); } } /** * * @throws Exception * @author * @version Sep 4, 2019 9:36:30 PM */ public void checkGLError(GL gl)throws Error { int glError=gl.glGetError(); if(glError!=GL_NO_ERROR) { //GL4 gl4 = (GL4) //gl.gluErrorString(glError); //gl.glGetError() 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) { } } |
Never mind. I finally figure out what was wrong!
Turns out that the shader was not being compiled. I had to use this code to check if the shader had compiled successfully: { int[] out={3}; gl.glCompileShader(vShader); gl.glGetShaderiv(vShader, GL3.GL_COMPILE_STATUS, out, 0);//the zero is the array offset, where the function should start storing the information Log.printDebugMsg("out="+out[0]); int result=out[0]; if(result==GL3.GL_TRUE) Log.printDebugMsg("Everything is good"); else if(result==GL3.GL_FALSE) throw new Error("Shader not compiled correctly"); else throw new Error("Should not be here"); } After it returned false then I check the shading code and changed the version to #version 150 and that did the trick. I guess my computer does not support version 430. |
Macs froze their OpenGL support at 4.10. So rather than change to 1.5, try changing to 4.1 instead.
Here is a writeup I did to show how to get programs written for version 4.3 (and later) to run on the Mac: https://athena.ecs.csus.edu/~gordonvs/errataMac.html |
Administrator
|
We'll have to find a solution on the long term, WebGPU or Vulkan.
Julien Gouesse | Personal blog | Website
|
I wonder if "ANGLE" is an option for the future:
https://en.wikipedia.org/wiki/ANGLE_(software) It seems like Google/Chrome and Apple/Safari are both supporting it to get OpenGL/WebGL support on multiple platforms. |
Administrator
|
Yes Angle could be an option if and only if it remained actively maintained under OS X.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |