Introduction
- Applications of Computer GraphicsComputer Graphics and Image ProcessingThe fields of computer graphics and image procesing are blending together more each year.
- Computer Graphics -- create pictures and images, synthesize them on the basis of some description, or model in a computer
Image Processing -- improve or alter images that were created elsewhereArt, Entertainment, and publishingmovie production, animation, special effectsbrowsing on the World Wide Webslide, book, and magazine designVideo Gameslatest computer graphics technologies are rapidly incorporated into latest video gamesWarcraft Halo 3 Monitoring a ProcessDisplaying Simulationse.g. virtual realityComputer-aided Designe.g. Computer-aided Architectural Design, Electrical Circuit DesignScientific Analysis and Visualizationpresenting scientific information in the right way let you gain new insights into the investigating processEduction AnimationDigital shape sampling and processing (DSSP)DSSP describes the ability to use scanning hardware and processing software to digitally capture physical objects and automatically create accurate 3D models with associated structural properties for design, engineering, inspection and custom manufacturing. What digital signal processing (DSP) is to audio, DSSP is to 3D geometry.
A Perceptron laser scanner scanned the original fan blade, and generated a point cloud with around 2.2 million points that was brought into DSSP software.
DSSP software was used to automatically generate a NURBS surface model, which could be imported into Pro/ENGINEER software.Video CompressionMPEG-4 Visual specifies support for animated face and body models within the Simple Face Animation and simple FBA ( Face and Body A nimation )a face model described by Facial Definition Parameters ( FDPs ) and animated using Facial Animation Parameters ( FAPs ).body is described by body animation parameters ( BAP )See also http://coven.lancs.ac.uk/mpeg4/
- What is OpenGL?Application programming interface ( API )a collection of routines that the programmer can call, along with a model of how the routines work together to produce graphics250 distinct commands ( about 200 core, 50 utility )Device-independent graphics programming
- produce nearly identical outputs in various hardware platforms
- no user-input commands in core
- no high-level commands for 3-D objects, one must build model from primitives -- points, lines, and polygons
- OpenGL Utility Library ( GLU ) provides many modeling features,
- Basics of OpenGL Code
- Rendering -- the process by which a computer creates images from models.
- Models or objects are constructed from geometric primitives such as points, lines, polylines, polygons which are defined by one or more vertices.
- Functions calls between glBegin() and glEnd()
Example -- drawing 3 pointsglBegin( GL_POINTS );glVertex2i( 100, 40 );glVertex2i( 120, 50 );glEnd();glVertex2i( 140, 80 );glVertex2i(...) gl
gl
libraryVertex
basic
command2
number of
argumentsi
type of
argumentsData Types:Suffix Data Type Corresponding
C typeOpenGL Type
Deinfitionb 8-bit Integer signed char GLbyte s 16-bit Integer short GLshort i 32-bit Integer int or long GLint, GLsizei f 32-bit Floating-point float GLfloat, GLclampf d 64-bit Integer double GLdouble, GLclampd ub 8-bit Unsigned Integer unsigned char GLubyte, GLboolean us 16-bit Unsigned Integer signed short GLushort ui 32-bit Unsigned Integer unsigned int or
unsigned longGLuint, GLenum, GLbitfield glVertex2i ( 7, 11 );glVertex2f ( 7.0, 11.0 );are the sameNumber of Arguments: 2, 3, 4Formats:- 'v' indicates vector format
- absence of 'v' indicates scalar format
- Example:glColor3f( 1.0, 0.0, 0.0 );GLfloat color_array[] = {1.0, 0.0, 0.0};glColor3fv( color_array );
- The Event Loop
- OpenGL programs often run in an event loop.
- After initialization, the program falls into an infinite loop accepting and handling events, such as displaying, mouse movement, window reshaping ..
- OpenGL as a State Machine
- OpenGL can be viewed as a state machine.
- state variables: color, line width, line stipple pattern, shading method, object positions ...
- On-Off state variablescan be set to GL_FALSE ( off ) or GL_TRUE ( on )glEnable ( .. ), glDisable( .. )GL_LINE_SMOOTH -- if enabled draw lines with correct filtering, otherwise draw lines with aliasing
- Mode state variablesrequire command specific to the state variable in order to change ite.g. glShadeModel ( GL_SMOOTH ) -- smooth shadingglShadeModel ( GL_FLAT ) -- flat shading ( default )
- Value state variablesrequire command specific to the state variable in order to change ite.g. glColor3f( 0.5, 0.5, 0.5 )
- Query current state
At any point, the programmer can query the system for any variable's current value. Typically, one of the four following commands is used glGetBooleanv(), glGetDoublev(), glGetFloatv(), or glGetIntegerv() - Save current state in stackA collection of state variables can be saved on an attribute stack.glPushAttrib()glPopAttrib()
- Demo Programs
- Simple Drawing
//draw.cpp : demo program for drawing 3 dots, two lines, ploylines, rectangles #include <GL/glut.h> //initialization void init( void ) { glClearColor( 1.0, 1.0, 1.0, 0.0 ); //get white background color glColor3f( 0.0f, 0.0f, 0.0f ); //set drawing color glPointSize( 4.0 ); //a dot is 4x4 glMatrixMode( GL_PROJECTION ); //subsequent calls affect projection matrices glLoadIdentity(); //replace current matrix with identity matrix gluOrtho2D( 0.0, 500.0, 0.0, 500.0 ); } void display( void ) { glClear( GL_COLOR_BUFFER_BIT ); //clear screen glBegin( GL_POINTS ); //draw points glVertex2i( 100, 50 ); //draw a point glVertex2i( 100, 150 ); //draw a point glVertex2i( 200, 200 ); //draw a point glEnd(); glBegin( GL_LINES ); //draw lines glVertex2i( 20, 20 ); //horizontal line glVertex2i( 400, 20 ); glVertex2i( 20, 10 ); //vertical line glVertex2i( 20, 400 ); glEnd(); glBegin( GL_LINE_STRIP ); //draw polyline glVertex2i( 200, 100 ); glVertex2i( 300, 100 ); glVertex2i( 450, 200 ); glVertex2i( 200, 100 ); glEnd(); glColor3f( 0.6, 0.6, 0.6 ); //bright grey glRecti( 400, 400, 450, 480 ); glColor3f( 1.0, 0.0, 0.0 ); //red glRecti( 350, 350, 380, 390 ); glFlush(); //send all output to screen } ------------------------------------------------------------------------------ //draw_main.cpp: main loop of drawing program #include <GL/glut.h> #include <math.h> #include <stdlib.h> #include <stdio.h> //initialization void init(void); //does the drawing void display(void); /* Main Loop * Open window with initial window size, title bar, * RGBA display mode, depth buffer. */ int main(int argc, char** argv) { glutInit(&argc, argv); //initialize toolkit glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB ); //set display mode: single bufferring, RGBA model glutInitWindowSize(500, 500); //set window size on screen glutInitWindowPosition( 100, 150 ); //set window position on screen glutCreateWindow(argv[0]); //open screen window init(); glutDisplayFunc (display); //points to display function glutMainLoop(); //go into perpetual loop return 0; }
-------------------------------
How to Install Dev-C++ and the GLUT Libraries for Compiling OpenGL Programs with ANSI C
No comments:
Post a Comment