Introduction to OpenGL

Slides:



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

OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
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.
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.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
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.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
Programming With OpenGL
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
Computer Graphics Lab 1 OpenGL.
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
Graphics: Conceptual Model
CSCE 441: Computer Graphics
Introduction to OpenGL Programming
CS552: Computer Graphics Lecture 6: Viewing in 2D.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
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.
Introduction to OpenGL (IDE: Eclipse)
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
CS380 Lab Spring Myungbae Son.
Programming with OpenGL Part 1: Background
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
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Line and Curve Drawing Algorithms
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Introduction to OpenGL

OpenGL Overview OpenGL low-level graphics library specification Hardware Independent use with the C and C++ programming languages but there are also bindings for a number of other programming languages such as Java, Tcl, Ada, and FORTRAN Graphics primitives and attributes points, lines, polygons, images, and bitmaps geometric transformation Translation, rotation, scaling, reflection viewing transformation viewport Parallel/Perspective projection

OpenGL Overview API Hierarchy OpenGL applications use the window system’s window, input, and event mechanism GLU supports quadrics, NURBS, complex polygons, matrix utilities, and more Unix System Windows System The OpenGL Visualization Programming Pipeline

Basic OpenGL Syntax OpenGL Basic Library (OpenGL Core Library) Function name Prefix  gl First letter  Capital Ex) glBegin, glClear, glCopyPixels, glPolygonMode Constants name Begin with the uppercase letter GL Capital Letter The underscore(_) is used as a seperator Ex) GL_2D, GL_RGB, GL_CCW, GL_POLYGON, GL_AMIBIENT_AND_DIFFUSE Data type The remainder of the name : standard data-type (lower case) Ex) GLbyte, GLshort, GLint, GLfloat, GLdouble, GLboolean

Related Libraries OpenGL Utility (GLU) Open Inventor GLU library Setting up viewing and projection matrices Describing complex objects Displaying quadric and B-splines Processing the surface-rendeing operations Prefix  glu Open Inventor An Object oriented toolkit based on OpenGL Written in C++

Related Libraries Display window Window-management operation depend on the computer OpenGL Extension to the X Window System (GLX) Unix System (Prefix  glx) Windows-to-OpenGL (WGL) Microsoft Windows System (prefix  wgl) Apple GL (AGL) Apple System (prefix  agl) Presentation Manager to OpenGL (PGL) IBM OS/2 (prefix  pgl) OpenGL Utility Toolkit (GLUT) window system independent toolkit Interacting with any screen-windowing system Prefix  glut

Installation (1/5) OpenGL Header files Library files dll files gl.h, glu.h  C:\Program Files\Microsoft Visual Studio\VC\Include\GL Library files opengl32.lib, glu32.lib C:\Program Files\Microsoft Visual Studio\VC\lib dll files openGL32.dll, glu32.dll  C:\Windows\system32 (Windows Xp 이상 운영체제에서는 자동으로 인식, 추가 안해도 됨)

Installation (2/5) Download Glut-3.7.6-bin.zip glutdlls37beta.zip GLUT for Win32 dll, lib and header file glut37.zip GLUT source code distribution Glut-3.7.6-bin.zip glut.h  C:\Program Files\Microsoft Visual Studio 10.0\VC\Include\GL glut32.lib  C:\Program Files\Microsoft Visual Studio 10.0\VC\Lib glut32.dll  C:\Windows\system32 glutdlls37beta.zip 64bit의 경우 C:\Windows\System32 폴더와 C:\Windows\SysWOW64 폴더에 복사

Installation (3/5) Previous Version (Window 7) glut.h  C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\GL glut32.lib  C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib glut32.dll  C:\Windows\SysWOW64, C:\WIndows\System32 Window 8 with Visual Studio 2013 glut.h  C:\Program Files (x86)\Windows Kits\8.0\Include\um\gl glut32.lib  C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86 (64bit, 32bit 구분) glut32.dll  C:\Windows\SysWOW64,   C:\Windows\System32 error LNK2026: 모듈이 SAFESEH 이미지에 대해 안전하지 않습니다 * SAFESEH ( Structured Exception Handling ) 윈도우 상에서 예외처리를 하는 기법 해결법 프로젝트 속성 -> 링커 -> 고급 -> 이미지에 안전한 예외처리기 포함(아니오 ) 혹은 명령줄 에서  /SAFESEH:NO 입력 failure during conversion to COFF 에러발생시 Project Properties > Manifest Tool > Input and Output : Embed Manifest (No)

