What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric Objects
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Normals Specifying the normal –void glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); When using lighting effects, normals must be defined for each.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Lecture 5 - Programming with OpenGL
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
Computer Graphics Bing-Yu Chen National Taiwan University.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Review of OpenGL Basics
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Computer Graphics Bing-Yu Chen National Taiwan University.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Intro to OpenGL: Vertices and Drawing
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
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
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
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.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
CSC Graphic Programming Lecture 2 OpenGL Lightning.
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
CSC Graphics Programming
State Management and Drawing Geometric Objects
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive programs that produce color images of moving three-dimensional objects. With OpenGL, you can control computer-graphics technology to produce realistic pictures or ones that depart from reality in imaginative ways. OpenGL is a software interface to graphics hardware. This interface consists of about 150 distinct commands that you use to specify the objects and operations needed to produce interactive three-dimensional applications.

Basic OpenGL commands glClearColor(0.0, 0.0, 0.0, 0.0); & glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); void glRect{sifd}(TYPEx1, TYPEy1, TYPEx2, TYPEy2); & void glRect{sifd}v(TYPE*v1, TYPE*v2); glVertex2s(2, 3); glVertex4f(2.3, 1.0, -2.2, 2.0); glVertex3d(0.0, 0.0, ); GLdouble dvect[3] = {5.0, 9.0, }; glVertex3dv(dvect);

What Is OpenGL? A software interface (API) to the display card. A software interface (API) to the display card. Client-Server abstraction Client-Server abstraction –The client is your program, it sends commands to the server. –The server is the graphics card – get the commands, interpret them and produces pixels on screen. Pipeline oriented abstraction of the rendering process. Pipeline oriented abstraction of the rendering process. Extremely portable – supported by most OS and display cards. Extremely portable – supported by most OS and display cards. Uses algorithms developed by Silicon Graphics, Inc (SGI). Uses algorithms developed by Silicon Graphics, Inc (SGI). –T&L –Texture mapping –Alpha blending

Open GL – history and feature list Version 1.0 – 1992 Version 1.0 – 1992 –Basic geometry primitives, flat and Gouroud shading, Parametric textures, alpha and stencil buffers and more Version Version –Vertex Arrays, Texture enhancements Version 1.2 – 1998 Version 1.2 – 1998 –Extension mechanism, 3D textures, RGBA pixel format Version 1.3 – 2001 Version 1.3 – 2001 –Compressed textures, Cube-maps, multitextures, multisamples Version 1.4 – 2002 Version 1.4 – 2002 –Automatic MipMap, Fog coordinates, Current version 1.5 – 2003 Current version 1.5 – 2003 –Vertex Buffers, Occlusion queries, Full set of Boolean operators Version 2.0 – final spec announced in SIGGRAPH 2004 Version 2.0 – final spec announced in SIGGRAPH 2004 –Card Programmability is the most notable addition

Basic OpenGL commands How to draw the geometric objects? glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(6.0, 1.5); glVertex2f(4.0, 0.0); glEnd();

GL Primitives OpenGL support ten primitives OpenGL support ten primitives –GL_POINTS Individual points –GL_LINES Vertices pairs, individual line segments –GL_LINE_STRIP –GL_LINE_LOOP –GL_TRIANGLES Vertices triplets interpreted as triangles –GL_TRIANGLE_STRIP –GL_TRIANGLE_FAN –GL_QUADS Vertices quadruples, 4 sided polygons –GL_QUAD_STRIP –GL_POLYGON Boundary of a simple, convex polygon

GL Primitives (cont.)

A Primitive is started by A Primitive is started by –glBegin(GLenum mode); And ended using And ended using –glEnd(); Between them you can specify the primitive coordinates, color, normal etc. Between them you can specify the primitive coordinates, color, normal etc. For example: For example:glBegin(GL_LINES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(100.0,100.0, 0.0); glVertex3f(100.0, 0.0, 0.0); glVertex3f(0.0, 100.0, 0.0); glEnd();

Geometric Primitives The following geometric primitives In 3D may be used The following geometric primitives In 3D may be used –Points –Lines –Polygons –Triangle strips/fans –quads Also supports Also supports –Lighting –Shading –Texture mapping –Animation –Other special effects Does not include any functions for Does not include any functions for –Windows management –User interaction –File I/O

Basic OpenGL commands

Basic OpenGL commands How to draw a circle? GLint circle_points = 100; glBegin(GL_LINE_LOOP); for (i = 0; i < circle_points; i++) { angle = 2*PI*i/circle_points; glVertex2f(cos(angle), sin(angle)); } glEnd();

Specifying Vertices: Specifying Vertices: –void glVertex{234}{sifd}[v](TYPE coords); (for {x, y, z, w}) and short, int, float or double (for {x, y, z, w}) and short, int, float or double –Example: glVertex2s(2, 3); glVertex3d(0.0, 0.0, ); glVertex4f(2.3, 1.0, -2.2, 2.0); GLdouble dvect[3] = {5.0, 9.0, }; glVertex3dv(dvect); Normals Normals –Void glNormal3{bdfis}[v]{params} Colors Colors –Void glColor{34}[u]{bdfis}[v]

OpenGL Options The glEnable() and glDisable() functions enable or disable OpenGL capabilities. The glEnable() and glDisable() functions enable or disable OpenGL capabilities. –GL_DEPTH_TEST for z-buffer, hidden surface elimination –GL_CULL_FACE for enabling back face culling –GL_LIGHTING for lightning enabling –GL_LIGHTi –GL_DITHER for color dithering –GL_BLEND –GL_COLOR_MATERIAL Etc …

Basic OpenGL commands void glEnable(GLenum cap); void glDisable(GLenum cap); void glGetBooleanv(GLenum pname, GLboolean *params); void glGetIntegerv(GLenum pname, GLint *params); void glGetFloatv(GLenum pname, GLfloat *params); void glGetDoublev(GLenum pname, GLdouble *params); void glPointSize(GLfloat size); void glLineWidth(GLfloat width); void glNormal3{bsidf}(TYPEnx, TYPEny, TYPEnz);

Double Buffering Most multimedia applications do not wish to have the flickering effect resulting from window updates. Most multimedia applications do not wish to have the flickering effect resulting from window updates. –This is solved by having two buffers for a device context. –We always update the back buffer. –Once it ’ s ready, we switch the two buffers, starting the update again. Windows has support for double buffering using the GDI function Windows has support for double buffering using the GDI function –BOOL SwapBuffers( HDC hdc);

Stages of Vertex Transformations

The Modelview Matrix A 4x4 matrix M representing the transformed coordinate system. A 4x4 matrix M representing the transformed coordinate system. Setting the matrix mode to modelview Setting the matrix mode to modelview –glMatrixMode(GL_MODELVIEW); Each vertex V you provide is a single vector matrix. Each vertex V you provide is a single vector matrix. Before the rendering process, Each V is multiplied by the Modelview matrix. Before the rendering process, Each V is multiplied by the Modelview matrix. –V ’ =M

The Projection Matrix A 4x4 matrix M representing the projection matrix. A 4x4 matrix M representing the projection matrix. Setting the matrix mode to projection Setting the matrix mode to projection –glMatrixMode(GL_PROJECTION); –Defines the clipping volume – object out of the clipping volume will be culled. Initializing functions Initializing functions –void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far ); –void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar ); –void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar );

