Jogl API Overview: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
Before starting, you should know that the JOGL API is not a young API, this means that there are some things that are old, so you should always evaluate what you are looking at.
Before starting, you should know that the JOGL API is not a young API, this means that there are some things that are (very) old, so you should always evaluate what you are looking at.


We will reference all the links to the principle [http://jogamp.org/git/?p=jogl.git;a=tree;hb=HEAD jogamp server], but you can click also on the GitHub version ([https://github.com/sgothel/jogl GH]) for a better layout and highlighting.
We will reference the links giving the priority to the main [http://jogamp.org/git/?p=jogl.git;a=tree;hb=HEAD jogamp server], but you can click also on the GitHub version ([https://github.com/sgothel/jogl GH]) for a better layout, font and support for highlighting or on the API docs ([http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/ AD]).


You can find the most interesting part under [http://jogamp.org/git/?p=jogl.git;a=tree;f=src/jogl/classes/com/jogamp/opengl;h=1b5d1802174cbd371560c9c786039870dcb106fa;hb=HEAD com.jogamp.opengl]
__TOC__
 
<h5> Preface </h5>
 
The JOGL API offers a lots of deep and detailed utilities for almost all the possible needs regarding OpenGL but most of them aren't used simply because people ignore about their existence. This small overview aims to alleviate this problem.


__TOC__
You can find the most interesting part under [http://jogamp.org/git/?p=jogl.git;a=tree;f=src/jogl/classes/com/jogamp/opengl;h=1b5d1802174cbd371560c9c786039870dcb106fa;hb=HEAD com.jogamp.opengl] ([https://github.com/sgothel/jogl/tree/master/src/jogl/classes/com/jogamp/opengl GH]).
 
<h3> Shaders </h3>
 
[http://jogamp.org/git/?p=jogl.git;a=tree;f=src/jogl/classes/com/jogamp/opengl/util/glsl;h=8e0f6ddfb2817836db16f26ecc8967553d8b6bd7;hb=HEAD com.jogamp.opengl.util.glsl] ([https://github.com/sgothel/jogl/tree/master/src/jogl/classes/com/jogamp/opengl/util/glsl GH]).
 
You can create your own GLSL program in JOGL by simply calling:
<code>
    private int initProgram(GL4 gl4) {
        ShaderCode vertexShader = ShaderCode.create(gl4, GL4.GL_VERTEX_SHADER, this.getClass(), "src/data", null, "simple", "vert", null, true);
        ShaderCode fragmentShader = ShaderCode.create(gl4, GL4.GL_FRAGMENT_SHADER, this.getClass(), "src/data", null, "simple", "frag", null, true);
        ShaderProgram program = new ShaderProgram();
        program.add(vertexShader);
        program.add(fragmentShader);
        program.link(gl4, System.out);
        return program.program();
    }
</code>
 
You can init vertex, fragment, geometry, tesselation control and tesselation evaluation shaders (compute will be implemented soon) using [http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java;h=e1db3f7a3467c57ebddbafcda52eddc154c4866b;hb=HEAD ShaderCode.create] ([https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java#L683-L689 GH] [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/glsl/ShaderCode.html AD]).
For the vertex shader, note that <code>"simple"</code> is the name and "vert" is the custom suffix. You need to specify that if your shaders suffices differ from [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java#L77-L117 these].
 
The two <code>null</code> refer to the path for the binary shaders and the name. If the shaders are located in the same package of the <code>class.initProgram(gl4)</code> you can pass  <code>null</code> also on the src path.
 
Then you can create the class ShaderProgram, but please note that this has nothing to do with OpenGL, it is just Java side.
 
Finally we can add the created shaders into our Program and link it. This last call is important because it is here that our program will be [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L242 initialized] on OpenGL and [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L259 linked].
 
The function will also check at the end if everything [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L261 went fine] or not.
 
Please note that the program id/name [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L321 <code>shaderProgram</code>] is obtained through the [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L54 program() method], the [https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java#L59 <code>id()</code> method] has nothing to do with it.


API docs: [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/glsl/ShaderCode.html ShaderCode] [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/glsl/ShaderProgram.html ShaderProgram] [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/glsl/ShaderState.html ShaderState] [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/glsl/ShaderUtil.html ShaderUtil]


<h5> Shaders </h5>
<h3> Textures </h3>

Latest revision as of 11:45, 26 July 2015

Before starting, you should know that the JOGL API is not a young API, this means that there are some things that are (very) old, so you should always evaluate what you are looking at.

We will reference the links giving the priority to the main jogamp server, but you can click also on the GitHub version (GH) for a better layout, font and support for highlighting or on the API docs (AD).

Preface

The JOGL API offers a lots of deep and detailed utilities for almost all the possible needs regarding OpenGL but most of them aren't used simply because people ignore about their existence. This small overview aims to alleviate this problem.

You can find the most interesting part under com.jogamp.opengl (GH).

Shaders

com.jogamp.opengl.util.glsl (GH).

You can create your own GLSL program in JOGL by simply calling:

   private int initProgram(GL4 gl4) {
       ShaderCode vertexShader = ShaderCode.create(gl4, GL4.GL_VERTEX_SHADER, this.getClass(), "src/data", null, "simple", "vert", null, true);
       ShaderCode fragmentShader = ShaderCode.create(gl4, GL4.GL_FRAGMENT_SHADER, this.getClass(), "src/data", null, "simple", "frag", null, true);
       ShaderProgram program = new ShaderProgram();
       program.add(vertexShader);
       program.add(fragmentShader);
       program.link(gl4, System.out);
       return program.program();
   }

You can init vertex, fragment, geometry, tesselation control and tesselation evaluation shaders (compute will be implemented soon) using ShaderCode.create (GH AD). For the vertex shader, note that "simple" is the name and "vert" is the custom suffix. You need to specify that if your shaders suffices differ from these.

The two null refer to the path for the binary shaders and the name. If the shaders are located in the same package of the class.initProgram(gl4) you can pass null also on the src path.

Then you can create the class ShaderProgram, but please note that this has nothing to do with OpenGL, it is just Java side.

Finally we can add the created shaders into our Program and link it. This last call is important because it is here that our program will be initialized on OpenGL and linked.

The function will also check at the end if everything went fine or not.

Please note that the program id/name shaderProgram is obtained through the program() method, the id() method has nothing to do with it.

API docs: ShaderCode ShaderProgram ShaderState ShaderUtil

Textures