CS 468 OpenGL Jon Moon Spring 2004 Computer Science Cornell University.

Slides:



Advertisements
Similar presentations
Java + OpenGL = JOGL Java and OpenGL Rich Truban Andrew Potozniak.
Advertisements

Today Composing transformations 3D Transformations
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Graphics Pipeline.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
3D Graphics Rendering and Terrain Modeling
CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
INTRODUCTION. Painting with numbers! Aspects Modeling Rendering Animation.
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
OpenGL and Projections
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
10/5/04© University of Wisconsin, CS559 Fall 2004 Last Time Compositing Painterly Rendering Intro to 3D Graphics Homework 3 due Oct 12 in class.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
Week 2 - Wednesday CS361.
2002 by Jim X. Chen George Mason University Transformation and Viewing.1. Plane Example: J2_0_2DTransform.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
OpenGL and Parametric Curves Advanced Multimedia Technology: Computer Graphics Yung-Yu Chuang 2005/12/21 with slides by Brian Curless, Zoran Popovic, Robin.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Lecture 11: Exam Revision 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271  Coursework.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
1 Computer Graphics Week9 -3D Geometric Transformation.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Modeling with OpenGL Practice with OpenGL transformations.
UniS CS297 Graphics with Java and OpenGL Basic Definitions.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
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?
Basic 3D Concepts. Overview 1.Coordinate systems 2.Transformations 3.Projection 4.Rasterization.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
2/19/04© University of Wisconsin, CS559 Spring 2004 Last Time Painterly rendering 2D Transformations –Transformations as coordinate system changes –Transformations.
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Introduce Jogl. 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.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Introduction to Computer Graphics
- Introduction - Graphics Pipeline
School of Computer Science
Week 2 - Friday CS361.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
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.
3D Graphics Rendering PPT By Ricardo Veguilla.
CS451Real-time Rendering Pipeline
Projection in 3-D Glenn G. Chappell
Plane 2D GEOMETRICAL TRANSFORMATIONS Example: J2_0_2DTransform
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
CS297 Graphics with Java and OpenGL
Presentation transcript:

CS 468 OpenGL Jon Moon Spring 2004 Computer Science Cornell University

Who am I?  Jon Moon  University of Minnesota ’03  First year PhD   Office: 4143 Upson

The Plan  What is OpenGL?  OpenGL basic interactions  OpenGL with Java: JOGL  Sample code: General framework 3D Transformations Lighting

What is OpenGL?  It’s a graphics API: Software layer that sits between the programmer and the CPU, GPU  It’s window system and platform independent  It’s fast and easy to use

What is OpenGL?  It’s a renderer: Primitives are points, lines, polygons…  It’s a State Machine: The output of the renderer depends on the state, which includes:  Current color, normal, etc.  Shading, lighting  Viewing  All sorts of other stuff

Viewing in OpenGL  OpenGL maintains two viewing matrices: Model view matrix: for object positions Projection matrix: for camera properties  Projection can be perspective or orthographic  Camera is always at the origin, looking toward -z

OpenGL with Java: enter JOGL  JOGL is a java binding for the OpenGL API.  JOGL is not very object oriented: Make a single GL object, which then has methods, fields Basically a wrapped c header file gl.h  Simple to port C code to java this way

Enough talk, where’s the code? import... import net.java.games.jogl.*; public class OpenGLDemo01 extends JFrame implements GLEventListener { public OpenGLDemo01() {...} public static void main(String[] args) {new OpenGLDemo01();} public void init(...) {} public void reshape(...) {...} public void display(...) {...} public void displayChanged(...) {} }

Demo 1, high level  Constructor handles window: canvas, JPanel  Main simply creates an instance  Init sets some start state stuff  Reshape sets the modelview and projection matrices and viewport  Display specifies geometry and transformation

Demo 1: constructor public OpenGLDemo01() { super("OpenGL Demo 01"); setLocation(100, 100); setSize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); canvas = GLDrawableFactory.getFactory(). createGLCanvas(new GLCapabilities()); canvas.addGLEventListener(this); JPanel glPanel = new JPanel(new BorderLayout()); glPanel.add(canvas, BorderLayout.CENTER); glPanel.setSize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); getContentPane().add(glPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); show(); }

Demo1: reshape public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height) { final GL gl = gLDrawable.getGL(); final GLU glu = gLDrawable.getGLU(); gl.glViewport(0, 0, width, height); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0, VIEWPORT_WIDTH, 0, VIEWPORT_HEIGHT); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); }

