3D Application and Game Development With OpenGL



Similar documents
Experiences with 2-D and 3-D Mathematical Plots on the Java Platform

Java game programming. Game engines. Fayolle Pierre-Alain

How To Teach Computer Graphics

A Short Introduction to Computer Graphics

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

JavaFX Session Agenda

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

The MaXX Desktop. Workstation Environment. Revised Road Map Version 0.7. for Graphics Professionals

Introduction to Computer Graphics

Optimizing AAA Games for Mobile Platforms

Game Programming with Groovy. James Sr. Software Engineer, BT/Ribbit

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Computer Graphics Hardware An Overview

Using jvmstat and visualgc to Solve Memory Management Problems

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

INTRODUCTION TO RENDERING TECHNIQUES

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

The Future Of Animation Is Games

Image Synthesis. Transparency. computer graphics & visualization

Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Computer Graphics on Mobile Devices VL SS ECTS

The Car Tutorial Part 1 Creating a Racing Game for Unity

Performance Optimization and Debug Tools for mobile games with PlayCanvas

<Insert Picture Here> Java, the language for the future

Low power GPUs a view from the industry. Edvard Sørgård

Creating Your Own 3D Models

OpenGL Performance Tuning

Dynamic Resolution Rendering

Introduction to Computer Graphics

3D VIRTUAL DESKTOP APPLICATION Of UNSW. Introduction. What we propose to do 2/4. What we propose to do 1/4. What we propose to do 4/4

Lecture 1 Introduction to Android

SketchUp Instructions

Computer Applications in Textile Engineering. Computer Applications in Textile Engineering

Fachbereich Informatik und Elektrotechnik SunSPOT. Ubiquitous Computing. Ubiquitous Computing, Helmut Dispert

Workstation Applications for Windows. NVIDIA MAXtreme User s Guide

Multiresolution 3D Rendering on Mobile Devices

Graphic Design. Background: The part of an artwork that appears to be farthest from the viewer, or in the distance of the scene.

SmartArrays and Java Frequently Asked Questions

OpenGL & Delphi. Max Kleiner. 1/22

NVIDIA IndeX Enabling Interactive and Scalable Visualization for Large Data Marc Nienhaus, NVIDIA IndeX Engineering Manager and Chief Architect

