OpenGL Programming Related Links The Official OpenGL Website OpenGL v1.1 Redbook

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++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
COMPUTER GRAPHICS SOFTWARE.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Chapter 2: Graphics Programming
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Pemrograman OpenGL Dasar
TOPIC 3 INTRODUCTION TO OPENGL CGMB214: Introduction to Computer Graphics.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
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.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
Development of Interactive 3D Virtual World Applications
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
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.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS 480/680 Computer Graphics Programming with Open GL Part 1: Background Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL Part 1: Background
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
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 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 1: Background Ed Angel Professor Emeritus.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Computer Graphics I, Fall 2010 Working with Callbacks.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- Programming with OpenGL 2.
Programming With OpenGL
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
Lecture 2: Introduction to OpenGL
Introduction to OpenGL Programming
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Basic Program with OpenGL and GLUT
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
Working with Callbacks
Computer Graphics Lecture 33
Working with Callbacks
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Programming with OpenGL Part 1: Background
OpenGL Background CS 4722.
OpenGL-Rendering Pipeline
Presentation transcript:

OpenGL Programming Related Links The Official OpenGL Website OpenGL v1.1 Redbook OpenGL Specifications OpenGL Extension Registry GLUT NeHe OpenGL Tutorials

OpenGL Rendering Pipeline Vertex Data Pixel Data Display List Evaluators Pixel Operations Vertex Operations Primitive Assembly Rasterization Texture Assembly Fragment Operations Frame Buffer OpenGL can be considered as a state machine. It has many states (modes) that control various aspects of the rendering pipeline. These states remain effective until you change them.

Vertex Operations Modeling, Viewing and Projection transformations Lighting calculations Automatic texture coordinate generation Primitive Assembly Assemble vertices into groups of triangles Clipping Polygon face culling Perspective division and viewport mapping Display ListStore OpenGL commands for later use Evaluators Convert curves and surfaces that are described by parametric equations into vertex data. (Tessellation)

Rasterization Convert vertex and pixel data into fragments Polygon shading Fragment: A square area corresponding to a pixel. Fragment Operations Apply texel (texture element) Fog effect calculations Antialiasing Scissor, alpha, stencil and depth tests Blending, dithering, logical operations and frame buffer masking Pixel Operations Pixel data packing and unpacking Pixel scaling, biasing and clamping Transfer pixel data inside frame buffer Transfer pixel data from frame buffer to texture memory Texture AssemblyTexture storage, sampling and mapping

GLU (OpenGL Utility Library) OpenGL Related Libraries A set of API functions that use low level OpenGL functions to perform some high level operations. GLU is part of OpenGL standard. Viewing and projection transformation Polygon tessellation Quadric Surfaces NURBs Platform Specific OpenGL Extensions GLX for X Window System WGL for Microsoft Windows AGL for Apple Macintosh OpenGL Extensions Libraries that add new OpenGL functions

GLUT (OpenGL Utility Toolkit) A platform independent toolkit for OpenGL programming. GLUT is written by Mark Kilgard and is not part of OpenGL standard. Window management functions for OpenGL rendering Callback driven event processing for input devices Idle routine and timers Simple pop-up menu Simple bitmap and outline fonts Utility functions to generate various solid and wire frame objects Headers and Libraries APIHeaderImport LibraryDynamic Linked Library OpenGLgl.hopengl32.libopengl32.dll GLUglu.hglu32.libglu32.dll GLUTglut.hglut32.libglut32.dll

For X Window system: #include Platform specific header files: For Microsoft Windows: #include OpenGL header file: #include GLU header file: #include OpenGL extension header file: #include “glext.h” GLUT header file: #include glext.h can be downloaded from OpenGL Extension Registry glut.h implicitly includes gl.h and glu.h. glut.h also contains linker directives that automatically include necessary library files.

OpenGL Command Syntax OpenGLGLUGLUTWGLGLXAGL gl*glu*glut*wgl*glX*agl* Prefix Suffix and OpenGL data type SuffixData typeC typeOpenGL type definition b8-bit integercharGLbyte s16-bit integershortGLshort i32-bit integerint, longGLint, GLsizei f32-bit floating pointfloatGLfloat, GLclampf d64-bit floating pointdoubleGLdouble, GLclampd ub8-bit unsigned integerunsigned charGLubyte, GLboolean us16-bit unsigned integerunsigned shortGLushort ui32-bit unsigned integerunsigned int, unsigned long GLuint, GLenum, GLbitfield

