Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on...
-
Upload
pauline-franklin -
Category
Documents
-
view
224 -
download
0
description
Transcript of Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on...
![Page 1: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/1.jpg)
Introduce Jogl
![Page 2: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/2.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/3.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/4.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/5.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/6.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/7.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/8.jpg)
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…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/9.jpg)
Put them all together
![Page 10: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/10.jpg)
Animate them
![Page 11: Introduce Jogl. Outline What is Jogl Jogl coding template Create a GLPanel Draw a 2D object on GLPanel…](https://reader035.fdocuments.us/reader035/viewer/2022062402/5a4d1c117f8b9ab0599f703e/html5/thumbnails/11.jpg)
Questions?