Transformations Rotation Rotation –glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) Scaling Scaling –glScaled( GLdouble x, GLdouble y, GLdouble z ); Translation Translation –void glTranslated( GLdouble x, GLdouble y, GLdouble z ); The active GL matrix M is updated with the transformation T as follows: The active GL matrix M is updated with the transformation T as follows: –M = M x T Each transformation effects only the vertices defined after the transformation call. Each transformation effects only the vertices defined after the transformation call. In general, you make the active matrix the Modelview matrix. In general, you make the active matrix the Modelview matrix.

Other Matrix Operations Selecting the matrix mode is done using Selecting the matrix mode is done using –void glMatrixMode( GLenum mode ); –mode can be one of GL_MODELVIEW GL_MODELVIEW GL_PROJECTION GL_PROJECTION GL_TEXTURE GL_TEXTURE

Matrix Stack The active matrix is save on a stack. The active matrix is save on a stack. –The top of the stack is the activematrix –glPushMatrix(); –glPopMatrix(); drawCar() { draw_car_body();glPushMatrix();glTranslatef(40,0,30);draw_wheel();glPopMatrix();}

To initialize an identity matrix use To initialize an identity matrix use –LoadIdentity() To load a given matrix use To load a given matrix use –void glLoadMatrixd( const GLdouble *m ); –m is a pointer to a 4x4 matrix stored in column-major order as 16 consecutive values In order to directly multiply the active matrix with a given matrix, use In order to directly multiply the active matrix with a given matrix, use –void glMultMatrixd( const GLdouble *m ); –m is a pointer to a 4x4 matrix stored in column-major order as 16 consecutive values

Normals Specifying the normal Specifying the normal –void glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); When using lighting effects, normals must be defined for each polygon or for each vertex. OpenGL does not calculate a normal by itself. When using lighting effects, normals must be defined for each polygon or for each vertex. OpenGL does not calculate a normal by itself.

Shading Models Choose the shading model Choose the shading model –void glShadeModel( GLenum mode ); –mode may be GL_FLAT GL_FLAT GL_SMOOTH (the same as the Gouraud shading model) GL_SMOOTH (the same as the Gouraud shading model) OpenGL does not support the Phong shading model. OpenGL does not support the Phong shading model.

Material Properties An object has a certain reflective properties An object has a certain reflective properties When using lighting, each model part has its own material properties, which also define its color. When using lighting, each model part has its own material properties, which also define its color. –glMaterialfv(GLenum face, GLenum pname, const GLfloat *params ) –Face must be one of GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. –pname can be GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_SHININESS etc. –params change accordingly.

Colors In case you want to specify colors per face or per vertex, you must In case you want to specify colors per face or per vertex, you must –Enable color tracking. glEnable(GL_COLOR_MATRERIAL); glEnable(GL_COLOR_MATRERIAL); –Set material properties to follow glColor values. glColorMaterial(GLenum face, GLenum mode); glColorMaterial(GLenum face, GLenum mode); –Specify the color before defining it ’ s corresponding vertex. glColor3d(GLdouble red, GLdouble green, GLdouble blue); glColor3d(GLdouble red, GLdouble green, GLdouble blue); glColor3ub(GLubyte red, GLubyte green, GLubyte blue); glColor3ub(GLubyte red, GLubyte green, GLubyte blue);

Adding Light to a Scene Enabling lighting Enabling lighting –glEnable(GL_LIGHT); OpenGL supports up to GL_MAX_LIGHTS lights simultaneously OpenGL supports up to GL_MAX_LIGHTS lights simultaneously –Query with glGetIntegerv(GL_MAX_LIGHTS) Set the light properties Set the light properties –void glLightfv( GLenum light, GLenum pname, const GLfloat *params ); –pname can be GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION etc. –params change accordingly. Enable the specific light Enable the specific light –glEnable(GL_LIGHTi); –i is between 0 and GL_MAX_LIGHTS-1

Basic OpenGL commands Where to get the information? al/nehe.htm al/nehe.htm