Example: glVertex2i(1, 3); glVertex3f(1.0, 2.0, 3.0); A suffix of v indicates the command takes a pointer to an array of values instead of a series of individual arguments. Example: glColor3f(1.0, 0.0, 0.0); GLfloat color_array[3] = {1.0, 0.0, 0.0}; glColor3fv(color_array); GLclampf and GLclampd indicate floating point data types that need to be clamped between –1.0 and 1.0. v-suffix

Using OpenGL in Windows Program Create a Window Obtain Device Context Set Pixel Format Create OpenGL Rendering Context Initialize OpenGL Rendering States Render Using OpenGL Delete OpenGL Rendering Context Release Device Context Destroy Window

Create a Window HWND hWnd = CreateWindow(......); Obtain Device Context HDC hDC=GetDC(hWnd); Set Pixel Format PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion=1; pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType=PFD_TYPE_RGBA; pfd.cColorBits=24; pfd.cDepthBits=16; pfd.cStencilBits=0; int pixelFormat = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, pixelFormat, &pfd);

Create OpenGL Rendering Context Delete OpenGL Rendering Context Release Device Context HGLRC hRC=wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); Double Buffer Swapping SwapBuffers(hDC);

GLUT Window Management Functions void glutInit(int *argc, char **argv) void glutInitDisplayMode(unsigned int mode) modemeaning GLUT_RGBUse RGB color mode GLUT_INDEXUse color index mode GLUT_ALPHAUse alpha component GLUT_SINGLEUse single color buffer GLUT_DOUBLEUse double color buffers GLUT_DEPTHUse depth buffer GLUT_STENCILUse stencil buffer Initialize GLUT and process command line arguments. Initialize display mode.

void glutInitWindowPosition(int x, int y) void glutInitWindowSize(int width, int height) void glutCreateWindow(char *s) Initialize window position, in pixels, relative to upper left corner of the screen. Initialize window size in pixels. Create a window with string *s as window title. void glutFullScreen(void) Switch to full screen mode void glutSetWindowTitle(char *s) Set window title to string *s void glutReshapeWindow(int width, int height) Change window size.

cursor: GLUT_CURSOR_RIGHT_ARROW GLUT_CURSOR_LEFT_ARROW GLUT_CURSOR_INFO GLUT_CURSOR_HELP GLUT_CURSOR_WAIT GLUT_CURSOR_TEXT GLUT_CURSOR_CROSSHAIR GLUT_CURSOR_NONE void glutSetCursor(int cursor) Set cursor image void glutMainLoop(void)Start even loop and begin event processing.

GLUT Callback Functions void glutDisplayFunc(void (*func)(void)) Define the display callback function. This function is called when a screen redraw event is processed. Post a screen redraw event in the event queue, thus forcing a screen redraw. void glutPostRedisplay(void) void glutReshapeFunc(void (*func)(int w, int h)) Define the reshape callback function. This function is called when the window size changes. w:new window width h:new window height

void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)) Define the keyboard callback function. This function is called when a key with ASCII code is pressed. void glutSpecialFunc(void (*func)(int key, int x, int y)) Define the special keyboard callback function. This function is called when a special key is pressed. key:ASCII code of the key. x, y:Mouse cursor coordinates relative to upper left corner of the window. key:Code of the special key. x, y:Mouse cursor coordinates relative to upper left corner of the window. Escape, Backspace, and Delete keys are generated as ASCII characters. Escape:27 Backspace:8 Delete:127

Codes for special keys in GLUT: GLUT_KEY_Fn Fn function key. n = 1, 2, …, 12 GLUT_KEY_LEFT Left directional key. GLUT_KEY_UP Up directional key. GLUT_KEY_RIGHT Right directional key. GLUT_KEY_DOWN Down directional key. GLUT_KEY_PAGE_UP Page up key. GLUT_KEY_PAGE_DOWN Page down key. GLUT_KEY_HOME Home key. GLUT_KEY_END End key. GLUT_KEY_INSERT Insert key. int glutGetModifiers(void) Returns the state of modifier keys (SHIFT, CTRL and ALT). Must be called in a keyboard or mouse callback function. Masks for return value: GLUT_ACTIVE_SHIFT; GLUT_ACTIVE_CTRL; GLUT_ACTIVE_ALT; state = glutGetModifiers(); if (state & GLUT_ACTIVE_CTRL) {Ctrl key is down;}

