Download presentation
Presentation is loading. Please wait.
1
Introduction to OpenGL (IDE: Eclipse)
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 C/C++ & OpenGL with Eclipse
Installation Step Setup IDE for C/C++ Install Eclipse Cpp Neon Provide IDE(Integrated development environment) with C/C++ Install CDT (C/C++ Development Tooling) in Eclipse Setup fully functional C and C++ IDE based on the Eclipse platform. Install MinGW (Minimalist GNU for Windows) Setup a GCC (GNU Compiler Collection) Compiler Setup Preferences about MinGW in Eclipse Test C/C++ Program Setup OpenGL & GLUT Setup OpenGL Setup GLUT Writing Your First OpenGL Program Configure OpenGL Library (per-project)
8
Installation C/C++ with Eclipse (1/5)
Install Eclipse Cpp Neon (통합개발환경 설치) Download Eclipse: Eclipse IDE for C/C++ Developers Java for Windows Missing - install a Java Runtime Environment (JRE) Oracle JRE 1.8.0
9
Installation C/C++ with Eclipse (2/5)
Install CDT in Eclipse (C/C++ 개발 툴 설치) Select Menu: Help Install New Software…
10
Installation C/C++ with Eclipse (3/5)
Install MinGW (GCC 컴파일러 설치) Download MinGW : Select Package in MinGW Installation Manager mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base Select Menu: InstallationApply Changes Setup System Variable : Add Path “C:\MinGW\bin”
11
Installation C/C++ with Eclipse (4/5)
Setup Preferences about MinGW in Eclipse (환경 설정) Select WindowsPreferences C/C++New C/C++ Project WizardMakefile Project Binary Parsers : Select GNU Elf Parser Building Setting Uncheck “Use default build command” Build command: Mingw32-make.exe
12
Installation C/C++ with Eclipse (5/5)
Test C/C++ Program (C/C++ 프로그램 테스트) Select Menu: File New C++ Project Toolchains: MinGW GCC Build All (Ctrl + B) Run (Ctrl + F11)
13
Installation OpenGL with Eclipse (1/5)
Setup OpenGL Header files gl.h, glu.h C:\MinGW\include\GL Library files libopengl32.a, libglu32.a C:\MinGW\lib opengl32.lib, glu32.lib (Visual Studio의 경우) dll files openGL32.dll, glu32.dll C:\Windows\System32 C:\Windows\SysWOW64 (Windows Xp 이상 운영체제에서는 자동으로 인식, 추가 안해도 됨)
14
Installation OpenGL with Eclipse (2/5)
Setup GLUT Download GLUT glutdlls37beta.zip GLUT for Win32 dll, lib and header file glut37.zip GLUT source code distribution Glut bin.zip glut.h C:\MinGW\include\GL glut32.lib C:\MinGW\lib glut32.dll C:\MinGW\bin 동작 안할 경우 C:\Windows\system32, C:\Windows\SysWOW64 glutdlls37beta.zip
15
Installation OpenGL with Eclipse (3/5)
Writing Your First OpenGL Program Launch Eclipse Create a new C++ project Select "File" menu New C++ Project Project name : HelloGL Project type : Executable Empty Project Toolchain: MinGW GCC
16
Installation OpenGL with Eclipse (4/5)
Create a new Source file Right-click on the project node “HelloGL” New Source file : “TestGL.cpp” In "Source file", enter “TestGL.cpp" ⇒ Finish. In the editor panel for “TestGL.cpp", type the source codes * NOTE: For Windows, you should include "windows.h" header before the OpenGL headers
17
Installation OpenGL with Eclipse (5/5)
Setup OpenGL Library Properties : C/C++ Build Settings Tool Setting Tab : MinGW C++ Linker Libraries Add Libraries(-l) : glut32 , glu32 , opengl32 Build All (Ctrl + B), Run (Ctrl + F11)
18
Header file Include the header files
GLUT to handle the window-managing operation #include <GL/glut.h> // GLUT, includes glu.h and gl.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>
19
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();
20
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);
21
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();
22
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 ) 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) 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 .
23
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.
24
#include <windows.h> // For MS Windows
#include <GL/glut.h> // GLUT, includes glu.h and gl.h 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. int 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. return 0;
25
Project 1 Build Project 1 Download example1 C source
Right-click on the project node Import General File System Add Existing files from “example1” folder
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.