Intro to OpenGL (Version 2) - University of Iowa

Intro to OpenGL (Version 2) - University of Iowa

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: http://www.xmission.com/~nate/glut.html Download the .zip file, unzip it and store it in a convenient directory on your drive I stored everything in h:/documents/glut

Setting up the Compiler You need to tell the compiler where the header file is. One way is instead of using #include , which assumes that the glut header file is in a standard location, you can use #include h:/documents/glut/glut.h. Then the compiler will look at this location. An easy way to handle the .dll file is to copy it to the location of your executable file, perhaps: H:\testProgram\debug Setting up a Window with GLUT Learn about glut here:

http://www.opengl.org/developers/docume ntation/glut/spec3/spec3.html glutInit(argc, argv); /* initialize glut */ glutInitWindowSize(int width, int height); /* set the window size. 300x300 by default */ glutInitWindowPosition(x, y); /* set the window position, default 1, -1, which means let the operating system decide */ glutInitDisplayMode Use glutInitDisplayMode( GLUT_RGBA |

GLUT_SINGLE | GLUT_DEPTH ) Provides RGB color rather than indexed color A single frame buffer, rather than double buffering A depth buffer Opening a Window int glutCreateWindow(char *name); Returns an integer identifier for the window No drawing is effective until glutMainLoop

Several windows or subwindows may be opened. Windows may be resized or repositioned Window and display modes are system states that may be set and queried The Main Loop Glut allows you to define callbacks: void glutDisplayFunc(void (*func)(void)); void glutReshapeFunc(void (*func)(int width, int height)); void glutKeyboardFunc(void (*func) (unsigned char key, int x, int y));

void glutMouseFunc(void (*func)(int button, int state, int x, int y)); void glutMainLoop(void); Working with OpenGL Get information from here (as well as other sources) http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/ SGI_Developer/OpenGL_PG/ Clearing the Window To clear the color to black (in RGBA mode)

glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); To also clear the depth buffer you might use: glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Drawing Colors The current drawing color is a state. Change the

state with glColor3f commands such as: glColor3f(0.0, glColor3f(1.0, glColor3f(0.0,

glColor3f(1.0, glColor3f(0.0, glColor3f(1.0, glColor3f(0.0, glColor3f(1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0,

1.0, 0.0); 0.0); 0.0); 0.0); 1.0); 1.0); 1.0); 1.0); // black //red

//green //yellow //blue //magenta //cyan //white Flushing the Buffers void glFlush(void); Sends a command to flush out the pipeline and finish the drawing void glFinish(void);

Waits until drawing is completed, then returns Setting up a Coordinate Frame void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h); }

Recently Viewed Presentations

  • Office of the Deputy Assistant Secretary of Defense

    Office of the Deputy Assistant Secretary of Defense

    Pre-signature Edit. WHS Editor approved Manual. WHS Editor completes review by 1 Oct. Outcome: Create a DoDM 4500.36 that is aligned with and further defines the policy, responsibilities, and processes associated with the acquisition, management, and use of government owned...
  • Class 26: Executory Contracts - Union K, Limbo, Assumption

    Class 26: Executory Contracts - Union K, Limbo, Assumption

    In essence, can't "have your cake and eat it too" - if make non-dr perform, that = assumption Non-dr loses 7th circuit ruled that the DIP's need to take time to make a considered decision whether to assume or reject...
  • Technology Systems: Core Technologies

    Technology Systems: Core Technologies

    Examples. Structural Technology ... (pneumatics) or liquid (hydraulic) to apply force or to transport. Examples. Optical Technology. ... For the Sea Perch Project we will be focusing on three of the nine core technologies and how they integrate to create...
  • Combinatorial Optimization Problems in Computational Biology

    Combinatorial Optimization Problems in Computational Biology

    Algorithms for Biochip Design and Optimization Ion Mandoiu Computer Science & Engineering Department University of Connecticut Overview Driver Biochip Applications Driver applications Gene expression (transcription analysis) SNP genotyping CNP analysis Genomic-based microorganism identification Point-of-care diagnosis healthcare, forensics, environmental monitoring,…
  • Let's Review!! - Oklahoma

    Let's Review!! - Oklahoma

    Let's Review!! Question. You are assisting a new Infection preventionist with setting up her Infection prevention program. She is new to the role and just moved to the area and accepted the position of ICP at a local medical surgical...
  • Barriers to Communication - Technoblogger.net

    Barriers to Communication - Technoblogger.net

    Interpersonal barriers These barriers occur due to inappropriate transaction of words between two or more people. Two broad categories. Inefficiency in communication skills. Negative aspect nurturing in the climate
  • Type Title Here

    Type Title Here

    Amendment to the U.S. Lacey Act: Implications for Forest Products Manufacturers, Exporters and Importers Beijing, June 18-19, 2008 R. Juge Gregg
  • Inequalities, inequalities….. - World Bank

    Inequalities, inequalities….. - World Bank

    Main points. Global inequality (between world citizens) is some 70 Gini point today. This is the result obtained using new (2005) PPPs . About 9 percent of world population receives one-half of global income (or consumes ½ of goods and...