DOC PREVIEW
UD CISC 181 - Introduction to Open GL

This preview shows page 1-2-3-20-21-40-41-42 out of 42 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CISC181: Introduction to OpenGLOutlineOpenGL – What is It?Event-driven GLUT program structureSimple OpenGL program (no animation)Slide 6InitializationOpenGL screen coordinatesExample: Specifying the center of a squareSlide 10Simple OpenGL programRendering Steps (no animation)Callback registration functionsExample: Keyboard callbackExample: Mouse button callbackExample: Idle callbackOpenGL Geometric PrimitivesSpecifying Geometric PrimitivesOpenGL Command FormatsDrawing: MiscellaneousWhy We Need TransformationsExample: Shape vs. Viewing IssuesSlide 23Slide 24Slide 25Transformations for modeling, viewing2-D Transformations: OpenGLExample: 2-D Translation in OpenGLExample: Order of transformationsWhy does the order of transformations seem backwards?Limiting “Scope” of TransformationsExample: Pushing, popping transformationsWhat is Texture Mapping?Texture mapping applications: BillboardsOpenGL texturing steps (Red book)Create Texture ObjectRasterization: Texture application modesTexture mapping applications: LightmapsOpenGL: Texture application modesAlpha ChannelOpenGL: Enabling and DrawingRobins’ texture tutorCISC181:Introduction to OpenGLCourse web page:http://nameless.cis.udel.edu/class_wiki/index.php/CISC181_S2010April 15, 2010Outline•OpenGL & GLUT basics–Setting up a program –2-D drawing–2-D transformations–Applying textures to shapesOpenGL – What is It?•GL (Graphics Library): Library of 2-D, 3-D drawing primitives and operations–API for 3-D hardware acceleration •GLU (GL Utilities): Miscellaneous functions dealing with camera set-up and higher-level shape descriptions•GLUT (GL Utility Toolkit): Window-system independent toolkit with numerous utility functions, mostly dealing with user interface•Course web page has links to online function references (functions from each library start with library prefix—i.e., gl*, glu*, glut*)Event-driven GLUT program structure1. Configure and open window2. Initialize OpenGL state, program variables3. Register callback functions•Display (where rendering occurs)•Resize•User input: keyboard, mouse clicks, motion, etc. (on Thursday)4. Enter event processing loopPortions of some slides adapted from “An Interactive Introduction to OpenGL Programming”,D. Shreiner, E. Angel, V. Shreiner, SIGGRAPH 2001 courseSimple OpenGL program (no animation)#include <stdio.h>#include <GL/glut.h>void main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);glutInitWindowSize(100, 100);glutCreateWindow(“hello”);init(); // set OpenGL states, variablesglutDisplayFunc(display); // register callback routinesglutMainLoop(); // enter event-driven loop}adapted from E. AngelSimple OpenGL program (no animation)#include <stdio.h>#include <GL/glut.h>void main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);glutInitWindowSize(100, 100);glutCreateWindow(“hello”);init(); // set OpenGL states, variablesglutDisplayFunc(display); // register callback routinesglutMainLoop(); // enter event-driven loop}adapted from E. AngelInitialization•glutInit: Pass command-line flags on to GLUT•glutInitDisplayMode: OR together bit masks to set modes on pixel type (indexed vs. true color), buffering, etc.•glutInitWindowSize, glutCreateWindow: Set drawing window attributes, then make it•init(): Set OpenGL state, program variables–Use GL types/typedefs GLfloat, GLint, GL_TRUE, GL_FALSE, etc. for cross-platform compatibilityvoid init() {glClearColor(0.0, 0.0, 0.0, 0.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluOrtho2D(0, right, 0, top);}sets “units” of subsequent draw commandsOpenGL screen coordinates•Bottom left corner is origin•gluOrtho2D() sets the units of the screen coordinate system•gluOrtho2D(0, w, 0, h) means the coordinates are in units of pixels•gluOrtho2D(0, 1, 0, 1) means the coordinates are in units of “fractions of window size” (regardless of actual window size)from HillExample: Specifying the center of a square(320, 240)gluOrtho2D(0, 640, 0, 480)Example: Specifying the center of a square(0.5, 0.5)11gluOrtho2D(0, 1, 0, 1)Simple OpenGL program#include <stdio.h>#include <GL/glut.h>void main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);glutInitWindowSize(100, 100);glutCreateWindow(“hello”);init(); // set OpenGL states, variablesglutDisplayFunc(display); // register callback routinesglutMainLoop(); // enter event-driven loop}adapted from E. AngelRendering Steps (no animation)•In function registered with glutDisplayFunc():1. Clear window: glClear(GL_COLOR_BUFFER_BIT)2. Draw shapes•Set colors, patterns, point/line sizes•Specify type of geometric primitive(s) and list vertices3. Make offscreen draw buffer the display buffer with glutSwapBuffers()Callback registration functions •Render glutDisplayFunc()•Key down in window glutKeyboardFunc()•Key up in window glutKeyboardUpFunc()•Button press/release glutMouseFunc() •Mouse motion glutMotionFunc() (with button down)•Window reshaping glutResizeFunc() •Nothing happening glutIdleFunc() •Passive motion, other input devices, etc.: Look these up on GLUT reference pages on webExample: Keyboard callback•What key has been pressed and where the cursor is:glutKeyboardFunc(keyboard);void keyboard(unsigned char key, int x, int y){ switch(key) { case ‘q’ : case ‘Q’ : exit(1); break; case ‘r’ : case ‘R’ : rotate_mode = GL_TRUE; break; }}Example: Mouse button callback•Which mouse button, where, and has it been pressed or released:glutMouseFunc(mouse);void mouse(int button, int state, int x, int y){ if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_DOWN) { left_down = TRUE; mouse_x = x; mouse_y = y; } else if (state == GLUT_UP) left_down = FALSE; }}Example: Idle callback•Use for animation and continuous updateglutIdleFunc(idle);void idle(void){// change position variables, etc. t += dt;// call glutDisplayFunc() callback ASAP glutPostRedisplay();}OpenGL Geometric PrimitivesSpecifying Geometric Primitives•Primitives are specified usingglBegin(primType);...glEnd();–primType determines how vertices are combinedGLfloat red, green, blue;GLfloat x, y;glBegin(primType);for (i = 0; i < nVerts; i++) { glColor3f(red, green, blue); glVertex2f(x, y); ... // change


View Full Document
Download Introduction to Open GL
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Open GL and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Open GL 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?