GLSL and GLU Teapot

Started by
17 comments, last by Glass_Knife 10 years, 1 month ago

Well I can't help you with JOGL but with LWJGL its more or less like:

ContextAttribs cAttribs = new ContextAttribs(3,3).withProfileCore(true); // Object containing context data.
PixelFormat pFormat = new PixelFormat(8,24,8); // 8 bit alpha, 8 bit stencil, 24 bit depth.
 
Display.create(pFormat, cAttribs); // Create the window with a context and pixel format.

And that should be it. You can set a specific display mode (ie, resolution, refresh rate) after creating the display or before, its up to you.

Are you sure about the version of the context you're running on? JOGL should provide some method to check that.

Now that I remember... I think I saw an user with similar issues, the shader compiler complained about the layout qualifiers, so he had to enable the extension by hand in the shader. I think the syntax for enabling GLSL extension was to insert this line on the shaders:

#extension ARB_explicit_attrib_location : enable

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Advertisement
It used to be that Mac only supported OGL 3.2 (there was a fakery way to make the OS believe it has 3.3, not sure whether there has been any official support added) - which iirc does not have attribute layout location in core. The extension of it might be available though, as TheCubu noted.

Glass_Knife, i did not notice you telling how the "Not working" manifests itself? What is the error message given? Are you sure you have OGL 3.3 available in the first place?


Are you sure about the version of the context you're running on? JOGL should provide some method to check that.

I have looked at that stuff, but the docs are sketchy. I though jwjgl looked more promising but didn't see how it would integrate with a swing application.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532


Glass_Knife, i did not notice you telling how the "Not working" manifests itself? What is the error message given? Are you sure you have OGL 3.3 available in the first place?

I'm a moderator. We don't have problems, we fix them. :-)


#version 330

layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;
out vec4 theColor;

void main()
{
	gl_Position = position;
	theColor = color;
}

Here is the error for the shader:


Compile failure in fragment shader:
ERROR: 0:3: Invalid use of layout 'location'
ERROR: 0:4: Invalid use of layout 'location'
ERROR: 0:9: Use of undeclared identifier 'gl_Position'
ERROR: 0:9: Use of undeclared identifier 'position'
ERROR: 0:10: Use of undeclared identifier 'color'

And so if you're working on this at midnight, you won't notice that you're getting fragment shader errors for your vertex shader. ;-)

But that still hasn't solved the profile issue.


Exception in thread "AWT-EventQueue-0-AWTAnimator" java.lang.RuntimeException: javax.media.opengl.GLException: Not a GL2 implementation
	at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
	at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
	at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
	at javax.media.opengl.Threading.invoke(Threading.java:191)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:75)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:416)
	at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:188)
	at java.lang.Thread.run(Thread.java:744)

I just haven't figured out the magical formula. But progress is happening...

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

And so if you're working on this at midnight, you won't notice that you're getting fragment shader errors for your vertex shader. ;-)

Reading what the error message says -> the path to victory biggrin.png

java.lang.RuntimeException: javax.media.opengl.GLException: Not a GL2 implementation

Looks like OGL2 implementation was asked for ... which i am fairly sure MacOS simply cannot give (unless backwards compatibility was added at some point - which i seriously doubt). Unfortunately, the last time i used OGL with Java i used LWJGL and i do not know anything about JOGL.

Perhaps, if the error message is to believe, you are not properly asking for the right OGL version - source dump of the relevant part might help.

Anyway, if Google is let to believe it should go fairly simply like this (the example i saw was for GL2, i just changed it to GL3 - i mean, should be good enough, right?):

GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
GLCanvas canvas = new GLCanvas(capabilities);

...

GL3 gl = drawable.getGL().getGL3();
gl.doFunkyStuff...
edit: Actually, i have no idea in what state Mac OGL support is nowadays - i think it should be able to support OGL2 when excluding OGL3 (ie. no backward compatibility option). Should not change anything in what i said though.

It used to be that Mac only supported OGL 3.2 (there was a fakery way to make the OS believe it has 3.3, not sure whether there has been any official support added) - which iirc does not have attribute layout location in core.

Explicit attrib location was made core in 3.3!? That explains a lot. I was sure it was a 3.2 core extension.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator


Looks like OGL2 implementation was asked for ... which i am fairly sure MacOS simply cannot give (unless backwards compatibility was added at some point - which i seriously doubt). Unfortunately, the last time i used OGL with Java i used LWJGL and i do not know anything about JOGL.

Yes, that seems to be the case. I fixed the capabilities code to ask for a profile, and everything seems to be working. What I had done was just ask for the default profile on my Linux box, without realizing that it would default to a backwards compatibility mode, but that the mac only supports the fixed-function pipeline OR shaders, but not both.

Switching the code to specifically use a GL3 profile caught and crashed when I tried to use the FFP, which means it is working, as far as I can tell.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Yay!, sweet - sweet progress :D

*high-five*

For reference, here is the working template swing app:


package tim.opengl.util;

import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.jogamp.opengl.util.Animator;

public class GLApp extends JFrame implements GLEventListener {
	
	private GLCanvas mainPanel;
	private Animator animator;
	protected GLUtil util = new GLUtil();
	
	public GLApp() {
		
	}
	
	private void createAndShowGUI() {
		
		setTitle( getAppTitle() );
		setSize( 640, 480 );
		Container canvas = getContentPane();
		canvas.add( getMainPanel() );
		
		preCreate();
		animator = new Animator();
		animator.add( getMainPanel() );
		setVisible( true );
		
		animator.start();
	}
	
	private GLCanvas getMainPanel() {
		if( mainPanel == null ) {
			if( !GLProfile.isAvailable( GLProfile.GL3 ) ) {
				throw new RuntimeException("GL3 not available");
			}
			GLProfile profile = GLProfile.get( GLProfile.GL3 );
			mainPanel = new GLCanvas( new GLCapabilities( profile ) );
			mainPanel.addGLEventListener( this );
		}
		return mainPanel;
	}
	
	protected String getAppTitle() {
		return "TBD";
	}
	
	protected void preCreate() {
		
	}
	
	public void onWindowClosing() {
        new Thread(new Runnable() {
            public void run() {
              animator.stop();
              System.exit(0);
            }
          }).start();
	}

	public static void launchApp( final GLApp app ) {
		app.addWindowListener( new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				app.onWindowClosing();
			}
		});
		SwingUtilities.invokeLater( new Runnable() {
			@Override
			public void run() {
				app.createAndShowGUI();
			}
		});
	}

	@Override
	public void display(GLAutoDrawable glad) {
		
	}

	@Override
	public void dispose(GLAutoDrawable glad) {
		
	}

	@Override
	public void init(GLAutoDrawable glad) {
		
	}

	@Override
	public void reshape(GLAutoDrawable glad, int x, int y, int ww, int hh) {
		
	}
}

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

This topic is closed to new replies.

Advertisement