Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to OpenGL

Similar presentations


Presentation on theme: "Introduction to OpenGL"— Presentation transcript:

1 Introduction to OpenGL

2 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

3 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

4 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

5 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++

6 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

7 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 이상 운영체제에서는 자동으로 인식, 추가 안해도 됨)

8 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 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 폴더에 복사

9 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)

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

11 Installation (4/5) Link Library Files Project Setting
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

12 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

13 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>

14 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();

15 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);

16 A Complete OpenGL Program
Display a 2D line segment Orthogonal Projection glMatrixModel(GL_PROJECTION); gluOrtho2D (0.0, , 0.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();

17 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)

18 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.

19 #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.


Download ppt "Introduction to OpenGL"

Similar presentations


Ads by Google