Introduction to OpenGL (IDE: Eclipse)

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++.
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
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.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
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 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
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
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 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.
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.
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.
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
Introduction to OpenGL
Chapter 3 Computer Graphics Software
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 (IDE: Eclipse)

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

Installation C/C++ with Eclipse (1/5) Install Eclipse Cpp Neon (통합개발환경 설치) Download Eclipse: http://www.eclipse.org/downloads/ Eclipse IDE for C/C++ Developers Java for Windows Missing - install a Java Runtime Environment (JRE)    Oracle JRE 1.8.0

Installation C/C++ with Eclipse (2/5) Install CDT in Eclipse (C/C++ 개발 툴 설치) Select Menu: Help  Install New Software… http://download.eclipse.org/tools/cdt/releases/kepler/

Installation C/C++ with Eclipse (3/5) Install MinGW (GCC 컴파일러 설치) Download MinGW : http://www.mingw.org/ Select Package in MinGW Installation Manager mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base Select Menu: InstallationApply Changes Setup System Variable : Add Path “C:\MinGW\bin”

Installation C/C++ with Eclipse (4/5) Setup Preferences about MinGW in Eclipse (환경 설정) Select WindowsPreferences C/C++New C/C++ Project WizardMakefile Project Binary Parsers : Select GNU Elf Parser Building Setting Uncheck “Use default build command” Build command: Mingw32-make.exe

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)

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

Installation OpenGL with Eclipse (2/5) Setup GLUT Download GLUT https://www.opengl.org/resources/libraries/glut/glut_downloads.php 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:\MinGW\include\GL glut32.lib  C:\MinGW\lib glut32.dll  C:\MinGW\bin 동작 안할 경우  C:\Windows\system32, C:\Windows\SysWOW64 glutdlls37beta.zip

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

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

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)

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>

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

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

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