OpenGL and Related Libraries

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

GPGPU Programming Dominik G ö ddeke. 2Overview Choices in GPGPU programming Illustrated CPU vs. GPU step by step example GPU kernels in detail.
Chapter 2: Graphics Programming
 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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
LAB #1: Computer Graphics Framework IGX is a set of programs which allow you to write graphics programs in C/C++ from plain text files. Benefits: 1. You.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Overview of Computer Graphics Chapter 1. Bird’s Eye View  Overview of Computer Graphics –Basic concept of computer graphics, system, programming platforms,
2005 by Jim X. Chen: The OpenGL graphics system is an application Programming interface (API) to graphics hardware. WHAT.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Overview of Computer Graphics.
Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Real-time Graphical Shader Programming with Cg (HLSL)
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
GPU Shading and Rendering Shading Technology 8:30 Introduction (:30–Olano) 9:00 Direct3D 10 (:45–Blythe) Languages, Systems and Demos 10:30 RapidMind.
1 Chapter 1 Overview of Computer Graphics  To understand the basic objectives and scope of computer graphics  To identify computer graphics applications.
Computer Graphics Tz-Huan Huang National Taiwan University.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
Programming with OpenGL Part 1: Background
Introduction to OpenGL Programming Jian-Liang Lin 2002.
UniS CS297 Graphics with Java and OpenGL Basic Definitions.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
From Turing Machine to Global Illumination Chun-Fa Chang National Taiwan Normal University.
OpenGL Shading Language
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
GPU Computing for GIS James Mower Department of Geography and Planning University at Albany.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Our Graphics Environment Landscape Rendering. Hardware  CPU  Modern CPUs are multicore processors  User programs can run at the same time as other.
From VIC (VRVS) to ViEVO (EVO) 3 years of experiences with developing of video application VIC for VRVS allowed us to develop a new video application.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Khang Lam Daniel Limas Kevin Castillo Juan Battini
Programming with OpenGL Part 1: Background
Our Graphics Environment
Computer Graphics George Mason University Jim X. Chen, Ph.D.
Chapter 6 GPU, Shaders, and Shading Languages
CS451Real-time Rendering Pipeline
Understanding Theory and application of 3D
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Starting to draw dealing with Windows which libraries? clipping
Advanced Menuing, Introduction to Picking
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Introduction to geometry instancing
Introduction to Shaders
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 1: Background
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 2: Complete Programs
CS297 Graphics with Java and OpenGL
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
OpenGL Background CS 4722.
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

OpenGL and Related Libraries DEMO 1 DEMO 2 WHAT IS OpenGL? The OpenGL graphics system is an application programming interface (API) to graphics hardware @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .1.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu OpenGL-Related Libraries The OpenGL Utility Library (GLU) contains several routines that use OpenGL commands. It is considered part of your OpenGL. The OpenGL Extension to the X Window System (GLX) provides a means of creating an OpenGL context and associating it with a drawable window on a machine that uses the X. OpenGL Auxiliary Library (AUX) or Utility Toolkit (GLUT) to make programming examples simpler. Works for X, Win, Apple, etc. WGL for Windows; AGL for Apple; PGL for OS/2 JOGL – Java OpenGL API @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .2.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu OpenGL and DirectX libraries Theoretically, OpenGL and DirectX (Direct3D) are the same OpenGL and Direct3D are mature graphics library OpenGL is easier to learn and use, and is integrated in most modern graphics textbooks DirectX is much more popular in PC game industry in the past @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .3.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu JOGL – Java for OpenGL JOGL implements Java bindings for OpenGL. Provides platform for 3D graphics applications in Java JOGL provides full access to OpenGL functions and integrates with the AWT or Swing widget sets. Part of a suite of open-source technologies initiated by the Game Technology Group at Sun Microsystems. JOGL1_0_Frame * JOGL initial set up: * Open a frame with a background color @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .4.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Shaders Earlier GPU programming are through separate libraries: Cg, HLSL, etc. OpenGL 4.x includes GLSL as a standard: shader programming that runs on GPU Cg library faced out 2013 Old CPU graphics pipeline faced out @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

