Michael Bien's Weblog don't panic http://michael-bien.com/mbien/feed/entries/atom 2010-12-29T11:11:15+01:00 Apache Roller (incubating) http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained JOGL 2 - OpenGL Profiles explained mbien 2009-08-22T20:20:41+02:00 2010-06-16T21:13:09+02:00 <p> <b>June 16 2010, updated blogpost: OpenGL 4</b> </p> <p> JOGL 2 supports several OpenGL Profiles. In this blog entry I try to explain what profiles are and why they are needed.</p><h3>History</h3><p>SGI released the first OpenGL specification 1992. Since this point OpenGL 1.x constantly evolved (under the ARB and later Khronos Group) by adding new functions to the core API. This went well until programmable graphics hardware became mainstream and shaders became suddenly more flexible and efficient as the generic fixed function pipeline.</p><p> OpenGL 2.x was the last version in which you could freely mix the fixed function pipeline with the programmable pipeline (as a core feature).</p> <a href="http://www.khronos.org/news/press/releases/khronos-releases-opengl-3.2-third-major-opengl-release-within-twelve-months/"> <img src="http://www.opengl.org/img/uploads/news/OpenGL-3-evolution_sml.jpg" class="left" alt=""/></a> <p> With the release of OpenGL 3.0 the whole fixed function pipeline has been deprecated but you could still use it if you haven't requested a forward compatible context.</p><p> OpenGL 3.1 and 3.2 removed most deprecated functionality from core specification, however some implementations (e.g. Nvidia drivers) still allow to get them back via an optional compatibility extension. Since 3.1 was the first release which broke compatibility, it is often seen as major OpenGL 3 release. <br /></p> <h3>JOGL 2 (JSR 231)<br /></h3> <p>JOGL 1.1.1 lived in the timeframe up to OpenGL 3.0 which made it easy to stay in sync with the spec. To be able to solve the issue with the deprecation of functionality, JOGL 2 (JSR maintenance release) introduces an abstraction of the original OpenGL versioning called Profile. Profiles allow Java applications to be written in a way which allows compatibility with multiple OpenGL versions at the same time. Since OpenGL ES (GL for embedded systems) has overlapping functionality with OpenGL itself it opened the opportunity to add even Profiles which bridge desktop and embedded implementations. The class diagram below shows the dependencies between <a href="http://jogamp.org/jogl/doc/bouml/html-svg/">all available Profiles</a>.<br /> </p> <p> <embed src="http://jogamp.org/jogl/doc/bouml/html-svg/fig128069.svg" width="735" height="600"/> </p> <p> Before you start writing a JOGL application you will have to decide first which GLProfile you want to use. The code snippet below lists all currently supported profiles (extracted from <a href="http://jogamp.org/deployment/jogl-next/javadoc_public/javax/media/opengl/GLProfile.html">GLProfile</a>). </p> <br/> <h3>Current list of supported profiles and their mapping to the implementation versions</h3> <pre class="brush: java;"> /** The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.<br> <code>bc</code> stands for backward compatibility. */ public static final String GL4bc = "GL4bc"; /** The desktop OpenGL core profile 4.x, with x >= 0 */ public static final String GL4 = "GL4"; /** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.<br> <code>bc</code> stands for backward compatibility. */ public static final String GL3bc = "GL3bc"; /** The desktop OpenGL core profile 3.x, with x >= 1 */ public static final String GL3 = "GL3"; /** The desktop OpenGL profile 1.x up to 3.0 */ public static final String GL2 = "GL2"; /** The embedded OpenGL profile ES 1.x, with x >= 0 */ public static final String GLES1 = "GLES1"; /** The embedded OpenGL profile ES 2.x, with x >= 0 */ public static final String GLES2 = "GLES2"; /** The intersection of the desktop GL2 and embedded ES1 profile */ public static final String GL2ES1 = "GL2ES1"; /** The intersection of the desktop GL3, GL2 and embedded ES2 profile */ public static final String GL2ES2 = "GL2ES2"; /** The intersection of the desktop GL3 and GL2 profile */ public static final String GL2GL3 = "GL2GL3"; </pre> <p> <i>Note: GL2 Profile supports OpenGL up to version 3.0 (included) - this is not a bug: OpenGL 3.1 was the big game changer</i> </p> <p> The next two code snippets show the basic steps how to set up OpenGL with JOGL 2. </p> <h3>Context creation</h3> <pre class="brush: java;"> //create a profile, in this case OpenGL 3.1 or later GLProfile profile = GLProfile.get(GLProfile.GL3); //configure context GLCapabilities capabilities = new GLCapabilities(profile); capabilities.setNumSamples(2); // enable anti aliasing - just as a example capabilities.setSampleBuffers(true); //initialize a GLDrawable of your choice GLCanvas canvas = new GLCanvas(capabilities); //register GLEventListener canvas.addGLEventListener(...); //... (start rendering thread -> start rendering...) </pre> <br/> <h3>Rendering</h3> <pre class="brush: java;"> public void display(GLAutoDrawable drawable) { GL3 gl = drawable.getGL().getGL3(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); //.. render something } </pre> <h3>Summary</h3> <p> Profiles make JOGL 2 very flexible and allow it to build modular and portable applications. For instance part A of an application can be written against the GL2ES2 interface and part B (which is more hardware specific) against the GL3 interface. This would in theory allow to reuse A in an embedded application and B could e.g. disable itself on old desktop hardware which runs only OpenGL 2.x or fall back to a GL2 implementation. </p> <p> More information can be found on <a href="http://jogamp.org">JogAmp.org</a> (<a href="http://jogamp.org/deployment/jogl-next/javadoc_public/">direct link to javadoc</a>) </p> <p> The next release of the <a href="http://kenai.com/projects/netbeans-opengl-pack">OpenGL Pack</a> for NetBeans will fully support JOGL 2. Beta builds can be found <a href="http://projectkenai.com/projects/netbeans-opengl-pack/downloads/directory/early-access">here</a> (builds contain JOGL2 beta5): </p> http://michael-bien.com/mbien/entry/using_the_wiiremote_for_headtracking Using the WiiRemote for headtracking and cool 3D effects mbien 2007-12-31T00:20:05+01:00 2007-12-31T00:25:22+01:00 <p><p>Chung Lee <a target="_blank" href="http://youtube.com/watch?v=Jd3-eiid-Uw">demonstrates and explains</a> how you can use a WiiRemote for headtracking and how this technique could be used for view dependent 3D effects on your desktop- or TV screen. Awesome!<br /></p><p>I will try it out with my own 3D engine as soon as I have a WiiRemote or similar hardware. It should be easy to implement since the whole 3D illusion is based on simple matrix manipulation (projection matrix) of the rendering pipeline. The WiiRemote could be accessed with <a href="https://jinput.dev.java.net/">JInput</a>. </p><p>But first I have to write some exams ;)<br /></p></p>