Advanced Graphics Application Development with OpenGL - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Advanced Graphics Application Development with OpenGL

Description:

www.corbis.com. 2/26/05. Dan Cliburn. 16. Fog ... To specify how close Fog should appear from the eye (and how far the effects ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 31
Provided by: dancl2
Category:

less

Transcript and Presenter's Notes

Title: Advanced Graphics Application Development with OpenGL


1
Advanced Graphics Application Development with
OpenGL
  • Dan Cliburn
  • Hanover College
  • Hanover, IN

2
Objectives for this Workshop
  • To learn the basics of creating a first person
    perspective video game.
  • Specifically, we will cover
  • Lighting
  • Joystick Input
  • Textures
  • Fog
  • Simple Collision Detection
  • Billboards
  • Picking
  • Sound (with DirectX)
  • Particle Systems
  • Any CS major can learn these topics!

3
Format for this Workshop
  • For each new topic, we will
  • Discuss the topic
  • Look at code to illustrate the concept
  • Work individually on the program
  • At the conclusion, everyone should have a fully
    functioning video game.
  • NOTE Every line of the code in the program will
    not be discussed!

4
OpenGL, GLUT, and DirectX
  • OpenGL is a software interface to graphics
    hardware 1
  • GLUT (Graphics Library Utility Toolkit) is a
    platform independent window manager and event
    handler that can be used in conjunction with
    OpenGL applications 2
  • DirectX is an advanced suite of multimedia
    application programming interfaces (APIs) built
    into Microsoft Windows 3

5
A Very Quick Review
  • OpenGL has three primitive geometric entities
    (points, lines, and polygons) from which we can
    design a model of our scene.
  • The vertices of these objects are defined with
    calls to
  • void glVertex3f( float x, float y, float z)
  • and bracketed by a begin/end pair
  • glBegin( Glenum mode )
  • //glVertex3f calls go here
  • glEnd()

6
A Very Quick Review
7
A Very Quick Review
  • OpenGL uses a camera analogy for describing view
    orientation.
  • gluLookAt(eyeX, eyeY, eyeZ,
  • aimX, aimY, aimZ,
  • upX, upY, upZ)

8
A Very Quick Review
Perspective Projection - view volume is a
truncated pyramid.
9
Designing a Maze
  • Mazes are defined with a simple text file
  • 10 10
  • wall.bmp
  • floor.bmp
  • monster.bmp
  • w w w w w w w w w w
  • w f R m f f R f R w
  • w R w f w f w w f w
  • w f w f w f w f f w
  • w f L f f f w f w w
  • w w f w w f w L f w
  • w f f f f f f f f w
  • w f w f w f w w m w
  • w s L f w f f L f w
  • w w w w w w w w w w

Convention is row column w wall quad f floor
panel R, L, B lights (up to 8) m monster s
start position of player
10
Lighting
  • OpenGL approximates real world lighting.
  • Surface types
  • Diffuse- Scatters light evenly in all directions.
  • Specular-Light is reflected in the direction
    opposite the angle of incidence.
  • Types of Light
  • Direct-Light source can be determined.
  • Ambient-Light source can not be determined.
  • Emissive Object acts as a light.

11
Four Steps to Lighting in OpenGL
  • 1) Define normal vectors for every vertex.
  • glNormal3f(float x, float y, float z)
  • 2) Define material properties for each surface.
  • glMaterialfv(FACE, PROPERTY, VALUE) (p.202)
  • 3) Create and position each light.
  • glLightfv(LIGHT, PROPERTY, VALUE) (p.185)
  • glEnable(LIGHT)
  • 4) Set global parameters and turn lighting on.
  • glEnable(GL_LIGHTING)

12
Joystick Input
  • GLUT has two callbacks for joystick input
  • glutJoystickFunc( functionName, pollInterval )
  • Registers a function with GLUT to call at the
    pollInterval if the joystick has changed state.
  • glutForceJoystickFunc()
  • Forces glut to call the function registered with
    glutJoystickFunc immediately. This method should
    be placed in a timer to call the joystickFunc at
    regular intervals. If the joystick is held in a
    constant state, the joystickFunc is not invoked.

13
Texture Mapping
  • Application of a texture (digital image or
    pattern) to a polygon for enhanced realism.
  • Textures are simply rectangular arrays of data
    whose dimensions must be a power of 2 by a power
    of 2.
  • EXAMPLE 256x128
  • DRAWBACK OpenGL has no support for reading
    various image files.

14
Texture Mapping
  • Texturing is turned on and off with
  • glEnable(GL_TEXTURE_2D)
  • glDisable(GL_TEXTURE_2D)
  • To map 2D texture coordinates to vertices
  • glTexCoord2f( float s, float t )
  • To specify how textures should be applied
  • glTexEnvf( GL_TEXTURE_ENV,
  • GL_TEXTURE_ENV_MODE, mode )
  • where mode can be GL_DECAL, GL_BLEND, or
    GL_MODULATE

