CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk

Slides:



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

Computer Graphics - Graphics Programming -
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
Chapter 2: Graphics Programming
OPENGL.
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
TOPIC 3 INTRODUCTION TO OPENGL CGMB214: Introduction to Computer Graphics.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
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,
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Noggin (BYU Students, SIGGRAPH 2006). Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
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.
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.
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
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 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);
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Introduction to OpenGL. OpenGL is a low-level graphics library specification. It makes available to the programmer  a small set of geometric primitives.
Affine Geometry Jehee Lee Seoul National University.
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Graphics: Conceptual Model
CS559: Computer Graphics Lecture 11: Antialiasing & Visibility, Intro to OpenGL Li Zhang Spring 2010.
CSCE 441: Computer Graphics
Introduction to OpenGL Programming
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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,
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
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 Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
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.
Introduction to OpenGL (IDE: Eclipse)
The Human Visual System vs The Pinhole camera
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Graphics Programming (I)
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Line and Curve Drawing Algorithms
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk

Introduction to OpenGL OpenGL: Open Graphics Library OpenGL provides a library of functions for various graphical operations including Graphics pirimitives Attiributes Geometric transformations Viewing transformations OpenGL is hardware independent

Basic OpenGL Syntax In OpenGL, function names are prefixed with gl. glBegin glClear glCopyPixels glPolygonMode Symbolic constants assigened as an argument of a function begin as GL followed by its name GL_2D GL_RGB GL_POLYGON Example: glBegin(GL_POLYGON);

Basic OpenGL Syntax(cont.) In OpenGL functions expect specific data types. The OpenGL uses special built-in data-type names GLbyte GLshort GLint GLfloat GLdouble GLboolean

Basic OpenGL Syntax(cont.) SuffixData TypeTypical Corresponding C- Language Type OpenGL Type Definition b8-bit integersigned charGLbyte s16-bit integershortGLshort i32-bit integerlongGLint, GLsizei f32-bit floating-pointfloatGLfloat, GLclampf d64-bit floating-pointdoubleGLdouble, GLclampd ub8-bit unsigned integerunsigned charGLubyte, GLboolean us16-bit unsigned integerunsigned shortGLushort ui32-bit unsigned integerunsigned longGLuint, GLenum, GLbitfield

Basic OpenGL Syntax(cont.) The two commands are equivalent, glVertex2i(1, 3); glVertex2f(1.0, 3.0); Except that the first specifies the vertex's coordinates as 32-bit integers and the second specifies them as single-precision floating-point numbers.

Basic OpenGL Syntax(cont.) Some OpenGL commands can take a final letter v, which indicates that the command takes a pointer to a vector (or array) of values rather than a series of individual arguments. glColor3f(1.0, 0.0, 0.0); float color_array[] = {1.0, 0.0, 0.0}; glColor3fv(color_array);

The OpenGL Utility Library In addition to the OpenGL core library, there are a number of associated libraries for handling special operations: The OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL commands to perform such tasks as setting up matrices for specific viewing orientations and projections, performing polygon tessellation, and rendering surfaces. GLU (The OpenGL Utility) library: Provides routines for  Setting up vieving and projection matrices  Describing complex objects with line and polygon approximations  Displaying B_splines and processing surface-rendering operations.

Related Libraries Every OpenGL implementation includes the GLU library. GLU function names start with the prefix glu: gluBeginCurve gluCylinder gluPerspective gluNurbsSurface

Related Libraries(cont.) Since OpenGL is hardware independent, we need to set up a display window on our video screen by using OpenGL. This is a rectangular area of the screen in which our picture will be displayed. There are several window-system libraries that support OpenGL functions for a variety of machines. For Microsoft Windows systems, the WGL routines provide a Windows-to-OpenGL interface. These routines are prefixed with the letters wgl.

Related Libraries(cont.) The OpenGL Utility Toolkit (GLUT) provides a library of functions for interacting with any screen-windowing system. The GLUT library functions are prefixed with glut and this library contains methods for rendering curves and surfaces. glutCreateWindow glutDisplayFunc glutFullScreen glutSetColor

Related Libraries(cont.) Since the OpenGL Utility Toolkit(GLUT) is an interface to other device-specific windows systems, we can use GLUT so that our programs will be device independent.

Header Files Files:.h,.lib,.dll The entire folder gl is placed in the Include directory of Visual C++ The individual lib files are placed in the lib directory of Visual C++ The individual dll files are placed in C:\Windows\System32

