Computer Graphics Lecture 33

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
Based on slides created by Edward Angel
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
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.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- Programming with OpenGL I.
School of Computer Science University of Seoul. 1. Interaction 2. Input Devices 3. Clients and Servers 4. Display Lists 5. Programming Event-Driven Input.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
Lecture 3 OpenGL.
Computer Graphics I, Fall 2010 Input and Interaction.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
Managing Multiple Windows with OpenGL and GLUT
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
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.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
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: –
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- Programming with OpenGL 2.
University of New Mexico
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week.
Introduction to OpenGL Programming
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
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
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
SPACE SHUTTLE LAUNCHING GUIDE Mis. V.R.PRATIMA Mr. ASWIN KUMAR PUNITH.K PAUL SUDEEP.G Submitted by.
Introduction to Graphics Programming. Graphics API.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Basic Program with OpenGL and GLUT
Computer Graphics Lecture 32
CSC461 Lecture 8: Input Devices
Advanced Graphics Algorithms Ying Zhu Georgia State University
The User Interface Lecture 2 Mon, Aug 27, 2007.
Computer graphic -- Programming with OpenGL 2
Advanced Menuing, Introduction to Picking
גרפיקה ממוחשבת: מבוא ל-OpenGL
Rendering Pipeline, OpenGL/GLUT
Drawing in the plane 455.
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Introduction to OpenGL
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Programming with OpenGL Part 2: Complete Programs
Basic OpenGL programming, Geometric objects & User Interaction
Managing Multiple Windows with OpenGL and GLUT
Programming with OpenGL Part 2: Complete Programs
OpenGL, GLUT, Transformations I Week 2, Wed Jan 16
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Computer Graphics Lecture 33

OpenGL Programming Taqdees A. Siddiqi cs602@vu.edu.pk

Many OpenGL functions are used specifically for drawing objects such as points, lines, polygons, and bitmaps.

Some functions control the way that some of this drawing occurs (such as those that enable antialiasing or texturing). Other functions are specifically concerned with framebuffer manipulation.

The topics discussed here describe how all of the OpenGL functions work together to create the OpenGL processing pipeline. Here we also take a closer look at the stages in which data is actually processed, and tie these stages to OpenGL functions.

The following diagram details the OpenGL processing pipeline The following diagram details the OpenGL processing pipeline. For most of the pipeline, you can see three vertical arrows between the major stages.

These arrows represent vertices and the two primary types of data that can be associated with vertices: color values and texture coordinates.

Writing a program, using OpenGL, for any of the operating system we can use OpenGL Utility Library name glut.

glut is platform independent. glut can: create window get keyboard input and run an event handler or message loop of application

Functions start with the prefix “gl” are the core OpenGL functions and those start with “glu” or “glut” are the OpenGL utility library functions.

Let’s write a program using “glut” and also OpenGL function to create graphics.

#include <GL/glut.h> int main() { glutCreateWindow( "first graphics window" ); }

String argument in the window is used as window name. glutCreateWindow creates a top-level window.   String argument in the window is used as window name.

Implicitly, the current window is set to the newly created window. Each created window has a unique associated OpenGL context.

window's display state is not actually acted upon until glutMainLoop is entered. This means until glutMainLoop is called, rendering to a created window is ineffective.

The int value returned is a unique identifier for the window. identifiers starts from one, identifier can be used for calling glutSetWindow.

Now we will use more features of glut library in a sample program provided you in the notes; here we will discuss them in details.

glutInitDisplayMode

glutInitDisplayMode sets the initial display mode. void glutInitDisplayMode ( unsigned int mode); Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.

Modes have values: GLUT_RGBA Bit mask to select an RGBA mode window. This is the default if neither GLUT_RGBA nor GLUT_INDEX are specified.

GLUT_RGB An alias for GLUT_RGBA. GLUT_INDEX Bit mask to select a color index mode window. This overrides GLUT_RGBA.

