UniS CS297 Graphics with Java and OpenGL Basic Definitions.

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 2: State Management and Drawing Geometric Objects Jim Mims, Spring 2009.
Advertisements

Chapter 2: Graphics Programming
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
In the name of God Computer Graphics Bastanfard.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
UniS CS297 Graphics with Java and OpenGL Introduction.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
UniS CS293 Graphics with Java and OpenGL Introduction.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Image Synthesis Rabie A. Ramadan, PhD 1. 2 About my self Rabie A. Ramadan My website and publications
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Computer Graphics Week2 –Creating a Picture. Steps for creating a picture Creating a model Perform necessary transformation Lighting and rendering the.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
NoufNaief.net TA: Nouf Al-harbi.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 1 Graphics Systems and Models Models and Architectures.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
- Introduction - Graphics Pipeline
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Programming with OpenGL Part 2: Complete Programs
CS451Real-time Rendering Pipeline
OpenGL API 2D Graphic Primitives
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Models and Architectures
Introduction to Computer Graphics with WebGL
Display Lists & Text Glenn G. Chappell
Introduction to OpenGL
Models and Architectures
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
CS297 Graphics with Java and OpenGL
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

UniS CS297 Graphics with Java and OpenGL Basic Definitions

UniS 2 Introduction to OpenGL, Rendering Pipeline Construct shapes from geometric primitives, thereby creating mathematical descriptions of objects. (OpenGL considers points, lines, polygons, images, and bitmaps to be primitives.) Arrange the objects in three-dimensional space and select the desired vantage point for viewing the composed scene. Calculate the color of all the objects. The color might be explicitly assigned by the application, determined from specified lighting conditions, obtained by pasting a texture onto the objects, or some combination of these three actions. Convert the mathematical description of objects and their associated color information to pixels on the screen. This process is called rasterization.

UniS 3 Basic Definitions Models, or objects, are constructed from geometric primitives - points, lines, and polygons - that are specified by their vertices. Pixel, is the smallest visible element the display hardware can put on the screen. Rendering, process by which a computer creates images from models and consists of pixels drawn on the screen. Bitplane, area of memory that holds one bit of information for every pixel on the screen. E.g. bit might indicate how red a particular pixel is supposed to be. Framebuffer, stores all bitplanes, and holds all the information that the graphics display needs to control the color and intensity of all the pixels on the screen.

UniS 4 Models, or objects, are constructed from geometric primitives - points, lines, and polygons - that are specified by their vertices. Model of Torus, constructed from triangles (each rectangle is two triangles where the diagonals are not shown).

UniS 5 OpenGL simple example Very simple example shows many of JOGL elements that are common to all graphic programs. Only displays white square on black background, shown in Java Swing JFrame object. Full Code on course web site.

UniS 6 // various package imports declared here public class Simple2 implements GLEventListener { /* ***** Missing Code for GLEventListener interface methods on next slide ********* */ public static void main(String[ ] args) { JFrame.setDefaultLookAndFeelDecorated(false); JFrame jframe = new JFrame("Simple2"); jframe.setSize(500, 500); jframe.setLocationRelativeTo(null); // center of screen GLJPanel canvas = new GLJPanel(); Simple2 newGLEvtListnr = new Simple2(); canvas.addGLEventListener(newGLEvtListnr); jframe.getContentPane().add(canvas);//add canvas to JFrame window jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setVisible(true); // show window } }

UniS 7 Missing Code for Simple2 class public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); gl.glBegin(GL.GL_POLYGON); gl.glVertex2f(-0.5f, -0.5f); gl.glVertex2f(-0.5f, 0.5f); gl.glVertex2f(0.5f, 0.5f); gl.glVertex2f(0.5f, -0.5f); gl.glEnd(); gl.glFlush(); }

UniS 8 Simple2 drawable method glClearColor() establishes what color the window will be cleared to glClear() actually clears the window Once the clearing color is set, the window is cleared to that color whenever glClear() is called. glColor3f() command establishes what color to use for drawing objects – white for this example. glOrtho(), specifies coordinate system OpenGL assumes as it draws the final image and how the image gets mapped to the screen for orthographic parallel viewing volume.

UniS 9 gl.glOrtho(left, right, bottom, top, near, far); (left, bottom, -near) (right, top, -near) initial point of view (right, top, -far) (left, bottom, -far) z y x

UniS 10 Perspective (used later for 3D) gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); glu.gluPerspective(40.0, (float) w / (float) h, 1.0, 20.0); Note glOrtho does not define perspective in 3D, it only defines the space that will be observable. For perspective different OpenGL operators are necessary: These will be discussed in detail in later sections.

UniS 11 Simple2 drawable method code between glBegin() and glEnd(), define the object to be drawn a polygon with four vertices polygon's "corners" are defined by the glVertex3f() commands, or in 2D diagram glVertex2f(). Note the ‘f’ denotes that parameters are given as floating point values. (x, y, z) coordinates, the polygon is a rectangle on the z=0 plane glFlush() ensures that the drawing commands are actually executed rather than stored in a buffer awaiting additional OpenGL commands

UniS 12 Introduction to elementrary animation in OpenGL Movie motion is achieved by taking a sequence of pictures and projecting them at 24 per second on the screen Each frame is moved into position behind the lens, The shutter is opened, and the frame is displayed. The shutter is momentarily closed while the film is advanced to the next frame, then that frame is displayed, and so on. Old Charlie Chaplin movies were shot at 16 frames per second and are noticeably jerky. Computer-graphics screens typically refresh (redraw the picture) approximately 60 to 76 times per second Refresh rates faster than 120, however, are beyond the point of diminishing returns, since the human eye is only so good. The key reason that motion picture projection works is that each frame is complete when it is displayed.