Demo1: display public void display(GLDrawable gLDrawable) { final GL gl = gLDrawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT);// gl.glBegin(gl.GL_TRIANGLES); gl.glColor3d(1.0, 0.0, 0.0); gl.glVertex2i(250, 450); gl.glColor3d(0.0, 1.0, 0.0); gl.glVertex2i(50, 50); gl.glColor3d(0.0, 0.0, 1.0); gl.glVertex2i(450, 50); gl.glEnd(); }

That wasn’t so bad, was it?  But that was just 2D – drawing a triangle isn’t exactly amazing  Suppose we wanted to draw a perspective (3D) cube: What would have to change?  Camera type  Geometry  Hidden Surface removal!

Demo2: Init public void init(GLDrawable gLDrawable) { final GL gl = gLDrawable.getGL(); gl.glEnable(gl.GL_DEPTH_TEST); }

Demo2: reshape changes... gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (float) width / (float) height, 0.2f, 100.0f); glu.gluLookAt(3.0f, 5.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);...

Demo2: display changes... gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glBegin(gl.GL_QUADS); // Front Face gl.glColor3d(0.0, 0.0, 1.0); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f);...

Demo2: That’s it!  Booya -- perspective 3D cube.  glu.gluPerspective and glu.gluLookAt  HSR accomplished by enabling z- buffer, gl.glEnable(gl.GL_DEPTH_TEST) and clearing it for each display  Use gl.glBegin(GL_QUADS): list vertices in groups of 4, changing color/normals if desired

Demo3: Using the Model View Matrix  Even 3D perspective cubes get boring… what if we wanted it to spin?  Recall that the Model View matrix is part of the state of OpenGL: Changing it in one display call will persist until it is changed again. Let’s call the display method regularly, and each time tweak model view matrix

Demo3: Using the Model View Matrix  In display, we make this call: gl.glRotatef(0.5f, 1.0f, 1.6f, 0.7f); “rotate.5 degrees around the vector {1,1.6,.7}” More accurately, “calculate the matrix for that rotation, and multiply the Model View matrix by it”  Other nifty matrix changing calls: gl.glTranslatef(x,y,z) gl.glScalef(x,y,z)

Matrix stacks  OpenGL maintains multiple matrix stacks  gl.glPushMatrix pushes a copy of the current matrix onto the stack  gl.glPopMatrix discards the top of the stack  What is this useful for?

Demo4: Hierarchical transforms  Goal: box with two small boxes on top  Non-hierarchical method: Draw big base box Translate, rotate, scale into desired position of 2 nd box, draw it Translate, rotate, scale over to desired 3 rd box position, draw it? (or…)  But 3 rd should be relative to 1 st

Demo4: Hierarchical transforms  Hierarchical method: Draw big base box Push current matrix onto stack Transform to draw 2 nd box Pop matrix from stack  Back in coordinates of base box! Push matrix again Transform to draw 3 rd box Pop matrix

Demo4: Do it in OpenGL gl.glPushMatrix(); gl.glScalef(1,.3f,1); drawCube(gl); //just draws standard cube gl.glPushMatrix(); gl.glTranslatef(.5f,2f,0); gl.glScalef(0.3f,1f,0.3f); gl.glRotatef(15,0,1,0); drawCube(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-.5f,2f,0); gl.glScalef(0.2f,1f,0.2f); drawCube(gl); gl.glPopMatrix();

Demo5: The last one, I promise  What about lighting?  You can specify lights as part of the OpenGL state – position, color, emission, type, and more  First define a light: float lightColor[] = {1.0f, 1.0f, 1.0f}; gl.glLightfv(gl.GL_LIGHT0, gl.GL_COLOR, lightColor ); (similar for position, etc)  Then, enable it: glEnable(gl.GL_LIGHTING); glEnable(gl.GL_LIGHT0);

Demo5: Materials too!  Can also define a material as part of the state: float materialColor[] = {1.0f, 1.0f, 0.0f}; gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, materialColor);  Don’t worry much about lighting and materials in OpenGL; we can do much cooler stuff with Cg.

Other resources:  JOGL home:  GL, GLU function descriptions: bielefeld.de/doc/OpenGL/hp/Reference.html bielefeld.de/doc/OpenGL/hp/Reference.html  Java API spec:  Swing guides: ng/mini/index.html ng/mini/index.html