Course Overview. CSCI 480 Computer Graphics Lecture 1. Administrative Issues Modeling Animation Rendering OpenGL Programming [Angel Ch.

Adding Animation With Cinema 4D XL

Lecture Notes, CEng 477

Overview Motivation and applications Challenges. Dynamic Volume Computation and Visualization on the GPU. GPU feature requests Conclusions

Deferred Shading & Screen Space Effects

Writing Applications for the GPU Using the RapidMind Development Platform

How To Run A Factory I/O On A Microsoft Gpu 2.5 (Sdk) On A Computer Or Microsoft Powerbook 2.3 (Powerpoint) On An Android Computer Or Macbook 2 (Powerstation) On

Java (12 Weeks) Introduction to Java Programming Language

REAL-TIME IMAGE BASED LIGHTING FOR OUTDOOR AUGMENTED REALITY UNDER DYNAMICALLY CHANGING ILLUMINATION CONDITIONS

Web Based 3D Visualization for COMSOL Multiphysics

LibGDX játék fejlesztése és publikálása Google Play-en. Vörös Viktor, NNG

1. Overview of the Java Language

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

System Structures. Services Interface Structure

How To Learn To Program In Csc 406 Computer Graphics

Fundamentals of Java Programming

DATA VISUALIZATION OF THE GRAPHICS PIPELINE: TRACKING STATE WITH THE STATEVIEWER

Lezione 4: Grafica 3D*(II)

Beginning Android 4. Games Development. Mario Zechner. Robert Green

3D Stereoscopic Game Development. How to Make Your Game Look

m ac romed ia Fl a s h Curriculum Guide

Developing Applications for ios

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

L20: GPU Architecture and Models

Kathy Au Billy Yi Fan Zhou Department of Electrical and Computer Engineering University of Toronto { kathy.au, billy.zhou }@utoronto.

Introduction to Computer Graphics

Introduction to WebGL

APPENDICES. Appendix 1 Autodesk MapGuide Viewer R6 Help

Getting Started with CodeXL

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

DM810 Computer Game Programming II: AI. Lecture 11. Decision Making. Marco Chiarandini

Computer Graphics. Computer graphics deals with all aspects of creating images with a computer

Petascale Visualization: Approaches and Initial Results

CREATE A 3D MOVIE IN DIRECTOR

Operating System Structures

Hardware/Software Co-Design of a Java Virtual Machine

Mastering Mobile Web with 8 Key Rules. Mastering Mobile Web with 8 Key Rules

Programming 3D Applications with HTML5 and WebGL

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

Boundless Security Systems, Inc.

Enterprise Mobile Application Development: Native or Hybrid?

WebSphere Architect (Performance and Monitoring) 2011 IBM Corporation

Fundamentals of Computer Animation

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Chapter 2 - Graphics Programming with JOGL

Gursharan Singh Tatla Page No. 1 COMPUTER GRAPHICS (Short Answer type Questions)

iz3d Stereo Driver Description (DirectX Realization)

The Rocket Steam Locomotive - Animation

Transcription:

3D Application and Game Development With OpenGL java.sun.com/javaone/sf Daniel Petersen Kenneth Russell Sun Microsystems, Inc. 1

Presentation Goal Show how to build leading-edge 3D applications and games using the Java programming language and the OpenGL 3D API 2

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 3

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 4

Introduction OpenGL Powerful, cross-platform 3D API Industry standard for writing 3D applications and games On multiple platforms From multiple programming languages Supported by multiple vendors Provides access to latest hardware features Vertex and fragment programs Floating-point framebuffers 5

Introduction Java programming language OpenGL bindings A few bindings under active development LWJGL Game-focused OpenGL binding Single window Usually full-screen JOGL Integrates with AWT and Swing Relies on J2SE platform for, e.g., full-screen support Today s talk will use JOGL for examples 6

Introduction Java programming language OpenGL bindings Standardization effort underway One Java programming language binding to OpenGL Can be implemented by multiple vendors if desired Being developed under the Java Community Process SM service JSRs 231 and 239 7

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 8

JSR Update Overview What are JSR 231 and JSR 239 Benefits of a JSR JSR 231 and JSR 239 Status 9

JSR 231 and 239 What they are JSR 231 Java bindings to OpenGL Based on JOGL project on java.net Most likely based on OpenGL 1.5 JSR 239 Java bindings to OpenGL ES Will use the GlueGen technology of JOGL to generate bindings Most likely based on OpenGL ES 1.0 Both being run under the Java Community Process version 2.6 10

Why Do a JSR? Benefits of a JSR Align market around one specification No need to download multiple APIs for the same binding Specification and TCK ensure compliant bindings can be produced Ensure all functionality of native library present Some industries (e.g., mobile devices) prefer JCP APIs 11

JSR 231 and 239 Status Both JSRs were filed and approved by their respective ECs Both Expert Groups have been formed and are meeting regularly EGs working together to make both APIs as similar as possible Both EGs hope to have EDRs late this year 12

JSR 231 and 239 Notes Both JSRs are fundamentally tracking a third-party API Want to track the OpenGL APIs as closely as possible Plan to use maintenance releases for updates 30-day review period (shortest possible) 13

What You Can Do More help is ALWAYS welcome Join an Expert Group Specification work SI work TCK work Contribute to JOGL project on java.net Participate in EDRs 14

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 15

Using JOGL With AWT and Swing DirectDraw incompatibilies on Windows -Dsun.java2d.noddraw=true Disables Java 2D API s internal use of DirectDraw APIs on Windows Incompatible with OpenGL Frequent driver bugs arise when mixing the two APIs, even when they are used in separate windows Should be specified for all JOGL applications! No harm specifying on non-windows platforms Especially for Java Web Start applications Add following to resources section of JNLP file: <property name="sun.java2d.noddraw" value="true"/> 16

Using JOGL With AWT and Swing GLCanvas and GLJPanel GLCanvas: heavyweight AWT widget for OpenGL rendering Best performance (hardware accelerated) Works in most GUI situations See this article on mixing lightweight and heavyweight widgets successfully: http://java.sun.com/products/jfc/tsc/articles/mixing/ JPopupMenu. setlightweightpopupenabled(false); To get Swing menus to overlap GLCanvas 17

Using JOGL With AWT and Swing GLCanvas and GLJPanel GLJPanel: lightweight Swing widget for complete compatibility with Swing UIs JInternalFrames Currently not hardware-accelerated Poor performance Investigating using OpenGL pbuffers to implement GLJPanel Faster, but still not fast enough Still has texture readback Experimental work underway to integrate better with Java 2D API and JFC/Swing 18

Using JOGL With AWT and Swing Rendering and animation options Automatic redraws initiated by the AWT For static scenes Call repaint() in animation thread Use Animator class or start your own thread and call GLDrawable.display() directly Most efficient for games Allows optimized OpenGL context handling on some platforms As efficient as single-threaded C code 19

Using JOGL With AWT and Swing Multithreading AWT events like mouse and keyboard events are delivered on AWT event queue thread Not allowed / possible to make OpenGL calls directly inside these listeners Though you can schedule or force a redraw Instead, pass information between these threads and any animation threads via member data Use appropriate synchronization Read data exactly once in your display() method Avoids flickering and other artifacts during mouse interaction 20

Using JOGL With AWT and Swing Examples See demos at http://jogl-demos.dev.java.net/ for examples of animation, interaction, and advanced features 21

Agenda 22 Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Scene graphs and game engines Object picking Shadows Optimizing JOGL Applications Demos Conclusion

Scene Graphs and Game Engines Overview Higher-level, typically object-oriented layer for applications to build on top of Often have hierarchical structure Good for representing character animation Use OpenGL or similar API at the bottom Ones discussed here use JOGL Look for extensibility Ability to call out to OpenGL from within scene graph to implement leading-edge effects 23

Scene Graphs and Game Engines Examples Xith3D: http://www.xith.org/ General-purpose scene graph, but focused on gaming and high performance Designed to be nearly identical to Java 3D APIs Supports leading-edge functionality like shadow volumes and vertex and fragment programs Aviatrix3D: http://aviatrix3d.j3d.org/ Focused on visualization market Minimal API design Also supports vertex and fragment programs 24

Scene Graphs and Game Engines Examples OpenMind: http://www.mind2machine.com/ 3D game engine Built-in support for 3D Studio Max ASE format Supplies tool chain for developers 25

Scene Graphs and Game Engines Demo Abdul Bezrati (a.k.a. Java Cool Dude ) Xith3D demos http://xith.org/demo/javacooldude.php 26

Object Picking Using the selection buffer Interactive applications require the ability to pick objects in 3D OpenGL provides a built-in mechanism for object selection Special rendering mode User supplies storage for results and sets up special pick matrix View volume centered around cursor Any objects rendered into this view volume are reported to the user 27

Object Picking Using the selection buffer Set up selection buffer IntBuffer buf = BufferUtils.newIntBuffer(1024); gl.glselectbuffer(buf.capacity(), buf); Switch into selection mode gl.glrendermode(gl.gl_select); Color buffer is frozen at this point and not updated until selection mode is exited Initialize name stack gl.glinitnames(); Set up pick matrix glu.glupickmatrix(...); 28

Object Picking Using the selection buffer Render objects, assigning names to them int objectid =...; gl.glpushname(objectid); renderobject(gl); gl.glpopname(); Switch out of selection mode int numhits = gl.glrendermode(gl.gl_render); Process hits int idx = 0; while (idx < numhits) { int hit = buf.get(idx++);... } 29

Object Picking Demo Selection buffer demo (courtesy Thomas Bladh) http://www.sm.luth.se/csee/courses/smd/159/ TestPrograms/Picking.java 30

Object Picking Using the selection buffer Advantages Easy to start working with selection buffer Can reuse normal rendering code; just add names Names have no effect in GL_RENDER mode Disadvantages Still have to disambiguate multiple hits based on depth values No surface normal or other information at hit site Not exactly casting a ray into the scene To implement dragging behavior, still need some kind of policy for motion Doesn t solve problem of moving camera in response to mouse motion 31

Object Picking Using Manual Linear Algebra Picking can also be done at the application level Perform ray-triangle intersection tests using a linear algebra library Depending on application s representation of geometry, may be able to accelerate drastically Octrees or other spatial partitioning techniques Degenerate cases like vertical rays Have full control over information returned and response to dragging May require some more code 32

Object Picking Using Manual Linear Algebra Libraries exist for adding 3D interaction gleem (OpenGL Extremely Easy-To-Use Manipulators) in jogl-demos workspace on java.net Will be shown shortly Most scene graphs have picking mechanisms Scene graphs discussed earlier support it Depending on application and library, may be very easy to integrate the two 33

Shadows Why do we need shadows? Humans use shadows to infer spatial relationships Relative positions of objects Locations of light sources Shape of an object Scene looks more natural Scene is easier to understand Shadows look cool 34

Shadows Two basic techniques Render-to-texture shadows Image-space technique Volumetric Geometric technique 35

Shadows Render-to-texture shadows Render the scene from the light s perspective Store depth of rendered scene as texture Render scene from viewer s perspective Render the depth texture onto the scene Careful setup of texture transform and texture-coord generation Object s position maps to correct u-v texture coords in depth texture Object s r texture coord maps to distance from the object to the light source If r value is greater than texture value, pixel is in shadow 36

Shadows Demo NVidia Hardware Shadow Mapping 37

Shadows Render-to-texture shadows Advantages: Performance independent of geometric complexity No additional cost for animated geometry Can take into account alpha-masked geometry (example: a chain-link fence) 38

Shadows Render-to-texture shadows Disadvantages: Dependent on texture resolution (aliasing) Not good for long projections Need special tricks to get self-shadowing to work well Older hardware may not support render-to-texture in hardware Fall back to slow framebuffer --> texture copy 39

Shadows Volumetric shadows Basic idea: Use geometry to calculate volume of space that is in shadow Calculate silhouette edge of object, from light s perspective Extrude the silhouette away from the light Objects inside this volume are in shadow from the light 40

Shadows Volumetric shadows Uses stencil buffer for per-pixel in/out test Render scene, ambient light only Sets the depth buffer Render shadow volumes with stencil enabled Render front / back faces separately If pixel passes depth test, adjust stencil value Many adjustment heuristics (z-pass, z-fail) If stencil value is 0 afterwards, pixel is not in shadow 41

Shadows Demo NVidia Infinite Shadow Volumes 42

Shadows Volumetric shadows Advantages: Self-shadowing just works No aliasing problems Crisp shadows, even at infinite projection distances Good for wide-open spaces 43

Shadows Volumetric shadows Disadvantages: Performance depends on scene Expensive for complex objects, many lights, or many shadow receivers N lights = N+1 render passes per shadowed object Slow for non-static geometry / non-static lights Silhouettes must be recalculated each frame Incorrect shadows cast from alpha-masked geometry Purely geometric technique Many subtleties to make it work correctly for all intersections of light, viewer, and shadow volume 44

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 45

Optimizing JOGL Applications Data organization Application writer needs to decide how to lay out data in memory Multiple Java objects in heap? Primitive types and/or primitive arrays? New I/O? Use memory-mapped files instead of reading them in? Guide decisions by how various data structures will be used and how much data they store When compatibility with C data structures in memory-mapped files is required, GlueGen tool can help provide access to data GlueGen is in JOGL workspace on java.net 46

Optimizing JOGL Applications Data organization: Grand Canyon demo 300 MB of terrain data visualized in real time using Java technology and OpenGL Multiresolution algorithm More detail for terrain closer to camera Two components of data: geometry and texture NIO used to memory-map both Highest-resolution geometry mapped all of the time Processed by Java code to decimate to appropriate resolution Appropriate resolution textures mapped in by background thread Raw data handed off to OpenGL 47

Optimizing JOGL Applications Data organization: Grand Canyon demo Very little data stored in Java objects heap Plenty of garbage generated, but all short-lived No visible GC pauses Shows alternative to earlier programming models in Java language E.g., all data read in to Java objects heap 48

Optimizing JOGL Applications Demo Grand Canyon demo http://java.sun.com/products/jfc/tsc/articles/jcanyon/ 49

Optimizing JOGL Applications Efficiency JNI has a non-zero cost All OpenGL routines are necessarily called from the Java programming language through JNI Minimize number of OpenGL function calls per frame Use vertex arrays and New I/O Float/Double/IntBuffers to store and send down geometric data to OpenGL glvertexpointer, glnormalpointer, glcolorpointer 50

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 51

Demos Wurm Online 52

Demos Wurm Online Being developed by Mojang Specifications Fantasy Massively Multiplayer Online Role Playing Game written in Java language using JOGL http://www.wurmonline.com/ 53

Demos Max 54

Demos Max Developed by Synthetic Characters Group at The Media Lab, MIT http://characters.media.mit.edu/ Explores behavior systems that: Support teasing Develop expectations about people they interact with Develop over time, like animals do Characters code base written in Java programming language Small pieces of native code to interface to custom input devices 55

Demos Jake2 56

Demos Jake2 Port of Quake 2 engine to Java technology and JOGL Done by Bytonic Software http://www.bytonic.de/ Illustrates that Java platform is capable of creating commercial-quality games Better than 85% of speed of original C 210 fps compared to 245 fps 57

Agenda Introduction JSR Update Using JOGL With AWT and Swing Techniques for Application Development Optimizing JOGL Applications Demos Conclusion 58

Conclusion Java platform and OpenGL 3D API provide the tools to develop leading-edge 3D applications and games High performance, portability, and safety of the Java platform JOGL project and JSR 231 / 239 aiming for robust, full-featured, and easy-to-use interfaces to OpenGL Open source; join the development community Use the Java programming language for your next project 59

For More Information Technical Sessions TS-1338 Desktop Game Development BOFs BOF-1241 Meet the Java 2D API Team BOF-1938 Meet the AWT Team BOF-3215 Java 3D API URLs http://jogl.dev.java.net/ http://community.java.net/games/ 60

Q&A 61

3D Application and Game Development With OpenGL java.sun.com/javaone/sf Daniel Petersen Kenneth Russell Sun Microsystems, Inc. 62