Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.

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
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
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.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
InteractionHofstra University1 Graphics Programming Input and Interaction.
Device Independent Graphics and OpenGL
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
InteractionHofstra University1 Graphics Programming Input and Interaction.
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.
Graphics not part of C++ libraries –X libraries –QT library –OS specific.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Chapter 03: Graphics Primitives Course web page: Chapter #3.
Programming with OpenGL and GLUT
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Interaction with Graphics System
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Lecture 3 OpenGL.
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.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Managing Multiple Windows with OpenGL and GLUT
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
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: –
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
NoufNaief.net TA: Nouf Al-harbi.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
Project 2 Function Plotter Mon, Sep 22, 2003 Due Mon, Sep 29, 2003.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
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
Introduction to the Mouse
Computer Graphics Lecture 33
The User Interface Lecture 2 Mon, Aug 27, 2007.
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Coordinate Systems and Transforming the Coordinates
Introduction to OpenGL
OpenGL program.
2D Graphics Lecture 4 Fri, Aug 31, 2007.
Presentation transcript:

Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003

Graphics Libraries Theoretically, with only a function setPixel(x, y, red, green, blue), we could create any graphics image. However, it would be quite tedious. A graphics library provides an abundance of useful functions to simplify the task of creating graphics.

Device Independence A library is device-independent if it provides a common API, regardless of the hardware on which it is used. The OpenGL API for Windows is identical to the OpenGL API for the Macintosh. Of course, the library must be compiled separately for each hardware system.

Windows-Based Programming OpenGL consists of three libraries gl – graphics library  Basic functions. glu – graphics library utility  Composites of basic GL functions. glut – graphics library utility toolkit  Functions that interact with the windowing system.

Window-based Programming int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(screenWidth, screenHeight); glutInitWindowPosition(100, 150); glutCreateWindow(“My Window Title"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); init(); glutMainLoop(); return 0; }

The glut functions are used in main() to create and open a graphics window. Functions used to create a graphics window. glutInit(&argc, argv). glutInitDisplayWindow(options). glutInitWindowSize(width, height). glutInitWindowPosition(x, y). glutCreateWindow(name). Window-Based Programming

Windows-Based Programming glutInitglutInit(&argc, argv). Initializes the glut library. Should be called before any other glut function. Must receive the command-line arguments. glutInitDisplayModeglutInitDisplayMode(options). Specifies color mode. Specifies single or double buffering.

Windows-Based Programming glutInitWindowSizeglutInitWindowSize(width, height). Sets the height and width of the window in pixels. glutInitWindowPositionglutInitWindowPosition(x, y). Sets the position of the upper left corner of the window. glutCreateWindowglutCreateWindow(name). Creates, but does not display, the window.

Callback Functions A callback function is a user-specified function that the library will call whenever necessary. Each callback function must be registered with glut. glut provides for over 20 callbacks.callbacks

Callback Functions The glut library contains functions with names of the form glutXXXFunc(parameter), where XXX stands for some form of windows interaction (mouse, keyboard, etc.). The parameter is a user-defined function xxx().

Callback Functions In the main function we write glutXXXFunc(xxx). Then when XXX is activated by the user (mouse click, keystroke, etc.), the function xxx() is called to handle the event.

OpenGL Callback Functions glutDisplayFuncglutDisplayFunc(display); Called whenever the scene needs to be redrawn. Activated by calls to glutPostRedisplay(). glutReshapeFuncglutReshapeFunc(reshape); Called whenever the window is resized. Activated by resizing the window. Warning: This does not respond to iconifying the window.

OpenGL Callback Functions glutMouseFuncglutMouseFunc(mouse) Called whenever the mouse is clicked. Activated by mouse clicks. Left or right, up or down. glutKeyboardFuncglutKeyboardFunc(keyboard) Called whenever a key is pressed. Activated by keystrokes (down only) of an ASCII key (letters, digits, punctuation).

OpenGL Callback Functions glutSpecialFuncglutSpecialFunc(special) Called whenever a special key is pressed. Activated by keystrokes (down only) of a non-ASCII key (function key, arrow key, etc.). glutMotionFuncglutMotionFunc(motion) Called whenever the mouse is moved while the button is pressed.

OpenGL Callback Functions glutPassiveMotionFuncglutPassiveMotionFunc(passiveMotion) Called whenever the mouse is moved while the button is not pressed. glutIdleFuncglutIdleFunc(idle) Called whenever nothing else is happening.

The Main Loop Typically main() ends by calling glutMainLoop() This function runs forever. It calls the callback functions as necessary. It handles all drawing commands as they are generated.

The Main Loop main display reshape keyboard mouse Process keyboard and mouse events glutMainLoop() display() mouse() keyboard() reshape() Library Functions

Example: Callback Functions CallbackTest.cpp

Other Initializations void init() { glClearColor(0.8, 0.8, 0.8, 0.0); // light gray glColor3f(0.0f, 0.0f, 0.0f); // black glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(xmin, xmax, ymin, ymax); glViewport(0, 0, screenWidth, screenHeight); }

World Coordinates The call to gluOrtho2D() establishes the world coordinates of the window. gluOrtho2D(xmin, xmax, ymin, ymax) The x-coordinates go from xmin to xmax from left to right. The y-coordinates go from ymin to ymax from bottom to top.

Example: Draw a 2D Object DrawTeapot.cpp