1 / 11

Preview of 3-D Graphics

This preview provides an overview of 3-D graphics concepts, including changing the display based on keyboard input, automatically changing the display, and quick solutions for viewing, hidden-surface removal, lighting, and smooth animation.

damianj
Download Presentation

Preview of 3-D Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Preview of 3-D Graphics Glenn G. ChappellCHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 17, 2003

  2. Review:intro2d.cpp • GLUT calls the keyboard function whenever an ASCII keypress happens. • Use the GLUT “special” function for non-ASCII (like arrow keys). • The ASCII value of the keypress is in key. Mouse position is in x, y. • Your keyboard (or special) function will usually be one big switch. • GLUT calls the idle function whenever nothing else needs doing. • It is useful for making time-dependent changes to the scene. • Think “animation”. CS 381

  3. Review:Making a Changing Display [1/3] • We looked at how to make the display change: • Based on keyboard input. • Using the keyboard (or special) function. • Automatically. • Using the idle function. • These ideas will be covered in greater detail in chapter 3. • Coming up on Friday. CS 381

  4. Review:Making a Changing Display [2/3] • To add keypress-based display changes to a GLUT program: • A global variable is needed to hold the current state of whatever part of the display is to change. • Declare the variable. • Initialize this variable to an appropriate value somewhere. • In its declaration? • In the init function? • In the display function: • Use the value of this variable. • Draw whatever should be drawn, according to the current value of the variable. • Do not change the variable in the display function. • In the keyboard function, when the appropriate key is pressed: • Change the value of the variable. • Call “glutPostRedisplay();”. • Do not call the display function. CS 381

  5. Review:Making a Changing Display [3/3] • To add automatic display changes to a GLUT program: • So it just like keyboard input, except: • Modify the idle function instead of the keyboard function. • Do not worry about the ASCII value of a key. • Doing this kind of programming may require a new mindset: • Remember to handle events in the proper callbacks. • Display does display, keyboard handles ASCII keypresses, etc. • Remember that your functions can be called in just about any order! • Again, we’ll look at this in more detail in chapter 3. CS 381

  6. 3-D Preview:Introduction • From a certain point of view, 3-D graphics is easy. • Just use 3 coordinates instead of 2 in your glVertex* commands. • In practice, it is much trickier. • We will be studying 3-D CG in detail starting with chapter 4. For now, a preview. CS 381

  7. 3-D Preview:Three Issues in 3-D CG • Viewing and Transformations • How do we look at a scene from any point of view within the scene, looking in any direction? • How do we do perspective projection? • How do we rotate things about arbitrary axes in 3-D? • Hidden-Surface Removal • When one object is behind another, we don’t want to see the hidden one. • Then there is transparency … • Lighting • 3-D CG is lousy without lighting. How do we do it? • In addition, we want to do smooth animation. CS 381

  8. 3-D Preview:Quick & Dirty Solutions [1/4] • Viewing & Transformations • By default, you are looking in the –z direction. • So the +z axis points toward you. • More negative values are farther away. • The rest will have to wait a little. • See sample3d.cpp for a few hints. CS 381

  9. 3-D Preview:Quick & Dirty Solutions [2/4] • Hidden-Surface Removal • Add GLUT_DEPTH to your glutInitDisplayMode call. • This allocates a depth buffer. • Remember, the various constants are bitwise-or’ed together. • Add GL_DEPTH_BUFFER_BIT to your glClear call. • This clears the depth buffer. • Again, bitwise-or. • Put glEnable(GL_DEPTH_TEST) somewhere in your initialization. • This enables hidden-surface removal. CS 381

  10. 3-D Preview:Quick & Dirty Solutions [3/4] • Lighting • This is tough to explain quickly. • For now, either • Ignore lighting, and make polygons lots of different colors, so you can tell them apart. • Or, base your programs on sample3d.cpp (or something similar), and use the GLUT built-in shape functions. • Like glutSolidTorus. CS 381

  11. 3-D Preview:Quick & Dirty Solutions [4/4] • Smooth Animation • Use double buffering. • Change GLUT_SINGLE to GLUT_DOUBLE in your glutInitDisplayMode call. • Change glFlush to glutSwapBuffers in your display callback. • Now the user only sees completed frames. • No flicker in animation. • Faster sometimes, slower others. • User cannot see the frame being built. • Sometimes this is bad, as with some complex fractals. CS 381

More Related