Выбрать главу

    if (!keys['F']) // Has F Key Been Released?

    {

     fp=FALSE; // If So, fp Becomes FALSE

    }

The next four lines check to see if we are pressing the 'Page Up' key. If we are it decreases the variable z. If this variable decreases, the cube will move into the distance because of the glTranslatef(0.0f, 0.0f, z) command used in the DrawGLScene procedure.

    if (keys[VK_PRIOR]) // Is Page Up Being Pressed?

    {

     z-=0.02f; // If So, Move Into The Screen

    }

These four lines check to see if we are pressing the 'Page Down' key. If we are it increases the variable z and moves the cube towards the viewer because of the glTranslatef(0.0f, 0.0f, z) command used in the DrawGLScene procedure.

    if (keys[VK_NEXT]) // Is Page Down Being Pressed?

    {

     z+=0.02f; // If So, Move Towards The Viewer

    }

Now all we have to check for is the arrow keys. By pressing left or right, xspeed is increased or decreased. By pressing up or down, yspeed is increased or decreased. Remember further up in the tutorial I said that if the value in xspeed or yspeed was high, the cube would spin faster. The longer you hold down an arrow key, the faster the cube will spin in that direction.

    if (keys[VK_UP]) // Is Up Arrow Being Pressed?

    {

     xspeed-=0.01f; // If So, Decrease xspeed

    }

    if (keys[VK_DOWN]) // Is Down Arrow Being Pressed?

    {

     xspeed+=0.01f; // If So, Increase xspeed

    }

    if (keys[VK_RIGHT]) // Is Right Arrow Being Pressed?

    {

     yspeed+=0.01f; // If So, Increase yspeed

    }

    if (keys[VK_LEFT]) // Is Left Arrow Being Pressed?

    {

     yspeed-=0.01f; // If So, Decrease yspeed

    }

Like all the previous tutorials, make sure the title at the top of the window is correct.

    if (keys[VK_F1]) // Is F1 Being Pressed?

    {

     keys[VK_F1]=FALSE; // If So Make Key FALSE

     KillGLWindow(); // Kill Our Current Window

     fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode

     // Recreate Our OpenGL Window

     if (!CreateGLWindow("NeHe's Textures, Lighting & Keyboard Tutorial", 640, 480, 16, fullscreen)) {

      return 0; // Quit If Window Was Not Created

     }

    }

   }

  }

 }

 // Shutdown

 KillGLWindow(); // Kill The Window

 return (msg.wParam); // Exit The Program

}

By the end of this tutorial you should be able to create and interact with high quality, realistic looking, textured mapped objects made up of quads. You should understand the benefits of each of the three filters used in this tutorial. By pressing specific keys on the keyboard you should be able to interact with the object(s) on the screen, and finally, you should know how to apply simple lighting to a scene making the scene appear more realistic.

Jeff Molofee (NeHe)

* DOWNLOAD Visual C++ Code For This Lesson.

* DOWNLOAD Borland C++ Builder 5.0 Code For This Lesson. (Conversion by Neil Flynn)

* DOWNLOAD Cygwin Code For This Lesson. (Conversion by Stephan Ferraro)

* DOWNLOAD Delphi Code For This Lesson. (Conversion by Brad Choate)

* DOWNLOAD Game GLUT Code For This Lesson. (Conversion by Milikas Anastasios)

* DOWNLOAD GLUT Code For This Lesson. (Conversion by Andy Restad)

* DOWNLOAD Irix Code For This Lesson. (Conversion by Lakmal Gunasekara)

* DOWNLOAD Java Code For This Lesson. (Conversion by Jeff Kirby)

* DOWNLOAD Jedi-SDL Code For This Lesson. (Conversion by Dominique Louis)

* DOWNLOAD Linux Code For This Lesson. (Conversion by Richard Campbell)

* DOWNLOAD Linux/GLX Code For This Lesson. (Conversion by Mihael Vrbanec)

* DOWNLOAD Linux/SDL Code For This Lesson. (Conversion by Ti Leggett)

* DOWNLOAD Mac OS Code For This Lesson. (Conversion by Anthony Parker)

* DOWNLOAD Mac OS X/Cocoa Code For This Lesson. (Conversion by Bryan Blackburn)

* DOWNLOAD MASM Code For This Lesson. (Conversion by Nico (Scalp))

* DOWNLOAD Visual C++ / OpenIL Code For This Lesson. (Conversion by Denton Woods)

* DOWNLOAD Power Basic Code For This Lesson. (Conversion by Angus Law)

* DOWNLOAD Solaris Code For This Lesson. (Conversion by Lakmal Gunasekara)

* DOWNLOAD Visual Basic Code For This Lesson. (Conversion by Peter De Tagyos)

* DOWNLOAD Visual Fortran Code For This Lesson. (Conversion by Jean-Philippe Perois

Lesson 08

Simple Transparency

Most special effects in OpenGL rely on some type of blending. Blending is used to combine the color of a given pixel that is about to be drawn with the pixel that is already on the screen. How the colors are combined is based on the alpha value of the colors, and/or the blending function that is being used. Alpha is a 4th color component usually specified at the end. In the past you have used GL_RGB to specify color with 3 components. GL_RGBA can be used to specify alpha as well. In addition, we can use glColor4f() instead of glColor3f().