Jump to content

Java Bindings for OpenGL

From Wikipedia, the free encyclopedia

Java Binding for the OpenGL APIis aJSRAPIspecification (JSR 231) for theJava Platform, Standard Editionwhich allows to useOpenGLon theJava (software platform).[1]There is alsoJava Binding for the OpenGL ES API(JSR 239) for theJava Platform, Micro Edition.

Programming concepts

[edit]

Core OpenGL API andGLUlibrary calls are available fromJavathrough a thin wrapper looking very much as the original OpenGLCAPI, Except GLUNURBSroutines which are not exposed through the public API.

All platform specific libraries (available from theCGLAPI forMac OS X,GLXforX Window System,andWGLforMicrosoft Windows) are also abstracted out to create a platform independent way of selectingFramebufferattributes and performing platform specific Framebuffer operations.

Platform-specific extensions are not included in the public API. Each implementation can choose to export some of these APIs via theGL.getPlatformGLExtensions()andGL.getExtension(String)method calls which return Objects whose data types are specific to the given implementation.

Example

[edit]

This example shows how to draw a polygon (without initialization or repaint code).[2]Here is the referenceCimplementation:

intDrawGLScene(GLvoid){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);// Move Left 1.5 Units
glBegin(GL_TRIANGLES);//Drawing Using Triangles
glVertex3f(0.0f,1.0f,0.0f);// Top
glVertex3f(-1.0f,-1.0f,0.0f);// Bottom Left
glVertex3f(1.0f,-1.0f,0.0f);// Bottom Right
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);// Draw A Quad
glVertex3f(-1.0f,1.0f,0.0f);// Top Left
glVertex3f(1.0f,1.0f,0.0f);// Top Right
glVertex3f(1.0f,-1.0f,0.0f);// Bottom Right
glVertex3f(-1.0f,-1.0f,0.0f);// Bottom Left
glEnd();
glFlush();
returnTRUE;
}

Which translates to the followingJavaimplementation:

publicvoiddisplay(GLAutoDrawableglDrawable){
finalGLgl=glDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f,0.0f,-6.0f);// Move Left 1.5 Units
gl.glBegin(GL.GL_TRIANGLES);// Drawing Using Triangles
gl.glVertex3f(0.0f,1.0f,0.0f);// Top
gl.glVertex3f(-1.0f,-1.0f,0.0f);// Bottom Left
gl.glVertex3f(1.0f,-1.0f,0.0f);// Bottom Right
gl.glEnd();
gl.glTranslatef(3.0f,0.0f,0.0f);
gl.glBegin(GL.GL_QUADS);// Draw A Quad
gl.glVertex3f(-1.0f,1.0f,0.0f);// Top Left
gl.glVertex3f(1.0f,1.0f,0.0f);// Top Right
gl.glVertex3f(1.0f,-1.0f,0.0f);// Bottom Right
gl.glVertex3f(-1.0f,-1.0f,0.0f);// Bottom Left
gl.glEnd();
gl.glFlush();
}

Implementations

[edit]

See also

[edit]

References

[edit]
  1. ^"JSR 231: JavaBinding for the OpenGL API".Java Community Process.Retrieved2011-02-06.
  2. ^Borrowed from theNehe tutorial,whose code is free to use elsewhere.
  3. ^"JSR-000231 Java Bindings for the OpenGL API".Java Community Process.Retrieved2011-02-06.In order to facilitate maximum community participation for the Java Binding for the OpenGL API, we use the JOGL project on java.net found athttps://jogl.dev.java.net.The JOGL source code can be found there, licensed under a liberal source code license (mostly licensed as BSD except where we use other parties' licensed code). We take a snapshot of the code from this project every few months, run the Technology Compatibility Kit on the source code, and then officially make it the Reference Implementation for each formal Java Binding for the OpenGL API release.
[edit]