15
Texture Mapping
  • Some good websites for textures
  • www.google.com (select images)
  • www.altavista.com (select images, then check
    graphics)
  • www.corbis.com

16
Fog
  • Gives the illusion that objects fade into the
    distance.
  • Can actually improve performance!
  • To turn Fog on glEnable(GL_FOG)
  • To specify the disappearance rate for objects
    glFogi(GL_FOG_MODE, mode )
  • where mode can be GL_LINEAR, GL_EXP, or
    GL_EXP2

17
Fog
  • To specify Fog density
  • glFogf(GL_FOG_DENSITY, density)
  • where density is between 0 and 1
  • To specify how close Fog should appear from the
    eye (and how far the effects should be carried
    out)
  • glFogf( GL_FOG_START, distance ) and
  • glFogf( GL_FOG_END, distance ) ,
  • where distance is a positive float.

18
Simple Collision Detection
  • We want to keep the user of our game from running
    through the walls!
  • We can reference the maze array with the eye
    position to determine if we have come into
    contact with a wall.
  • Collision Detection should be done in the
    joystick callback function, to determine if user
    movements are legal.

19
Billboards
  • Essentially a textured polygon that always faces
    the user.
  • Early 3D games used billboards instead of fully
    3D enemies 4.
  • The surface normal must be aligned so that it is
    parallel (but opposite) to the users view
    direction.
  • Square billboards can be made to look non-square
    through transparency.

20
Billboards
  • We can determine the users direction of view
    with
  • float matrix16
  • glGetFloatv(GL_MODELVIEW_MATRIX, matrix)
  • The returned matrix is a 4x4 matrix where the
    upper left 3x3 defines the users direction of
    view.

21
Billboards
  • The top row of the upper 3x3 defines a vector to
    the right of the viewer. The second row defines
    a vector pointing straight up.
  • Thus, we can create vectors that define the
    orientation of our billboard with
  • Vector right(matrix0, matrix4, matrix8)
  • Vector up(matrix1, matrix5, matrix9)

22
Billboards
  • We can use an alpha test to make parts of our
    textured billboard transparent.
  • glEnable(GL_ALPHA_TEST)
  • glAlphaFunc(GL_GREATER, 0)
  • //draw the object
  • glDisable(GL_ALPHA)

23
Enemies
  • Drawn using billboards with transparency.
  • Animated with a timer callbacks.
  • When enemies catch the player, the game is
    over.
  • New enemies can be easily created by coloring the
    image black in the parts you want invisible.

24
Picking
  • Allows us to determine if a subset of the scene
    geometry is within a particular portion of the
    display screen.
  • First, we assign pick IDs to the selectable
    geometry with
  • glPushName(int num)
  • //define selectable geometry
  • glPopName()

25
Picking
  • Next, we render the scene after defining a
    special pick matrix (see example 13-3 in 1).
  • Last, we process the returned array of hits.
  • We will use picking in our game to help us
    determine if the player captures a monster.
  • A cross hairs can be drawn at the pick center
    to help aim.

26
Sound
  • OpenGL has no facilities for handling sound,
    thats why we need DirectX (or more specifically,
    DirectMusic).
  • Essentially, we need to create 3 objects
  • A Performance Object (IDirectMusicPerformance8)
  • A Loader Object (IDirectMusicLoader8)
  • A Music Segment (IDirectMusicSegment8)

27
Sound
  • We also need to tell our OpenGL program to link
    with DirectX. In Visual C Project-gtSettings-gt
    Link tab-gtadd dxguid.lib in the Object/library
    modules text box.
  • A good website for sound files
  • http//www.partnersinrhyme.com/

28
Particle Systems
  • A collection of entities that behave according to
    a set of rules. Can be used to model fire,
    explosions, rain,
  • We will build a simple particle system to model a
    projectile thrown/fired at the monster in our
    maze.
  • We will use a timer to animate the particles.

29
Thats It!
  • Thanks for coming.
  • Contact info
  • Dan Cliburn
  • Box 890, Hanover College
  • Hanover, IN 47243
  • (812) 866-7286
  • cliburn_at_hanover.edu
  • http//www2.hanover.edu/cliburn

30
References
  • 1 OpenGL Architectural Review Board, OpenGL
    Programming Guide. Reading, Massachusetts
    Addison Wesley, 1993.
  • 2 GLUT, http//www.opengl.org/developers/
  • documentation/glut/
  • 3 Microsoft DirectX Home Page,
  • http//www.microsoft.com/windows/
  • directx/default.aspx
  • 4 Hawkins, K., Astle, D., OpenGL Game
    Programming. Roseville, California Prima Tech,
    2001.
Write a Comment
User Comments (0)
About PowerShow.com