introduce jogl. outline what is jogl jogl coding template create a glpanel draw a 2d object on...

11
Introduce Jogl

Upload: pauline-franklin

Post on 20-Jan-2018

224 views

Category:

Documents


0 download

DESCRIPTION

What is Jogl It is a wrapper graphics library that allows OpenGL to be used in Java. Some online demos: – https://jogl-demos.dev.java.net/https://jogl-demos.dev.java.net/ worldbuilder/

TRANSCRIPT

Page 1: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Introduce Jogl

Page 2: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Outline• What is Jogl• Jogl coding template• Create a GLPanel• Draw a 2D object on GLPanel• Draw texts on GLPanel• Draw a 3D object on GLPanel

Page 3: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

What is Jogl• It is a wrapper graphics library that allows

OpenGL to be used in Java.• Some online demos:

– https://jogl-demos.dev.java.net/

http://www.codededge.com/elflightengine/tools/worldbuilder/ http://bytonic.de/html/screenshots_0.html

Page 4: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Jogl coding templateJFarme

GLPanel

+ GLEventListener

init()display()reshape()displayChanged()

Your drawing functions, used in display()

drawA2DBall()drawA3DSphere()drawText()

Page 5: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Create a GLPanelpublic class JOGL3DBasics { JOGLDemo() { GLJPanel panel = getGLJPanel(); panel.addGLEventListener(new MyGLEventListener()); JFrame frame = new JFrame(); frame.getContentPane().add(panel); }

class MyGLEventListener { void init() {…} void display() {…} void reshape() [] {…} void displayChanged() {…} }

public static void main() { // create a JOGL3DBasics object }} // end of class

Page 6: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Draw a 2D objectvoid draw2DObject(GL gl) { gl.glColor3f(1, 0, 0); gl.glRecti(-SIZE / 2, -SIZE / 2, SIZE / 2, SIZE / 2);}

void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); // clean panel draw2DObject(gl);}

Page 7: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Draw textsCreate a TextRenderer object, called renderer.

void drawTexture(GLAutoDrawable drawable) { renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); renderer.setColor(1.0f, 0.1f, 0.8f, 0.8f); renderer.draw("Jogl Demo for CPSC 332", 80, 60); renderer.endRendering();}

Page 8: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Draw a 3D objectCreate a TextRenderer object, called renderer.

void drawTexture(GLAutoDrawable drawable) { renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); renderer.setColor(1.0f, 0.1f, 0.8f, 0.8f); renderer.draw("Jogl Demo for CPSC 332", 80, 60); renderer.endRendering();}

Page 9: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Put them all together

Page 10: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Animate them

Page 11: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…

Questions?