2005 by Jim X. Chen: The OpenGL graphics system is an application Programming interface (API) to graphics hardware. WHAT.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
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 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
OpenGL and Projections
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
by Jim X. Chen: 1.1. Professor Jim X. Chen Department of Computer Science George Mason University Fairfax, VA
Chapter 03: Graphics Primitives Course web page: Chapter #3.
2005 by Jim X. Chen: Jim X. Chen, Ph.D. Director of Computer Graphics Lab George Mason University.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
ATTRIBUTES OF GRAPHICS PRIMITIVES CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Programming with OpenGL Part 1: Background
Lecture 3 OpenGL.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
UniS CS297 Graphics with Java and OpenGL Basic Definitions.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
CSCE 441: Computer Graphics
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics and Multimedia Dr. Rajesh Siddavatam Ph.D (BITS–Pilani) Dean – Quality Assurance Professor Mail:
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
OpenGL and Related Libraries
Set up OpenGL Programming Environment
OpenGL API 2D Graphic Primitives
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Programming with OpenGL Part 1: Background
Introduction to OpenGL
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Starting to draw dealing with Windows which libraries? clipping
CS297 Graphics with Java and OpenGL
Presentation transcript:

by Jim X. Chen: The OpenGL graphics system is an application Programming interface (API) to graphics hardware. WHAT IS OPENGL? Around 130 graphics drawing and operation functions DEMO 1 DEMO 1 DEMO 2 DEMO 2

by Jim X. Chen: 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

by Jim X. Chen: /* Example 1.1.point.c: draw randomly generated points */ #include #define Height 400 #define Width Points

by Jim X. Chen: void display(void) { int x, y; //a. generate a random point x = rand() % Width; y = rand() % Height; //b. specify a drawing color: red glColor3f(1, 0, 0); //c. specify to draw a point glBegin(GL_POINTS); glVertex2i (x,y); glEnd(); //d. start drawing glFlush(); } 4

by Jim X. Chen: static void reshape(int w, int h) {//e. specify the window’s coordinates glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(0, Width, 0, Height, -1.0, 1.0); } int main(int argc, char **argv) {//f. initialize a drawing area glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(Width, Height); glutCreateWindow("Example 1.1.point.c"); //g. specify event callback functions glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(display); glutMainLoop(); } 5

by Jim X. Chen: import net.java.games.jogl.*; import java.awt.event.*; public class J1_1_Point extends J1_0_Point { static Animator animator; // drive display() in a loop public J1_1_Point() { //1. use super's constructor to initialize drawing //2. add a listener for window closing addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { animator.stop(); // stop animation System.exit(0); } }); } Points /* Example 1.1.point.c: revisit in JOGL */

by Jim X. Chen: // Called one-time for OpenGL initialization public void init(GLDrawable drawable) { // specify a drawing color: red gl.glColor3f(1.0f, 0.0f, 0.0f); //3. clear the background to black gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT); //4. drive the display() in a loop animator = new Animator(canvas); animator.start(); // start animator thread } Points

by Jim X. Chen: public void display(GLDrawable drawable) { //5. generate a random point double x = Math.random()*WIDTH; double y = Math.random()*HEIGHT; // specify to draw a point gl.glBegin(GL.GL_POINTS); gl.glVertex2d(x, y); gl.glEnd(); } Points

by Jim X. Chen: public static void main(String[] args) { J1_1_Point f = new J1_1_Point(); //6. Add a title on the frame f.setTitle("JOGL J1_1_Point"); f.setSize(WIDTH, HEIGHT); f.setVisible(true); } Points

by Jim X. Chen: OpenGL and DirectX libraries Theoretically, OpenGL and DirectX (Direct3D) are the same OpenGL is a mature graphics library, while DirectX has been advanced rapidly and significantly OpenGL is easier to learn and use, and is integrated in most modern graphics textbooks DirectX is much more popular in PC game Industry

by Jim X. Chen: 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 and Swing widget sets. Part of a suite of open-source technologies initiated by the Game Technology Group at Sun Microsystems.

by Jim X. Chen: ANIMATION AND DOUBLE BUFFERING Motion in a movie is achieved by projecting a sequence of pictures at 24 frames per second on the screen 60 per second is smoother than 30, and 120 is marginally better than 60.Refresh rates faster than 120 make no difference open_window(); for (i = 0; i < ; i++) { clear_the_framebuffer (); draw_frame(i); wait_until_a_24th_of_a_second_is_over (); } Double

by Jim X. Chen: Items drawn first are visible for the full 1/24 second and present a solid image on the screen; items drawn toward the end are instantly cleared as the program starts on the next frame. Double-buffering - hardware or software that supplies two complete color buffers. The frontbuffer is displayed while the backbuffer is drawn. When the drawing of a frame is complete, the two buffers are swapped. open_window_in_double_buffer_mode(); for (i = 0; i < ; i++) { clear_the_backbuffer (); draw_frame_into_backbuffer (i); swap_the_buffers (); } Double

glFlush() You treat a double-buffer as a single-buffer by 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); 2002 by Jim X. Chen:

by Jim X. Chen: Some Examples Coded In OpenGL DEMO 3 DEMO 3 DEMO 4 DEMO 4 DEMO 5 DEMO 5 DEMO 6 DEMO 6 DEMO 7 DEMO 7 DEMO 8 DEMO 8 DEMO 1 DEMO 1 DEMO 2 DEMO 2

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| // 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; } 2012 by Jim X. Chen:

Vector Operations – Cont. Addition/Subtraction –a+b = (a0+b0, a1+b1, a2+b2); Dot Product –a  b = |a||b|cos  = a0*b0 + a1*b1 + a2*b2 –A scalar value public double dotprod(double[] a, double[] b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); } 2012 by Jim X. Chen:

Vector Operations – Cont. Cross Product –a×b = a vector perpendicular to a&b // cros product of two vectors 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]; } 2012 by Jim X. Chen:

Reflect v1 around n to 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 v by Jim X. Chen: v1 n v2 v1v2 v1v2v1v2

Reflect v1 around n to 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]; } 2005 by Jim X. Chen: v1 n v2 v1v2 v1v2v1v2

by Jim X. Chen: HW1: due before next class draw a point that moves slowly along a circle Draw multiple points move inside the circle