GLUT_SINGLE Bit mask to select a single buffered window GLUT_SINGLE Bit mask to select a single buffered window. This is the default. GLUT_DOUBLE Bit mask to select a double buffered window. This overrides GLUT_SINGLE if it is also specified.

GLUT_ACCUM Bit mask to select a window with an accumulation buffer. GLUT_ALPHA Bit mask to select a window with an alpha component to the color buffer(s).

GLUT_DEPTH Bit mask to select a window with a depth buffer. GLUT_STENCIL Bit mask to select a window with a stencil buffer.

GLUT_MULTISAMPLE Bit mask to select a window with multisampling support. If multisampling is not available, a non-multisampling window will automatically be chosen.

GLUT_STEREO Bit mask to select a stereo window. GLUT_LUMINANCE Bit mask to select a window with a ``luminance'' color model.

glutReshapeWindow

glutReshapeWindow requests a change to the size. void glutReshapeWindow(int width, int height); New width and height of window in pixels.

This requests a change in the size of the current window This requests a change in the size of the current window. The width and height parameters are size extents in pixels. The width and height must be positive values.

The requests by glutReshapeWindow is executed after returning to the main event loop. This allows multiple glutReshapeWindow, glutPositionWindow, and glutFullScreen requests with same window be coalesced.

glutKeyboardFunc

glutKeyboardFunc sets the keyboard callback for the current window. void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)); func The new keyboard callback function.

glutKeyboardFunc sets the keyboard callback for the current window glutKeyboardFunc sets the keyboard callback for the current window. When a user types into the window, each key press generating an ASCII character will generate a keyboard callback.

The x and y callback parameters indicate the mouse location in window relative coordinates when the key was pressed.

glutDisplayFunc

glutDisplayFunc sets the display callback for the current window. void glutDisplayFunc(void (*func)(void)); func The new display callback function.

glutDisplayFunc sets the display callback for the current window glutDisplayFunc sets the display callback for the current window. When GLUT determines that the normal plane for the window needs to be redisplayed, the display callback for the window is called.

GLUT determines when the display callback should be triggered based on the window's redisplay state. The redisplay state for a window can be either set explicitly by calling glutPostRedisplay or implicitly as the result of window damage reported by the window system.

glutReshapeFunc

glutReshapeFunc sets the reshape callback for the current window. void glutReshapeFunc(void (*func)(int width, int height)); func The new reshape callback function.

glutReshapeFunc sets the reshape callback for the current window; triggered when a window is reshaped. Also triggered immediately before a window's first display callback after a window is created or whenever an overlay for the window is established.

The width and height parameters of the callback specify the new window size in pixels. Before the callback, the current window is set to the window that has been reshaped.

This default callback will simply call glViewport(0,0,width,height) on the normal plane. If an overlay is established for the window, a single reshape callback is generated. If a top-level window is reshaped, subwindows are not reshaped.

glutIdleFunc

glutIdleFunc sets the global idle callback. void glutIdleFunc(void (*func)(void));

glutIdleFunc sets the global idle callback to be func so a GLUT program can perform background processing tasks or continuous animation when window system events are not being received.

If enabled, the idle callback is continuously called when events are not being received. Programs with multiple windows and/or menus should explicitly set the current window and/or current menu and not rely on its current setting.

In general, not more than a single frame of rendering should be done in an idle callback. Passing NULL to glutIdleFunc disables the generation of the idle callback

glutMainLoop

glutMainLoop enters the GLUT event processing loop. void glutMainLoop(void); glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program.

glutSwapBuffers

glutSwapBuffers swaps the buffers of the current window if double buffered. void glutSwapBuffers(void); Performs a buffer swap on the layer in use for the current window.

Promotes the contents of the back buffer of the layer in use of the current window to become the contents of the front buffer. The contents of the back buffer then become undefined. The update typically takes place during the vertical retrace of the monitor.

An implicit glFlush is done by glutSwapBuffers before it returns An implicit   glFlush is done by glutSwapBuffers before it returns. Subsequent OpenGL commands are not executed until the buffer exchange. If the layer in use is not double buffered, glutSwapBuffers has no effect.