Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

CS2401-Computer Graphics &&
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
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.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
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,
Device Independent Graphics and OpenGL
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Based on slides created by Edward Angel
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
2003CS Hons RW778 Graphics1 Chapter 1: Introduction Admin: Admin: –Lecture slots: Monday 8-9:45, Tuesday 9:15-11:00. –Book: F. Hill, Computer Graphics.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
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.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
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.
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.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Graphics: Conceptual Model
Lecture 2: Introduction to OpenGL
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
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,
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
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.
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.
The Human Visual System vs The Pinhole camera
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Drawing in the plane 455.
Introduction to OpenGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
OpenGL program.
Starting to draw dealing with Windows which libraries? clipping
University of North Carolina at Greensboro
Presentation transcript:

Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP

27 May Spring '09CG by MAK2  Computer graphics is mastered most quickly by doing it. Write and test programs that produce a variety of pictures.  Start with the simple tasks Try some variations … see what happens … and move towards drawing more complex scenes.

27 May Spring '09CG by MAK3  You need an environment consisting of 1. Hardware to display pictures (usually a CRT display generally called a screen) and 2. A library of software tools that your program can use.  Initialization of the hardware 1. Establishes the display mode (to graphics) 2. Setting up a coordinate system on the display

27 May Spring '09CG by MAK4 (100,50) (150,75) (0,250) x increases to the right y inclrease donwards 1. The entire screen is used for drawing

27 May Spring '09CG by MAK A window-based system is used. Different rectangular windows of different sizes at various locations are supported. Initialization involves creating and opening a new window. A coordinate system is attached to each window. X inclreases to the right and y increases downwards X-Windows on Linux, Solaris, Ultrix etc Windows Application Programming Interface (API) on Windows XP Quick Drawn on Apple Macintosh system X-Windows on Linux, Solaris, Ultrix etc Windows Application Programming Interface (API) on Windows XP Quick Drawn on Apple Macintosh system

27 May Spring '09CG by MAK6 3. A window-based system is used. Different rectangular windows of different sizes at various locations are supported. Initialization involves creating and opening a new window. A coordinate system is attached to each window. X increases to the right and y increases upwards Any window based system using OpenGL

27 May Spring '09CG by MAK7  Device independent graphics programming means a uniform approach is made so that the same program could be compiled and run on a variety of environments with the guarantee to produce the same results  OpenGL offers such a tool.

27 May Spring '09CG by MAK8  OpenGL provides an API (application programming interface), i.e. a collection of routines that a programmer can call, shielding the programmer from the hardware and software details of the system.  OpenGL is most powerful when drawing images of complex three-dimensional (3D) scenes.  It also works well for two-dimensional (2D) drawings … which we will be looking into for the time being.

27 May Spring '09CG by MAK9  Most window-based programs are event-driven: a program responds to various events such as click of a mouse, pressing of a key on the keyboard or the resizing of the window.  The systems maintains an event-queue which receives messages stating that certain event has occurred and deals with them on first come first served basis.  The programs are generally written in terms of call-back functions: the function that is executed when a particular event takes place.

27 May Spring '09CG by MAK10 Setting Up the Environment There are three steps involved 1. Copy the glut32.lib to the folder C:\Program Files\Microsoft Visual Studio\VC98\Lib 2. Copy glut.h to C:\Program Files\Microsoft Visual Studio\VC98\include\GL 3. Copy glut32.dll to C:\Windows\System 4. Include the lib in the VC, Project-> Setting->link

27 May Spring '09CG by MAK11 COMMENTS void main() { initialize things create a screen window glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMouseFunc(myMouse); glutKeyboardFunc(myKeyboard); some other code here glutMainLoop() } All other call-back functions are defined here. // An example main function. // Text in italics is pseudo code. // register the redraw function //register the reshape function // register the mouse action function // register the keyboard action function // enter the un-ending main loop A SKELETON OF AN EVENT-DRIVEN PROGRAM USING OPENGL

27 May Spring '09CG by MAK12  glutDisplayFunc(myDisplay): Here myDisplay is the function which is executed whenever the graphics window is redrawn.  glutReshapeFunc(myReshape): The function myReshape is called whenever the window is reshaped (its size is changed)  glutMouseFunc(myMouse): The function myMouse is executed in response to a mouse event.  glutKeyboardFunc(myKeyboard): This command registers the function myKeyboard with the event of pressing or releasing a key on the keyboard.  glutMainLoop(): This functions makes the program to enter into an endless loop waiting for the event to occur.

