Lecture 2: Introduction to OpenGL

Slides:



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

COMPUTER GRAPHICS SOFTWARE.
Chapter 2: Graphics Programming
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
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
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
Introduction to OpenGL. What is OpenGL OpenGL is a low-level software interface to graphics hardware No commands for performing windowing tasks or obtaining.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Computer Graphics Bing-Yu Chen National Taiwan University.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
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.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
Programming with OpenGL Part 1: Background
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
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. 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,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to OpenGL Programming Jian-Liang Lin 2002.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
Modeling with OpenGL Practice with OpenGL transformations.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
CS 470 Computer Graphic Getting Started with OpenGL.
NoufNaief.net TA: Nouf Al-harbi.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
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,
Chapter 1 Graphics Systems and Models Models and Architectures.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
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.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Programming with OpenGL Part 1: Background
Draw a Simple Object.
Models and Architectures
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Models and Architectures
Models and Architectures
Programming with OpenGL Part 1: Background
Presentation transcript:

Lecture 2: Introduction to OpenGL CS552: Computer Graphics Lecture 2: Introduction to OpenGL

Objective After this lecture students will be able to Explain the importance of OpenGL Install OpenGL in their system Write program using OpenGL libraries

There really is no such thing as an The BIG Picture There really is no such thing as an “OpenGL program”

Graphics Library (API) The BIG picture Application Program Graphics Library (API) Hardware OpenGL A low-level interface to the graphics hardware

Illustration

Graphics lights (photons) objects (triangles) image (pixels) viewer

Physical reality (sort of) for (each photon) for (each triangle) for (each pixel) draw; lights (photons) objects (triangles) image (pixels)

Ray tracing for (each pixel) for (each triangle) for (each light) draw; lights (photons) objects (triangles) image (pixels)

Physical reality (sort of) for (each light) for (each triangle) for (each pixel) draw; lights objects (triangles) image (pixels)

Traditional graphics pipeline (OpenGL) for (each triangle) for (each light) for (each pixel) draw; lights objects (triangles) image (pixels)

Modern graphics pipeline (OpenGL 2.1) for (each triangle) for (each pixel) for (each light) draw; lights objects (triangles) image (pixels)

What is OpenGL? OpenGL is a software interface to graphics hardware. OpenGL is designed as a streamlined, hardware-independent interface to be implemented Runs on many different hardware platforms. With OpenGL, you must build your desired model from a small set of geometric primitives Points, lines, and polygons.

What OpenGL doesn’t do? The OpenGL API itself is not a programming language like C or C++. No commands for performing windowing tasks or obtaining user input are included in OpenGL Doesn't provide high-level commands for describing models of three-dimensional objects.

What is does do? Construct shapes from geometric primitives, thereby creating mathematical descriptions of objects. Arrange the objects in three-dimensional space and select the desired vantage point for viewing the composed scene. Calculate the colors of all the objects Convert the mathematical description of objects and their associated color information to pixels on the screen.

OpenGL Rendering Pipeline Geometry Path Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline Geometry Path It is a group of OpenGL commands that have been stored (compiled) for later execution. Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline Geometry Path Each vertex and normal coordinates are transformed by GL_MODELVIEW matrix Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline Primitives are transformed eye coordinates to clip coordinates. Viewport transform is applied in order to map 3D scene to window space coordinates. Last thing to do in Primitive Assembly is culling test if culling is enabled. Geometry Path Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline After reading the pixels, the data are performed scaling, bias, mapping and clamping. The transferred data are either stored in texture memory or rasterized directly to fragments. Geometry Path Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline Geometry Path Texture images are loaded into texture memory to be applied onto geometric objects. Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline It is the conversion of both geometric and pixel data into fragment. Fragments are a rectangular array containing color, depth, line width, point size and antialiasing calculations. Geometry Path Vertex Operation Primitive Assembly Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

OpenGL Rendering Pipeline Scissor Test ⇒ Alpha Test ⇒ Stencil Test ⇒ Depth Test. Geometry Path Vertex Operation Primitive Assembly Blending, dithering, logical operation and masking Vertex Data Display List Texture Memory Rasterization Fragment Operation Frame Buffer OpenGL Pipeline has a series of processing stages in order. Two graphical information, vertex-based data and pixel-based data, are processed through the pipeline, combined together then written into the frame buffer. Notice that OpenGL can send the processed data back to your application. A framebuffer (frame buffer, or sometimes framestore) is a portion of RAM containing a bitmap that is driven to a video display from a memory buffer containing a complete frame of data. Pixel Transfer Operation Pixel Data Image Path

The OpenGL State Machine Collection of variables the state of the pipeline A state machine is an abstract model of a collection of state variables

Graphics Library (API) OpenGL Abstractions OpenGL Application Program Graphics Library (API) Hardware GLUT GLU Viewing –perspective/orthographic Image scaling, polygon tessellation Sphere, cylinders, quadratic surfaces Primitives - points, line, polygons Shading and Color Translation, rotation, scaling Viewing, Clipping, Texture Hidden surface removal Windowing toolkit (key, mouse handler, window events)

Example #include <whateverYouNeed.h> main () { InitializeAWindowPlease(); glClearColor(0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); glFlush (); UpdateTheWindowAndCheckForEvents); }