Installation (3/5) C++에서 fopen 함수 사용시 C4996 에러 [프로젝트] - [속성]으로 들어간 후 '구성속성 - C/C++-전처리기'로 들어가서 전처리기 정의에 _CRT_SECURE_NO_WARNINGS를 추가

Installation (4/5) Link Library Files Project Setting http://logs.tobinelectronics.com/installing-glut-in-windows-visual-studio-2010/ Link Library Files Open Visual Studio Select Empty Project (name it what you wish here) Or Win32 Console Application (Select Empty Project) Select Project  Properties  Linker  Input and add to Additional Dependencies the following: opengl32.lib;glu32.lib;glut32.lib to the end Project Setting Right click on the project Select Properties  VC++ Directories  Include Directories drop down the arrow, and select edit. browse to C:\Program Files\Microsoft Visual Studio 10.0\VC\include\GL

Installation (5/5) Visual Studio Error: ‘exit’: identifier not found This comes from an incompatibility error between the glut.h file, and Visual Studio’s .NET framework, or the stdlib.h file. To fix this problem, we need to add a definition to the existing preprocessor definitions. So, within the Solutions Explorer: right click on the project giving the error Select Properties  C/C++  Preprocessor  Preprocessor Definitions append GLUT_BUILDING_LIB to the existing definitions http://logs.tobinelectronics.com/visual-studio-error-exit-identifier-not-found/

Header file Include the header files GLUT to handle the window-managing operation #include <GL/glut.h> OpenGL core library #include <GL/gl.h> OpenGL Utility #include <GL/glu.h> Required by the C++ code #include <stdio.h> #include <stdlib.h> #include <math.h>

Display-Window Management Using GLUT Getting Started GLUT initialization glutInit (&argc, argv); Buffering and color modes for the display window glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) Window position & size glutInitWindowPosition(50, 100); glutInitWindowSize(400, 300); A display window is to be created on the screen glutCreateWindow(“An Example OpenGL Program”); Specify what the display window is to contain glutDisplayFunc(lineSegment); Describing a line segment in a procedure called lineSegment All display windows activate glutMainLoop();

A Complete OpenGL Program Set background color glClearColor (1.0, 1.0, 1.0, 0.0); 1~3 argument : red, green, blue colors (between 0.0 and 1.0) Forth parameter : alpha value Activate the OpenGL blending operations 0.0  totally transparent object 1.0  an opaque object Assigned window color display glClear (GL_COLOR_BUFFER_BIT); Color buffer (refresh buffer) that are to be set to the values indicated in the glClearColor function Set object color glColor3f (1.0, 0.0, 1.0);

A Complete OpenGL Program Display a 2D line segment Orthogonal Projection glMatrixModel(GL_PROJECTION); gluOrtho2D (0.0, 200.0, 0.0, 150.0) Map 2D retangular area of world coordinates to the screen Lower-left window corner (0.0,0.0) Upper-right window corner (200.0, 150.0) Create line segment glBegin (GL_LINES); glVertex2i (180, 15); glVertex2i (10, 145); glEnd();

OpenGL Command Formats glVertex3fv( v ) Number of components Data Type Vector b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double omit “v” for scalar form glVertex2f( x, y ) The OpenGL API calls are designed to accept almost any basic data type, which is reflected in the calls name. Knowing how the calls are structured makes it easy to determine which call should be used for a particular data format and size. For instance, vertices from most commercial models are stored as three component floating point vectors. As such, the appropriate OpenGL command to use is glVertex3fv( coords ). As mentioned before, OpenGL uses homogenous coordinates to specify vertices. For glVertex*() calls which don’t specify all the coordinates ( i.e. glVertex2f()), OpenGL will default z = 0.0, and w = 1.0 . 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w)

OpenGL Geometric Primitives All geometric primitives are specified by vertices glBegin(mode) and glEnd() and a list of vertices in between glBegin(mode) glVertex(v0); glVertex(v1); ... glEnd(); Every OpenGL geometric primitive is specified by its vertices, which are homogenous coordinates. Homogenous coordinates are of the form ( x, y, z, w ). Depending on how vertices are organized, OpenGL can render any of the shown primitives.

#include <GL/glut.h> // (or others, depending on the system in use) 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. 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 Example OpenGL Program"); // Create display window. init ( ); // Execute initialization procedure. glutDisplayFunc (lineSegment); // Send graphics to display window. glutMainLoop ( ); // Display everything and wait.