27 May Spring '09CG by MAK13 // appropriate #include go here. void main(int argc, char** argv) { glutInit(&argc, argv); // initialize the toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode glutInitWindowSize(640, 480); // set the window size glutInitWindowPosition(100, 150); // set the window position on screen // open the screen window glutCreateWindow(“My first graphics program in opengl”); // register the callback functions glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMouseFunc(myMouse); glutKeyboardFunc(myKeyboard); myInit();// some additional initialization as required glutMainLoop(); }

27 May Spring '09CG by MAK14  In the next few slides, I present a complete OpenGL program to draw some dots on screen.  This will be followed by an explanation of some of the functions that have been used in this program.

#include void myInit()// *************** myInit ************** { glClearColor(1.0, 1.0, 1.0, 0.0); // set white background color glColor3f(0.0, 0.0, 0.0); // set the drawing color glPointSize(4.0); // a dot will be 4 by 4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } void myDisplay(void)// *************** myDisplay **************** { glClear(GL_COLOR_BUFFER_BIT); // clear the screen glBegin(GL_POINTS); // draw three points glVertex2i(100, 50); glVertex2i(100, 130); glVertex2i(150, 130); glEnd(); glFlush(); // send all output to display }

27 May Spring '09CG by MAK16 void main(int argc, char** argv) { glutInit(&argc, argv); // initialize the toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode glutInitWindowSize(640, 480); // set the window size glutInitWindowPosition(100, 150); // set the window position on screen // open the screen window glutCreateWindow(“Dots in opengl”); glutDisplayFunc(myDisplay); // register the redraw functions myInit();// some additional initialization as required glutMainLoop(); }

27 May Spring '09CG by MAK17 The initial coordinate system for drawing 479 Dots in OpenGL 639

27 May Spring '09CG by MAK18  Output primitives line points, lines, polylines and polygons are defined in terms of one or more vertices.  Such objects are drawn by passing a list of vertices. This list is defined within a pair of OpenGL function calls: glBegin() and glEnd(). glBegin(GL_POINTS); // draw three points glVertex2i(100, 50); glVertex2i(100, 130); glVertex2i(150, 130); glEnd();  Here GL_POINTS is a constant built-into OpenGL. Other constants are GL_LINES, GL_POLYGON etc.

27 May Spring '09CG by MAK19 SuffixData TypeTypical C or C++ type OpenGL type name b8-bit integersigned charGLbyte s16-bit integershortGLshort i32-bit integerint or longGLint or GLsizei f32-bit floating pointfloatGLfloat or GLclampf d64-bit floating pointdoubleGldouble or Glclampd ub8-bit unsigned numberunsigned charGLubyte or GLboolean us16-bit unsigned number unsigned shortGLushort ui32-bit unsigned number unsigned int or unsigned long GLuint, GLenum, GLbitfield

27 May Spring '09CG by MAK20  As an example, a function using suffix i “expects” a 32-bit integer, but your system might translate int as a 16-bit integer void drawDot(int x, int y) { glBegin(GL_POINTS); // draws a dot at (x, y) glVertex2i(150, 130); glEnd(); }  A better option will be to use: void drawDot(GLint x, GLint y) { glBegin(GL_POINTS); // draws a dot at (x, y) glVertex2i(150, 130); glEnd(); }

27 May Spring '09CG by MAK21  OpenGL keeps track of many “state variables”, such as The current size of a point, The current color of a drawing The current background color  The value of a state variable remains active until a new value is given.  The size of a point can be set with glPointSize(), which takes one floating point argument. If the argument is 3.0, the point is usually drawn as a square with 3 pixels on a side.

27 May Spring '09CG by MAK22  The color of a drawn can be specified using glColor3f( red, green, blue); where the values of red, green and blue vary between 0.0 and 1.0.  The background color is set with glClearColor( red, green, blue, alpha); where alpha specifies a degree of transparency.  To clear the entire window to the background color, use glClear( GL_COLOR_BUFFER_BIT);

27 May Spring '09CG by MAK23  We will discuss it in detail when we discuss windows, viewports and clipping.  The myInit() function is a good place to set up the coordinate system.  OpenGL performs routinely a large number of transformations. This is done using matrices. gluOrtho2D() function sets the transformation we need for a screen window of size 640 pixels by 480 pixels. gluOrtho2D() function sets the transformation we need for a screen window of size 640 pixels by 480 pixels.

27 May Spring '09CG by MAK24  Use GL_LINES as the argument to glBegin() and pass it the two endpoints as vertices. glBegin(GL_LINES ); glVertex2i(40, 100); glVertex2i(202, 96); glEnd();  If more than two vertices are specified between glBegin() and glEnd(), they are taken in pairs, and a separate line is drawn between each pair.

That’s all for today