void glutMouseFunc(void (*func)(int button, int state, int x, int y)) button: GLUT_LEFT_BUTTO N; GLUT_MIDDLE_BUTTO N; GLUT_RIGHT_BUTTO N; state:GLUT_UP (release); GLUT_DOWN (press); x, y:Mouse cursor coordinates relative to upper left corner of the window Define the mouse callback function. This function is called when a mouse button is pressed or released. void glutMotionFunc(void (*func)(int x, int y)) Defines the mouse motion callback function. This function is called when the mouse moves within the window while one or more buttons are pressed. void glutPassiveMotionFunc(void (*func)(int x, int y)) Defines the mouse passive motion callback function. This function is called when the mouse moves within the window with no buttons pressed.

void glutTimerFunc(unsigned int t, void (*func)(int value), int value) t:Time interval (in milliseconds) before generating timer event func:Timer callback function value:An integer value passed to the timer callback function Define timer callback function. This function is called when a timer event is processed. The timer event is only generated once. void glutIdleFunc(void (*func)(void)) Define idle callback function. This function is called when the operating system is in idle state. This is useful for processing background tasks.

Obtain OpenGL Information void GLubyte *glGetString(GLenum name) Return a pointer to a string that contains required OpenGL information. name:GL_VENDOR GL_RENDERER GL_VERSION GL_EXTENSIONS GL_VENDOR returns the name of the company responsible for the OpenGL implementation. GL_RENDERER returns an identifier for the OpenGL renderer. GL_VERSION returns a version string with the following format: where has the following format. or..

OpenGL Extensions glGetString(GL_EXTENSIONS) returns a pointer to a string that contains all supported OpenGL extension names, separated by space. Extension Name Conventions Extension nameMeaningNames for functions and symbolic constants GL_ARB_*ARB approved extensionglCommandARB() GL_DEFINITION_ARB GL_EXT_*Extension supported by more than one company glCommandEXT() GL_DEFINITION_EXT GL_XYZ_*Extension supported by company XYZ glCommandXYZ() GL_DEFINITION_XYZ

When an ARB approved extension gets promoted to core feature in a new OpenGL version, the string “ARB” is removed from names of extension functions and symbolic constants, but the extension name remains unchanged. Extension nameFunctionality GL_ARB_multitextureMultitexture GL_ARB_texture_cube_mapCube environment map GL_ARB_vertex_programVertex program for vertex shaders GL_ARB_fragment_programFragment program for pixel shaders GL_NV_*Extensions of NVidia Corporation GL_ATI_*Extensions of ATI Technologies Inc. More information about OpenGL extensions at OpenGL Extension Registry: Examples of OpenGL extensions:

Use OpenGL Extension on Microsoft Windows 1.Include header files glext.h and wglext.h 2.Use glGetString(GL_EXTENSIONS) to check extension support. 3.Use wglGetProcAddress() to get pointers to extension functions. PFNGLACTIVETEXTUREARBPROC glActiveTexture; glActiveTexture=(PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB"); PFNGLACTIVETEXTUREPROC glActiveTexture; glActiveTexture=(PFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTexture"); Example: For all OpenGL versions that support GL_ARB_multitexture: For OpenGL version 1.3 and higher:

OpenGL State Management void glEnable(GLenum cap) void glDisable(GLenum cap) Turns on a capability Turns off a capability GLboolean glIsEnabled(GLenum cap) Check if a capability is turned on. Return GL_TRUE if on; GL_FLASE if off. void glGetBooleanv(GLenum pname, GLboolean *pvalue) void glGetIntegerv(GLenum pname, GLint *pvalue) void glGetFloatv(GLenum pname, GLfloat *pvalue) void glGetDoublev(GLenum pname, GLdouble *pvalue) void glGetPointerv(GLenum pname, GLvoid *pvalue) Get state variables Example (Get current rendering color set by glColor): GLfloat color[4]; glGetFloatv(GL_CURRENT_COLOR, color);