OpenGL Basic Drawing 2003 Spring Keng Shih-Ling

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

Department of nskinfo i-education
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…
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
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.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Computer Graphics (Fall 2003) COMS 4160, Lecture 6: OpenGL 2 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
CENG477 Introduction to Computer Graphics Introduction to OpenGL, GLUT and GLUI.
1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Chapter 03: Graphics Primitives Course web page: Chapter #3.
Reference1. [OpenGL course slides by Rasmus Stenholt]
1 GLUT Callback functions Event-driven: Programs that use windows  Input/Output  Wait until an event happens and then execute some pre-defined functions.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Lecture 3 OpenGL.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
State Management and Drawing Geometry Objects
 “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.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Introduction to OpenGL Programming RedBook OpenGL.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
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.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
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.
CSCE 441: Computer Graphics
Introduction to OpenGL Programming
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Computer Graphics Comp 175 Chapter 2
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
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.
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.
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Computer Graphics Lecture 33
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Lecture 12: OpenGL Li Zhang Spring 2008
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

OpenGL Basic Drawing 2003 Spring Keng Shih-Ling <kensl@csie.nctu.edu.tw>

Example (GLUT)

Example (GLUT) #include <GL/glut.h> void display(void) { /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); /* draw white polygon (rectangle) with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glColor3f (1.0, 1.0, 1.0); glBegin(GL_POLYGON); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); /* don't wait! * start processing buffered OpenGL routines */ glFlush (); }

Example (GLUT) void init (void) { /* select clearing (background) color */ glClearColor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); } /* * Declare initial window size, position, and display mode * (single buffer and RGBA). Open window with "hello" * in its title bar. Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */

Example (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ }

OpenGL Command Syntax -1 OpenGL constants prefix by GL_. OpenGL routines prefixed by gl and suffiexed by the number of arguments and type. glVertex2i, glNormal3f, glTexCoord2fv…etc

OpenGL Command Syntax -2

OpenGL as a State Machine -1 OpenGL is a state machine. You put it into various states (or modes) that then remain in effect until you change them. As you've already seen, the current color is a state variable Many state variables refer to modes that are enabled or disabled with the command glEnable() or glDisable().

OpenGL as a State Machine -2 Each state variable or mode has a default value, and at any point you can query the system for each variable's current value. Typically, you use one of the six following commands to do this: glGetBooleanv(), glGetDoublev(), glGetFloatv(), glGetIntegerv(), glGetPointerv(), or glIsEnabled().

GLUT: Overview A very useful framework for rapid OpenGL program development. Portable through lots of platforms. Provide basic window, input, and event management. Callback event handler. Idle routine and timer. A simple, cascading popup menu facility. Offers lots of basic object. (wireframe/solid) …

GLUT: Initialize and creating a window -1 glutInit( int* argc, char** argv ); Initialize GLUT and process any command line arguments. This should be called before any GLUT routines. glutInitDisplayMode( unsigned int mode ); Specify whether to apply RGBA mode or color-indexed mode. GLUT_RGBA, GLUT_INDEX… Single or double buffering. GLUT_SINGLE, GLUT_DOUBLE… Other buffers. GLUT_DEPTH, GLUT_STENCIL, GLUT_ACCUM…

GLUT: Initialize and creating a window -2 glutInitWindowPosition( int x, int y ); Specify the screen location of your window glutInitWindowSize( int w, int h ); Specify the size of your window in pixels. glutCreateWindow( char* pTitle ); Create a window with OpenGL context for rendering. The window will appear until glutMainLoop() is called.

GLUT: Callback function -1 Callback functions are not called by you. They are called by GLUT. You can register some functions to GLUT, and they can be called when meeting the situation. Some types of callback Window event handler IO event handler Global handler

GLUT: Callback function -2 glutDisplayFunc( void (*pfn)(void) ); Display callback; GLUT called it when the content of the window needed to be updated. You call manually call glutPostRedisplay() to arbitrarily ask GLUT to call that callback function. glutReshapeFunc( void (*pfn)( int w, int h ) ); GLUT called it when the size of window is changed. Recalculate view frustum & viewport…

GLUT: Callback function -3 glutKeyboardFunc( void(*pfn)(unsigned char key, int x, int y )); and glutMouseFunc( void(*pfn)( int button, int state, int x, int y )); User Input event handler. glutMotionFunc( void(*pfn)( int x, int y )); GLUT call this registered callback function when the mouse is moved while a mouse button is also pressed. glutIdleFunc( void(*pfn)(void)); GLUT call this registered callback function when idling. You can simply call: glutIdleFunc( glutPostRedisplay );

Start GLUT framework glutMainLoop(); Like Win32’s message loop. Start all GLUT operations.

GLUT: Simple 3D objects drawing support -1 GLUT includes several 3D objects drawing: Cone, cube, sphere, dodecahedron, icosahedron, octahedron, teapot, tetrahedron, torus. Both wireframe and solid. glutWireCube, glutSolidSphere … etc. These objects are drawn centered at the origin of the world coordinate system.

GLUT: Simple 3D objects drawing support -2 You can try this simple display callback function and see the result. void display(void) { glClear( GL_COLOR_BUFFER_BIT ); glutWireCube( 1.0 ); glFlush(); }

A Drawing Survival Kit -1 Clearing the window glClear( GLbitfield mask ); GL_COLOR_BUFFER_BIT -> glClearColor( … ); GL_DEPTH_BUFFER_BIT -> glClearDepth( … ); Specifying a color glColor3f( GLfloat r, GLfloat g, GLfloat b ); glIndexi( int i ); glutSetColor( int i, GLfloat r, GLfloat g, GLfloat b ); for setting indexed color.

A Drawing Survival Kit -2 Specifying Vertices glVertex{2,3,4}{sifd}[v]( … ); Ex: glVertex3f( 1.0f, 0.5f, 2.0f ); Vertex array Not introduced here.

A Drawing Survival Kit -3 OpenGL Geometric Drawing Primitives glBegin( GLenum mode ); mode is GL_POLYGON, GL_LINES … etc glEnd(); All primitives should be placed between these two OpenGL routines Ex glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(6.0, 1.5); glVertex2f(4.0, 0.0);

A Drawing Survival Kit -4

A Drawing Survival Kit -5 Valid calls between glBegin(…); & glEnd(); glVertex*(); glNormal*(); glColor*(); glIndex*(); glTexCoord*(); glMaterial*(); … Forcing Completion of Drawing glFlush(void); Asynchronous glFinish(void); Synchronous glutSwapBuffers(void); Swap back buffer and front buffer. (Double buffering for animation)

A Drawing Survival Kit -6 Basic State Management glEnable( … ); Enable some state. Ex: glEnable( GL_LIGHTING ); glDisable( … ); Disable some state. Ex. glDisable( GL_TEXTURE_2D ); glIsEnabled( … ); Query if the specific state is enabled. Ex: glIsEnabled( GL_BLEND ); glGetBooleanv(…); glGetIntegerv(…); glGetFloatv(…); glGetDoublev( … ); glGetPointerv(…); Query the specific state value. Ex: glGetIntegerv( GL_VIEWPORT, vp );

A Drawing Survival Kit -7 Polygon Detail glPolygonMode( GLenum face, GLenum mode ); face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK mode: GL_POINT, GL_LINE, GL_FILL glFrontFace( GLenum mode ); mode: GL_CCW(default), GL_CW glCullFace( GLenum mode ); mode: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK glEnable( GL_CULL_FACE );

A Drawing Survival Kit -8 Specifying a Shading Model glShadeModel( GLenum mode ); mode: GL_SMOOTH(default), GL_FLAT

Any Question? ?