The rendering pipeline Vertex shader: parallel vertex processing Fragment shader: parallel fragment processing JOGL1_0_Point Draw a point with vertex and fragment shaders JOGL1_1_PointVFfiles vertex and fragment shader programs are stored in corresponding files @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Animation Motion in a movie was achieved by projecting a sequence of pictures at 24 frames per second on the screen 60 f/s is smoother than 30, and 120 is marginally better than 60. Refresh rates faster than 120 make no difference. Double-buffering The frontbuffer is displayed while the backbuffer is drawn. When the drawing of a frame is complete, the two buffers are swapped. @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .7.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu JOGL’s Animator JOGL1_2_Animate * Animate a point * Animator starts a thread that calls display() repetitively * Uniform sends a variable value from JOGL main program to the shader program Technical details are covered in the program @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

For Drawing an Object Just Once JOGL1_2_Animate comment out clearing the background: a shimmy line (alternating points in two buffers) Treat double-buffer as a single-buffer setting glDrawBuffer() to GL_FRONT with a glFlush() call. To switch back to double-buffered, you need to set glDrawBuffer() to GL_BACK. You can just choose to draw into both buffers: glDrawBuffer(GL_FRONT_AND_BACK); @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Some old Examples Coded In OpenGL DEMO 1 DEMO 3 DEMO 5 DEMO 7 DEMO 2 DEMO 4 DEMO 6 DEMO 8 @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .10.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Vector Operations Vector: a and b a=(a0, a1, a2); b=(b0, b1, b2); It gives a length and a direction Length: |a| = sqrt(a0*a0 + a1*a1 + a2*a2) Direction: a/|a| = (a0 /|a| , a1 /|a| , a2 /|a| ) // normalize a vector to unit vector public void normalize(double a[]) { double d = Math.sqrt(a[0]*a[0] + a[1]*a[1]+ a[2]*a[2]); if (d == 0) {System.err.println("0 length vector: normalize()."); return;} a[0] /= d; a[1] /= d; a[2] /= d; } GLSL: normalize(vec3) or normalize(vec4) @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

Vector Operations – Cont. Addition/Subtraction a+b = (a0+b0, a1+b1, a2+b2); GLSL: vec3 ± vec3 Dot Product (easy for finding cos) ab = |a||b|cos = a0*b0 + a1*b1 + a2*b2 GLSL: dot(vec3,vec3) or dot(vec4,vec4) public double dotprod(double[] a, double[] b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); } @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

Vector Operations – Cont. Cross Product (easy for finding the perpendicular vector, or normal) a×b = a vector perpendicular to a&b a×b = n|a||b|sin // cross product of two vectors GLSL: cross(vec3,vec3) public void crossprod(double[] a, double[] b, double[] v) { v[0] = a[1] * b[2] - a[2] * b[1]; v[1] = a[2] * b[0] - a[0] * b[2]; v[2] = a[0] * b[1] - a[1] * b[0]; } @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Reflect v1 around n to v2 n v1 v2 n is normalized; dotprod(v1,n) is the projection length of v1 on n 2*dotprod(v1,n) is twice of the above 2*dotprod(v1,n)*n is the vector along n with the length The above minus v1 will give you v2 v1 v2 v1 v2 v1 v2 @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu Reflect v1 around n to v2 n v1 v2 // reflect v1 around n to v2 public void reflect(double v1[], double n[], double v2[]) { // v2 = 2*dot(v1, n)*n + v1 for (int i = 0; i < 3; i++) { v2[i] = 2 * dotprod(v1, n) * n[i] - v1[i]; } GLSL: reflect(v1, n); v1 v2 v1 v2 v1 v2 @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu HW1: due before next class draw points that moves slowly along a circle Draw multiple points that move and bounce inside the circle Draw multiple points that bounces outside a circle and inside a rectangle @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .16.