Java Bindings for OpenGL: Difference between revisions

Content deleted Content added
script-assisted date audit and style fixes per MOS:NUM
 
(37 intermediate revisions by 22 users not shown)
Line 1:
{{refimprove|date=August 2010}}
'''Java Binding for the OpenGL API''' is a [[Java Community Process|JSR]] [[API]] specification for the [[Java SE]] platform which allows to use [[OpenGL]] on the [[Java Platform]].
{{example farm|date=August 2010}}
{{Use mdy dates|date=March 2025}}
'''Java Binding for the OpenGL API''' is a [[Java Community Process|JSR]] [[API]] specification (JSR 231) for the [[Java SEPlatform, Standard Edition]] platform which allows to use [[OpenGL]] on the [[Java Platform(software platform)]].<ref>{{cite web
| url=http://jcp.org/en/jsr/detail?id=231
| title=JSR 231: JavaBinding for the OpenGL API
| publisher=[[Java Community Process]]
| accessdate=February 6, 2011}}</ref> There is also '''Java Binding for the OpenGL ES API''' (JSR 239) for the [[Java Platform, Micro Edition]].
 
== Programming concepts ==
Core OpenGL API and [[OpenGL Utility Library|GLU]] library calls are available from [[Java (programming language)|Java]] through a thin wrapper looking very much as the original OpenGL [[C (programming language)|C]] API, Except GLU [[Nonuniform rational B-spline|NURBS]] routines which are not exposed through the public API.
 
All platform specific libraries (available from the [[AppleCore GLOpenGL|AGLCGL]] API for [[Mac OS X]], [[GLX]] for [[X Window System]], and [[WiggleWin32WGL (software)|WGL]] for [[Microsoft Windows]]) are also abstracted out to create a platform independent way of selecting [[Framebuffer]] attributes 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 the [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLBase.html#getPlatformGLExtensions%28%29 GL.getPlatformGLExtensions()] {{Webarchive|url=https://web.archive.org/web/20110217002436/http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLBase.html#getPlatformGLExtensions%28%29 |date=February 17, 2011 }} and [http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLBase.html#getExtension%28java.lang.String%29 GL.getExtension(String)] {{Webarchive|url=https://web.archive.org/web/20110217002436/http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLBase.html#getExtension%28java.lang.String%29 |date=February 17, 2011 }} method calls which return Objects whose data types are specific to the given implementation.
 
==Example==
This examplesexample shows how to draw a Polygonpolygon (without initialization or repaint code) .<ref>Borrowed from the [http://nehe.gamedev.net/lesson.asp?index=01 Nehe tutorial] {{Webarchive|url=https://web.archive.org/web/20070406193934/http://nehe.gamedev.net/lesson.asp?index=01 |date=April 6, which2007 }}, whose code areis free to use elsewhere.</ref>. Here is the reference [[C (programming language)|C]] implementation :
<syntaxhighlight lang="c">
int DrawGLScene(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
Line 17 ⟶ 27:
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();
gl.glFlush();
return TRUE;
}
</syntaxhighlight>
 
Which translates to the following [[Java (programming language)|Java]] implementation :
<syntaxhighlight lang="java">
public void display([http://download.java.net/media/jogl/builds/nightly/javadoc_public/javax/media/opengl/GLAutoDrawable.html GLAutoDrawable] gLDrawable) {
public void display(GLAutoDrawable glDrawable) {
final [http://download.java.net/media/jogl/builds/nightly/javadoc_public/javax/media/opengl/GL.html GL] gl = [http://download.java.net/media/jogl/builds/nightly/javadoc_public/javax/media/opengl/GLAutoDrawable.html#getGL() gLDrawable.getGL()];
final GL gl = 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();
}
</syntaxhighlight>
 
== Implementations ==
*[[Java OpenGL]] : The reference implementation, available on [[Microsoft Windows]], [[Linux]], [[Mac OS X]], and [[Solaris (operating system)|Solaris]] platforms.<ref>{{cite web
| url=http://jcp.org/aboutJava/communityprocess/final/jsr231/index.html
 
| title=JSR-000231 Java Bindings for the OpenGL API
== References ==
| publisher=[[Java Community Process]]
<References/>
| quote=''In order to facilitate maximum community participation for the Java Binding for the OpenGL API, we use the JOGL project on java.net found at 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.''
| accessdate=February 6, 2011}}</ref>
 
== See also ==
*[[OpenGL]]
*[[Java Community Process]]
 
== References ==
{{Reflist}}
 
== External links ==
* [http://www.jcp.org/en/jsr/detail?id=231 JSR web page for Java Binding for the OpenGL API]
* [http://www.jcp.org/en/jsr/detail?id=239 JSR web page for Java Binding for the OpenGL ES API]
* [httpshttp://jogljogamp.dev.java.netorg/ JOGL home page]
* [http://downloadjogamp.java.netorg/mediadeployment/jogljogamp-next/buildsjavadoc/nightlyjogl/javadoc_publicjavadoc/overview-summary.html JSR 231 Specification (draft)]
 
{{Java desktop}}
 
{{DEFAULTSORT:Java Bindings For Opengl}}
[[Category:Java platform]]
[[Category:Java specification requests]]
[[Category:ApplicationJava programming interfacesAPIs]]