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

   glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, –1.0f);

   glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, –1.0f);

   glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, –1.0f, –1.0f);

   // Top Face

   glNormal3f( 0.0f, 0.5f, 0.0f);

   glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, –1.0f);

   glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

   glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);

   glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, –1.0f);

   // Bottom Face

   glNormal3f( 0.0f,-0.5f, 0.0f);

   glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, –1.0f, –1.0f);

   glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, –1.0f, –1.0f);

   glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, –1.0f, 1.0f);

   glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, –1.0f, 1.0f);

   // Right Face

   glNormal3f( 0.5f, 0.0f, 0.0f);

   glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, –1.0f, –1.0f);

   glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, –1.0f);

   glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);

   glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, –1.0f, 1.0f);

   // Left Face

   glNormal3f(-0.5f, 0.0f, 0.0f);

   glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, –1.0f, –1.0f);

   glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, –1.0f, 1.0f);

   glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

   glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, –1.0f);

  glEnd(); // Done Drawing Our Cube

  break; // Done Effect 0

This is where we draw the sphere. We start off with a few quick rotations on the x-axis, y-axis and z-axis. We then draw the sphere. The sphere will have a radius of 1.3f, with 20 slices and 20 stacks. I decided to use 20 because I didn't want the sphere to be perfectly smooth. Using fewer slices and stacks gives the sphere a rougher look (less smooth), making it semi obvious that the sphere is actually rotating when sphere mapping is enabled. Try playing around with the values! It's important to note that more slices or stacks requires more processing power!

 case 1: // Effect 1 – Sphere

  glRotatef (angle*1.3f, 1.0f, 0.0f, 0.0f); // Rotate On The X-Axis By angle

  glRotatef (angle*1.1f, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle

  glRotatef (angle*1.2f, 0.0f, 0.0f, 1.0f); // Rotate On The Z-Axis By angle

  gluSphere(quadratic,1.3f,20,20); // Draw A Sphere

  break; // Done Drawing Sphere

This is where we draw the cylinder. We start off with some simple rotations on the x-axis, y-axis and z-axis. Our cylinder has a base and top radius of 1.0f units. It's 3.0f units high, and is composed of 32 slices and 32 stacks. If you decrease the slices or stacks, the cylinder will be made up of less polygons and will appear less rounded.

Before we draw the cylinder, we translate –1.5f units on the z-axis. By doing this, our cylinder will rotate around it's center point. The general rule to centering a cylinder is to divide it's height by 2 and translate by the result in a negative direction on the z-axis. If you have no idea what I'm talking about, take out the tranlatef(…) line below. The cylinder will rotate around it's base, instead of a center point.

 case 2: // Effect 2 – Cylinder

  glRotatef (angle*1.3f, 1.0f, 0.0f, 0.0f); // Rotate On The X-Axis By angle

  glRotatef (angle*1.1f, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle

  glRotatef (angle*1.2f, 0.0f, 0.0f, 1.0f); // Rotate On The Z-Axis By angle

  glTranslatef(0.0f,0.0f,-1.5f); // Center The Cylinder

  gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32); // Draw A Cylinder

  break; // Done Drawing Cylinder

 }

Next we check to see if env is TRUE. If it is, we disable sphere mapping. We call glFlush() to flush out the rendering pipeline (makes sure everything gets rendered before we draw the next frame).

 if (env) // Environment Mapping Enabled?

 {

  glDisable(GL_TEXTURE_GEN_S); // Disable Texture Coord Generation For S (NEW)

  glDisable(GL_TEXTURE_GEN_T); // Disable Texture Coord Generation For T (NEW)

 }

 glFlush (); // Flush The GL Rendering Pipeline

}

I hope you enjoyed this tutorial. It's 2:00am at the moment… I've been working on this tut for the last 6 hours. Sounds crazy, but writing things so that they actually make sense is not an easy task. I have read the tut 3 times now and I'm still trying to make things easier to understand. Believe it or not, it's important to me that you understand how things work and why they work. That's why I babble endlessly, why I over-comment, etc.

Anyways… I would love to hear some feedback about this tut. If you find mistakes or you would like to help make the tut better, please contact me. As I said, this is my first attempt at AVI. Normally I wouldn't write a tut on a subject I just learned, but my excitement got the best of me, plus the fact that there's very little information on the subject bothered me. What I'm hoping is that I'll open the door to a flood of higher quality AVI demos and example code! Might happen… might not. Either way, the code is here for you to use however you want!

Huge thanks to Fredster for the face AVI file. Face was one of about 6 AVI animations he sent to me for use in my tutorial. No questions asked, no conditions. I emailed him and he went out of his way to help me out… Huge respect!

An even bigger thanks to Jonathan de Blok. If it wasn't for him, this tutorial would not exist. He got me interested in the AVI format by sending me bits of code from his own personal AVI player. He also went out of his way to answer any questions that I had in regards to his code. It's important to note that nothing was borrowed or taken from his code, it was used only to understand how an AVI player works. My player opens, decodes and plays AVI files using very different code!

Thanks to everyone for the great support! This site would be nothing without it's visitors!!!

Jeff Molofee (NeHe)

* DOWNLOAD Visual C++ Code For This Lesson. 

Lesson 36

Hi! I'm Dario Corno, also known as rIo of SpinningKids. First of all, I want to explain why I decided to write this little tutorial. I have been a scener since 1989. I want all of you to download some demos so you understand what a demo is and what demo effects are.

Demos are done to show off hardcore and sometimes brutal coding as well as artistic skill. You can usually find some really killer effects in todays demos! This won't be a killer effect tutorial, but the end result is very cool! You can find a huge collection of demos at http://www.pouet.net and http://ftp.scene.org.

Now that the introduction is out of the way, we can go on with the tutorial…

I will explain how to do an eye candy effect (used in demos) that looks like radial blur. Sometimes it's referred to as volumetric lights, don't believe it, it's just a fake radial blur! ;D

Radial blur was usually done (when there were only software renderers) by blurring every pixel of the original image in a direction opposite the center of the blur.