1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed 1997-1999.

Slides:



Advertisements
Similar presentations
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
Advertisements

MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
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.
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Viewing and Transformation
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.
OpenGL and Projections
3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections.
OpenGL (II). How to Draw a 3-D object on Screen?
Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03.
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
OpenGL Tutorial Jason Lawrence COS426 Precept Notes 2/16/04.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Development of Interactive 3D Virtual World Applications
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
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.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 CSE 872 Advanced Computer Graphics Charles B. Owen (Instructor) – 1138 E. B., MW 12:30-1:50pm.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
Graphics Programming using OpenGL. OpenGL is a software interface that allows the programmer to create 2D and 3D graphics images. This interface consists.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
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.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
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.
Computer Science Term 1, 2006 Tutorial 2 Assignment 3 – The Virtual World.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
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?
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
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.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Graphics: Conceptual Model
Chap 3 Viewing and Transformation
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
4. Geometric Objects and Transformations
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.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
The Human Visual System vs The Pinhole camera
School of Computer Science
Jason Lawrence COS426 Precept Notes 2/16/04
Reference1. [OpenGL course slides by Rasmus Stenholt]
Geometric Objects and Transformations (II)
Computer Graphics 3Practical Lesson
Lighting and Shading Lab 8:.
Presentation transcript:

1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed

2 Outline n Philosophy n Output primitives n Materials n The modelview matrix n The projection matrix n Specifiying a view n Utility library glu n GLUT for interfaces

3 Philosophy of OpenGL n Platform independent n Window system independent n Rendering only n Aims to be real-time n Takes advantage of graphics hardware where it exists n State system n Client-server system n Standard supported by major companies

4 Generating Output n Output generated within a glBegin(), glEnd() ‘block’: glBegin(GL_POINTS); –glVertex2d(1.0,1.0); –glVertex2d(2.0,1.0); –glVertex2d(2.0,2.0); glEnd(); n GL_POINTS is a GLenum one example of the ‘mode’ of drawing

5 Drawing Mode n glBegin(GLenum mode) mode includes –GL_POINTS –GL_LINES –GLINE_STRIP –GL_LINE_LOOP –GL_POLYGON convex only –triangles –quadrilaterals glBegin(GL_POLYGON); glVertex2d(1.0,1.0); glVertex2d(2.0,1.0); glVertex2d(2.0,2.0); glEnd();

6 glVertexnt n glVertex2d(GLdouble x, GLdouble y); n glVertex3f(GLfloat x, GLfloat y, GLfloat z); n glVertex2i(GLint x, GLint y); n glVertex3d(GLdouble x,GLdouble y, GLdouble z); n = 2,3,4 t = d, f, i, s glVertex4f(GLdouble x, GLdouble y, GLdouble z, GLdouble w);

7 Shading and Colours n Shading properties glShadeModel(GL_SMOOTH | GL_FLAT) n Colour glColorNT{V}(r,g,b,{a}) –N=3,4 –T=b,s,i,ub,ui,us –v implies passing a pointer to array of colours

8 Materials n Many lighting parameters n Specify a material emmisive, ambient, shininess, specular GLfloat mat_spec = { 0.5, 0.5, 1.0, 1.0}; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec) glColorMaterial(GL_FRONT, GL_DIFFUSE)

9 Lights n Must enable a light with materials GLfloat light_pos ={ 1.0, 2.0, 1.0, 0.0} glLightfv(GL_LIGHT0, GL_POSITION, light_pos) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0)

10 Modeling and Viewing n OpenGL provides no functions itself for directly specifying a view it has no ‘policy’ for how a ‘camera’ is to be specified n It provides no data structures for model hierarchies. n Instead it provides fundamental tools that allow the construction of many different camera models and hierachies.

11 Modelview Matrix n A stack of matrices is maintained called the ‘modelview’ stack. n The current modelview matrix is used to multiply vertices at the first stage of the rendering pipeline equivalent to matrix C.M –C = CTM, M:WC->VC n glMatrixMode(GL_MODELVIEW) making changes to modelview

12 Matrix Operations n glLoadMatrix{f}{d}(const GLfloat *m); replaces current matrix n glMultMatrix{f}{d} (const GLfloat *m); if t is current matrix then tm is the new one n glPushMatrix{f}{d} (); pushes copy of current matrix down on stack; n glPopMatrix(); restores top of stack to be current matrix.

13 Example: Object Hierarchy n Suppose the current modelview matrix is M:WC->VC (ie, based on VRP, VPN,VUV). n GObject *object; //pointer to graphics object –glMatrixModel(GL_MODELVIEW); –/*push and duplicate current matrix*/ –glPushMatrix(); –/*premultiply M by CTM*/ –glMultMatrix(object->CTM); –/*now draw all faces in object*/ –glPopMatrix(); //restore original M

14 The Projection Matrix n glMatrixMode(GL_PROJECTION); subsequent matrix ops affect this stack (only 2 deep) n A perspective projection can be specified by:- glLoadIdentity(); glFrustum(left, right, bottom, top, near, far); –each argument is GLdouble

15 Transformations n glTranslate{d}{f}(x,y,z); translation matrix T(x,y,z) n glScale{d}{f}(x,y,z); scaling matrix S(x,y,z) n glRotate{d}{f}(angle, x, y, z); matrix for positive (anti-clockwise) rotation of angle degrees about vector (x,y,z) n If M is current matrix, and Q is transformation matrix, then new current matrix is QM

16 Utility Library (glu) n Library that is constructed on top of OpenGL, performing many higher- level operations curves and surfaces other forms of primitive (quadrics) a simpler viewing mechanism

17 glu Viewing n Constructing an ‘M’ matrix gluLookAt(ex,ey,ez, //eye point COP(WC) cx,cy,cz, //point of interest upx,upy,upz //up vector ) n Matrix that maps (cx,cy,cz) to -ve Z-axis (ex,ey,ez) becomes the origin (upx,upy,upz) becomes the y-axis n Premultiplies current matrix e c VPN

18 glu Perspective n To specify projection matrix: gluPerspective(fovy, //field of view degrees aspect,//xwidth/yheight zNear,//front clipping plane zFar //back clipping plane ) fovy y -z

19 Cautions n OpenGL uses a RH coordinate system throughout (hence the default VPN is the negative z-axis). n It adopts the convention of points as column vectors and post-multiplication: n The transpose of all our matrices should be used!

20 Windows and Interaction n GLX is the OpenGL extension to X11 Windows - provides basic window functions to provide OpenGL rendering context. n GLUT is a user interface toolkit (simple) that constructs windows and provides basic interaction mechanisms (see trapezium example).

21 Summary n OpenGL is a massive ‘basic’ powerful, flexible standard platform and windowing independent rendering system. n glBegin, glVertex, glEnd n glMatrixMode(GL_MODELVIEW) n glFrustum n gluLookAt, gluPerspective