Header Files In all graphics programs we need to include the header file for the OpenGL core library. For most applications we also need header file for GLU and for window system. #include

Header Files(cont.) If we use GLUT we do not need to include gl.h and glu.h Thus, we replace the header files for OpenGL and GLU with #include

Header Files(cont.) In addition, we need to include header files that are required by the C++. For example, #include With the new ISO/ANSI standard for C++, these header files are called cstdio, stdlib and math.

Display-Window Management Using GLUT Since we use GLUT for window operations, we need to initialize it. We perform the GLUT initialization with the statement glutinit (&argc, argv);

Display-Window Management Using GLUT To create a display window on the screen we write the statement glutCreateWindow ("An OpenGL program");

Display-Window Management Using GLUT(cont) The next step is to specify what the display window is to contain. We create a picture using OpenGL functions and pass it to glutDisplayFunc which assigns the picture to the display window by the statement glutDisplayFunc(lineSegment);

Display-Window Management Using GLUT(cont) We need one more GLUT function to complete the window-processing operations. glutMainLoop ( ); After execution of above statement, all display windows that have been created are now activated.

Display-Window Management Using GLUT(cont) Although the display window that we created will be in some default location and size, we can control it by the following statements which locates the top left corner of the resulting window at the point with coordinates(50,100) and with size 400×300 glutInitWindowPosition (50, 100); glutInitWindowSize (400, 300);

Display-Window Management Using GLUT(cont) We can also set a number of other options for the display window. For example the following command specifies that a single refresh buffer is to be used and that the RGB color mode is to be used. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

A Complete OpenGL Program We need a few additional task to obtain a complete program First we choose a background color (e.g. white): glClearColor (1.0, 1.0, 1.0, 0.0); The first argument : Red The secondargument: Green The third argument : Blue The fourth argument: Alpha value (0: Completely transparent 1: Opac)

A Complete OpenGL Program (cont.) Although glClearColor command assigns a color to the display window, it does not put the display window on the screen. The following command gets the assigned window color displayed glClear (GL_COLOR_BUFFER_BIT);

A Complete OpenGL Program (cont.) In addition to setting the background color for the display window, we can choose colors for the objects we want to display. For example to specify three color components(RGB) using floating-point (f) values: glColor3f (1.0, 0.0, 0.0);

A Complete OpenGL Program (cont.) To display a straight-line (for example) we need to tell OpenGL how we want to project our picture onto the display window. glMatrixMode (GL_PROJECTION); gluOrtho2D (0.0, 200.0, 0.0, 150.0); The secod commands specify that the orthographic projection map the contents of a 2D rectangular area of world coordinates to the screen with coordinate ranges (x,y) → [(0.0, 200.0), (0.0, 150.0)]

A Complete OpenGL Program (cont.) Finally, we need to call the appropriate OpenGL routines to create the requred picture(e.g. the line segment). The folowing code defines a 2D line segment with integer, Cartesian endpoint coordinates (180,15) and (10,145). glBegin(GL_LINES); glVertex2i(180, 15); glVertex2i(10, 145); glEnd ( );

A Complete OpenGL Program (cont.) The following OpenGL program is organized into three procedures: init : Place all initializations and one-time parameter settings. lineSegment : Geometric description of the picture we want to display. This will be referenced by glutDisplayFunc. main : Contains the GLUT functions for setting up the display window and getting our line segment onto the screen.

An Example OpenGL Program #include void init (void) { glClearColor (1.0, 1.0, 1.0, 0.0);//Set display-window color to white. glMatrixMode (GL_PROJECTION);//Set projection parameters. gluOrtho2D (0.0, 200.0, 0.0, 150.0); } void lineSegment (void) { glClear (GL_COLOR_BUFFER_BIT);//Clear display window. glColor3f(1.0, 0.0, 0.0);//Set line segment color to red. glBegin(GL_LINES); glVertex2i(180, 15);//Specify line-segment geometry glVertex2i(10, 145); glEnd ( ); glFlush ( );//Process all OpenGL routines as quickly as possible }

An Example OpenGL Program(cont.) void main (int argc, char** argv) { glutInit (&argc, argv);//Initialize GLUT. glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB);//Set display mode. glutInitWindowPosition (50, 100);//Set top-left display-window position. glutInitWindowSize(400, 300);//Set display-window width and height. glutCreateWindow ("An OpenGL program");//Create display window. init ( );//Execute initialization procedure glutDisplayFunc(lineSegment);//Send graphics to display window. glutMainLoop ( );//Display everything and wait. }