Data Types OpenGL Data Type Internal Representation Defined as C Type C Literal Suffix GLbyte 8-bit integer Signed char b GLshort 16-bit integer Short s GLint, GLsizei 32-bit integer Long I GLfloat, GLclampf 32-bit floating point Float f GLdouble, GLclampd 64-bit floating point Double d GLubyte, GLboolean 8-bit unsigned integer Unsigned char ub GLushort 16-bit unsigned integer Unsigned short us GLuint, GLenum, GLbitfield 32-bit unsigned integer Unsigned long ui

Points, Lines, and Polygons Homogeneous Co-ordinate system four floating-point coordinates (x, y, z, w) glVertex2i(Glint xi, Glint yi); glVertex3f(Glfloat x, Glfloat y, Glfloat z);

Points, Lines, and Polygons glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEND(); Define a pair of points as: glBegin(GL_POINTS);

Viewport Transformation Transformations Model View Matrix Projection Matrix Perspective Division Viewport Transformation [x y z w] Eye coordinates Clip Coordinates Normalized Device Coordinate Window Coordinate

Transformations

Transformations Local Coordinate System World Coordinate System

Camera Coordinate System

The Big Picture Model Matrix View Matrix Local Coordinate System World Coordinate System Model Matrix Camera Coordinate System View Matrix

Projection Orthographic Perspective

OpenGL Example … glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity ();/*clear the matrix*/ /* viewing transformation */ gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /* modeling transformation */ glScalef (1.0, 2.0, 1.0); glutWireCube (1.0); glFlush (); Recall that the viewing transformation is analogous to positioning and aiming a camera.

OpenGL Example gluLookAt (0.0, 0.0, 5.0, // Camera position 0.0, 0.0, 0.0, // Lens aim at 0.0, 1.0, 0.0);// Camera orientation Recall that the viewing transformation is analogous to positioning and aiming a camera.

OpenGL Example … glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity ();/*clear the matrix*/ /* viewing transformation */ gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /* modeling transformation */ glScalef (1.0, 2.0, 1.0); glutWireCube (1.0); glFlush (); Recall that the viewing transformation is analogous to positioning and aiming a camera.

Modeling Transformations void glTranslate{fd}(TYPEx, TYPE y, TYPEz); void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); glRotatef(45.0, 0.0, 0.0, 1.0) void glScale{fd}(TYPEx, TYPE y, TYPEz); glScalef(2.0, -0.5, 1.0).

Coloring Widely used methods of describing a color is the RGB color model. OpenGL usually a value between 0 and 1 We can mix these three colors together to give us a complete range of colors

Example set_color(RED); draw_item(A); draw_item(B); set_color(GREEN); set_color(BLUE); draw_item(C);

glColor3f void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.5f, 0.0f, 1.0f); glBegin(GL_QUADS); glVertex2f(-0.75, 0.75); glVertex2f(-0.75, -0.75); glVertex2f(0.75, -0.75); glVertex2f(0.75, 0.75); glEnd(); glutSwapBuffers(); }

glColor3f (contd.) void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glColor3f(0.5f, 0.0f, 1.0f); glVertex2f(-0.75, 0.75); glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.75, -0.75); glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.75, -0.75); glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(0.75, 0.75); glEnd(); glutSwapBuffers(); }

Output

Keyboard & Mouse handling Write your function to handle key-press event void keyPressed (unsigned char key, int x, int y) {} In main invoke your function using GLUT glutKeyboardFunc(keyPressed); // If they ‘a’ key was pressed If (key == ‘a’) { // Perform action associated with the ‘a’ key }

Ubuntu Following packages are required freeglut3-dev mesa-common-dev Command sudo apt-get install freeglut3 freeglut3-dev mesa-common-dev

Windows Following files are required for development opengl32.lib glu32.lib gl.h glu.h For GLUT (Downloadable) glut32.dll glut32.lib glut.h

Windows Runtime libraries: C:\Windows\System32\{opengl,glu}32.dll On 64-bit Windows: C:\Windows\SysWOW64\{opengl,glu}32.dll Header files: C:\Program Files\Microsoft SDKs\Windows\v7.1A\Include\gl\{GL,GLU}.h Linker library: C:\Program Files\Microsoft SDKs\Windows\v7.1A\Lib\OpenGL32.Lib

Windows Runtime library: C:\Program Files\Microsoft Visual Studio *\VC\bin\glut32.dll Header file: C:\Program Files\Microsoft Visual Studio *\VC\include\GL\glut.h Linker library: C:\Program Files\Microsoft Visual Studio *\VC\lib\glut32.lib

Windows (in VC not there) Runtime library: C:\Windows\system\glut32.dll Header file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\GL\glut.h Linker library: C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\glut32.lib

Linux You will have to use the -lglut linker option with gcc/g++ to compile a program with glut library. For example, Name of the program to be compiled cube.c Command gcc -o cube cube.c -lglut -lGLU

gcc -o cube cube.c -lglut -lGLU Example Compiler Source File gcc -o cube cube.c -lglut -lGLU Output option OpenGL Option

Windows Start Visual C++ and create a new empty project of type Win32 Console Application Add a GLUT program to the project Go to Projects Settings C++ tab select Category - Preprocessor. In the additional include directory box give the path where GL/glut.h is present. Go to Projects Settings Link tab, select Category - Input. In additional library path give the location of glut32.lib

Thank you Next Lecture: Introduction to 2D Graphics