UniS 13 Simple Animation Sequence ‘Moon’ orbits round ‘planet’. Each frame is redrawn with ‘moon’ rotated slightly each time. When played rapidly in sequence creates illusion of motion.

UniS 14 doublebuf class consider very simple animation that creates a 2D square and rotates square in real time in JFrame want square to rotate by small amount 60 times per second to create illusion of animation

UniS 15 doublebuf class example, using animator thread public static void main(String[ ] args) { /* Part 1: create new Java application object demo with double buffering here Set up OpenGL canvas and Java Swing JFrame and define drawing elements here. */ FPSAnimator animator = new FPSAnimator(canvas, 60); demo.setAnimator(animator); /* Part 2: initialise frame look and feel and attach drawing canvas here */ animator.start(); }

UniS 16 FPSAnimator FPSAnimator, Frames Per Second animator Java thread. new FPSAnimator(canvas, 60); this will try to force 60 frames per second to be rendered completely on screen. FPSAnimator does not guarantee that 60 frames will be shown, this is a maximum that can be shown. FPSAnimator will force all drawable objects to finish execution before frame is displayed. FPSAnimator forces the display method to complete execution upto the number specified in the argument.

UniS 17 FPSAnimator FSPAnimator forces display() to execute up to N times each second. Guarantees that display will complete execution before next frame is rendered on screen.

UniS 18 main method Part 1 in doublebuf class GLCapabilities caps = new GLCapabilities(); // request double buffer display mode caps.setDoubleBuffered(true); GLJPanel canvas = new GLJPanel(caps); doublebuf demo = new doublebuf(); demo.setCanvas(canvas); canvas.addGLEventListener(demo); canvas.addKeyListener(demo); canvas.addMouseListener(demo); FPSAnimator animator = new FPSAnimator(canvas, 60);

UniS 19 main method Part 1 in doublebuf class GLCapabilities caps = new GLCapabilities(); caps.setDoubleBuffered(true); When creating GLCanvas and GLJPanel instances, the user may configure a certain set of OpenGL parameters in the form of a GLCapabilities object. These customise how OpenGL will perform rendering of drawable objects on the screen. In this case double buffering is set to true.

UniS 20 main method Part 1 in doublebuf class Double buffering uses two image buffers to handle drawing. One buffer is displayed on screen whilst current drawing operations are executed in the other buffer, off screen. Once all drawing operations are complete, the two buffers are swaped. This ensures complex models are only shown on screen once they are complete, and not incrementally constructed on screen.

UniS 21 double buffering in doublebuf class On screen buffer Off screen buffer clear buffer create new model render new model swap buffers clear buffer create new model etc

UniS 22 main method Part 1 in doublebuf class GLJPanel canvas = new GLJPanel(caps); GLJPanel is placeholder for all displayable objects. Provides event listener to notify drawable objects when they must be redrawn. display() method causes all registered listening objects to execute their display() methods. Class diagram shows some of methods for this class.

UniS 23 main method Part 1 in doublebuf class canvas.addGLEventListener(demo); the dublebuf demo object will now execute its display() method whenever an GLAutoDrawable event is created and notified to the canvas object

UniS 24 doublebuf display( ) method public synchronized void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glPushMatrix(); gl.glRotatef(spin, 0.0f, 0.0f, 1.0f); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glRectf(-25.0f, -25.0f, 25.0f, 25.0f); gl.glPopMatrix(); gl.glBegin(GL.GL_LINES); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(0.0f,0.0f,0.0f); gl.glVertex3f(40.0f,0.0f,0.0f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(0.0f,0.0f,0.0f); gl.glVertex3f(0.0f,40.0f,0.0f); gl.glEnd(); gl.glFlush(); spinDisplay(); // internal method to change value to rotate square }

UniS 25 GLAutoDrawable interface JOGL abstracts the OpenGL rendering pipeline as a GLContext class. Java is a concurrent language, and graphics rendering with JOGL is achieved via a dedicated thread. Within JOGL drawing is always within either a GLCanvas or a GLJPanel object. A GLAutoDrawable object can access the OpenGL current context with the getGL() method. GLCanvas, GLJPanel both implement the GLAutoDrawable interface. The GLAutoDrawable parameter for the display method is really whichever of GLCanvas, GLJPanel is being used to draw elements within the Java application.

UniS 26 GLContext A GL context contains all information for rendering graphic data to display device (e.g. the screen) –Vertex data –Pixel data –Model view matrix –Projection matrix –Textures –Framebuffer

UniS 27 OpenGL rendering pipeline Show here to illustrate complexity of process, will be discussed in more detail as course progresses.

UniS 28 doublebuf display( ) method gl.glClear(GL.GL_COLOR_BUFFER_BIT); forces the entire GL canvas (either a GLCanvas, GLJPanel object) to be erased and coloured entirely with the current GL clear colour (defined earlier in the code with gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f), which is black.

UniS 29 doublebuf display( ) method glPushMatrix() means "remember where you are" glPopMatrix() means "go back to where you were."

UniS 30 doublebuf display( ) method Using push and pop, the x and y axis remain stationary, whilst the square rotates

UniS 31 doublebuf display( ) method Without push and pop, the x and y axis rotate as well as the square

UniS 32 doublebuf display( ) method gl.glRotatef(spin, 0.0f, 0.0f, 1.0f); rotate the entire 3D virtual world where all drawing objects occur by spin degrees around the vector (0,0,1) y x z (0,0,1) y x

UniS 33 doublebuf display( ) method gl.glFlush(); causes every drawable object to appear and all rendering operations to be performed spinDisplay(); internal method that increases the angle to rotate square at next iteration performed by FPS animator.