NeHe OpenGL PDF NEW, Programowanie

[ Pobierz całość w formacie PDF ]
OpenGL
Tutorial
ii
Contents
Contents
.............................................................................................................................. ii
Preface
............................................................................................................................... iv
Lesson 01: Setting Up An OpenGL Window
..................................................................... 1
Lesson 02:
Your First Polygon
........................................................................................ 12
Lesson 03:
Adding Color
................................................................................................. 14
Lesson 04:
Rotation
......................................................................................................... 16
Lesson 05:
3D Shapes
...................................................................................................... 19
Lesson 06:
Texture Mapping
........................................................................................... 22
Lesson 07:
Texture Filters, Lightning &
Keyboard Control
.......................................... 26
Lesson 08:
Blending
......................................................................................................... 33
Lesson 09:
Moving Bitmaps In 3D Space
....................................................................... 36
Lesson 10:
Loading And Moving Through A 3D World
................................................ 41
Lesson 11:
Flag Effect (Waving Texture)
....................................................................... 45
Lesson 12: Display Lists
.................................................................................................. 48
Lesson 13: Bitmap Fonts
................................................................................................. 53
Lesson 14: Outline Fonts
................................................................................................. 58
Lesson 15:
Texture Mapped Outline Fonts
.................................................................... 63
Lesson 16: Cool Looking Fog
......................................................................................... 67
Lesson 17: 2D Texture Font
............................................................................................ 69
Lesson 18: Quadrics
......................................................................................................... 76
Lesson 19: Particle Engine Using Triangle Strips
......................................................... 80
Lesson 20: Masking
......................................................................................................... 90
Lesson 21: Lines, Antialiasing, Timing, Ortho View And Simple Sounds
.................... 97
Lesson 22: Bump-Mapping, Multi-Texturing & Extensions
....................................... 116
Lesson 23: Sphere Mapping Quadrics In OpenGL
...................................................... 136
Lesson 24: Tokens, Extensions, Scissor Testing And TGA Loading
........................... 140
Lesson 25: Morphing & Loading Objects From A File
............................................... 150
Lesson 26: Clipping & Reflections Using The Stencil Buffer
..................................... 159
Lesson 27: Shadows
....................................................................................................... 169
Lesson 28: Bezier Patches / Fullscreen Fix
.................................................................. 177
Lesson 29: Blitter Function, RAW Texture Loading
................................................... 185
Lesson 30: Collision Detection
...................................................................................... 194
Lesson 31: Model Loading
............................................................................................ 205
Lesson 32: Picking, Alpha Blending, Alpha Testing, Sorting
..................................... 211
Lesson 33: Loading Compressed And Uncompressed TGA’s
...................................... 226
Lesson 34: Beautiful Landscapes By Means Of Height Mapping
............................... 232
Lesson 35: Playing AVI Files In OpenGL
.................................................................... 239
Lesson 36: Radial Blur & Rendering To A Texture
..................................................... 248
Lesson 37: Cel-Shading
................................................................................................. 255
Lesson 38: Loading Textures From A Resource File & Texturing Triangles
............ 261
Neon Helium Productions

Jeff Molofee NeHe
iii
Lesson 39: Introduction To Physical Simulations
......................................................... 271
Lesson 40:
Rope Physics
................................................................................................. 278
Lesson 41: Volumetric Fog and IPicture Image
Loading
............................................. 285
Lesson 42: Multiple Viewports
.......................................................................................
294
Lesson 43: FreeType Fonts in OpenGL
......................................................................... 305
Lesson 44: 3D Lens Flare With Occlusion Testing
....................................................... 314
Lesson 45: Vertex Buffer Objects
................................................................................... 326
Lesson 46: Fullscreen AntiAliasing
............................................................................... 332
Lesson 47: CG Vertex Shader
........................................................................................
337
Lesson 48: ArcBall Rotation
..........................................................................................
343
Appendix 1: Setting Up OpenGL In MacOS
.................................................................. I
Appendix 2: Setting Up OpenGL In Solaris
.................................................................. III
Appendix 3: Setting Up OpenGL In MacOS X Using GLUT
....................................... V
References
......................................................................................................................
VII
Neon Helium Productions © Jeff Molofee NeHe
iv
Preface
The tutorials on this page may contain mistakes, poor commenting, and should
not be considered the best resource to learn OpenGL from. What you do with the
code is up to you. I am merely trying to make the learning process a little easier
for those people new to OpenGL. If you are serious about learning OpenGL, you
should spend the money and invest in the OpenGL Red Book (ISBN 0-201-
46138-2) and OpenGL Blue Book (ISBN 0-201-46140-4). I have the second
edition of each book, and although they can be difficult for the new OpenGL
programmer to understand, they are by far the best books written on the subject
of OpenGL. Another book I would recommend is the OpenGL Superbible,
although opinions vary. It is also important that you have a solid understanding of
the language you plan to use. Although I do comment the non-GL lines, I am self-
taught, and may not always write proper or even good code. It's up to you to take
what you have learned from this site and apply it to projects of your own. Play
around with the code, read books, ask me questions if need be. Once you have
surpassed the code on this site or even before, check out some of the more
professional sites such as
OpenGL.org
. Also be sure to visit the many OpenGL
links on my page. Each site I link to is an incredible asset the OpenGL
community. Most of these sites are run by talented individuals that not only know
their GL, they also program alot better than I do. Please keep all of this in mind
while browsing my site. I hope you enjoy what I have to offer, and hope to see
projects created by yourself in the near future!
One final note, if you see code that you feel is to similar to someone else's code,
please contact me. I assure you, any code I borrow from or learn from either
comes from the MSDN or from sites created to help teach people in a similar way
that my site teaches GL. I never intentionally take code, and never would without
giving the proper person credit. There may be instances where I get code from a
free site not knowing that site took it from someone else, so if that happens,
please contact me. I will either rewrite the code, or remove it from my program.
Most the code should be original however, I only borrow when I absolutely have
no idea how to accomplish something, and even then I make sure I understand
the code before I decide to include it in my program. If you spot mistakes in any
of the tutorials, no matter how tiny the mistake may be, please let me know.
One important thing to note about my base code is that it was written in 1997. It
has undergone many changes, and it is definitely not borrowed from any other
sites. It will more than likely be altered in the future. If I am not the one that
modifies it, the person responsible for the changes will be credited.
Neon Helium Productions

Jeff Molofee NeHe
Lesson 01 - Setting Up An OpenGL Window
1
Lesson 01
Setting Up An OpenGL Window
Welcome to my OpenGL tutorials. I am an average guy with a passion for OpenGL! The first time I heard about OpenGL was back
when 3Dfx released their Hardware accelerated OpenGL driver for the Voodoo 1 card. Immediately I knew OpenGL was
something I had to learn. Unfortunately, it was very hard to find any information about OpenGL in books or on the net. I spent
hours trying to make code work and even more time begging people for help in email and on IRC. I found that those people that
understood OpenGL considered themselves elite, and had no interest in sharing their knowledge. VERY frustrating!
I created this web site so that people interested in learning OpenGL would have a place to come if they needed help. In each of
my tutorials I try to explain, in as much detail as humanly possible, what each line of code is doing. I try to keep my code simple
(no MFC code to learn)! An absolute newbie to both Visual C++ and OpenGL should be able to go through the code, and have a
pretty good idea of what's going on. My site is just one of many sites offering OpenGL tutorials. If you're a hardcore OpenGL
programmer, my site may be too simplistic, but if you're just starting out, I feel my site has a lot to offer!
This tutorial was completely rewritten January 2000. This tutorial will teach you how to set up an OpenGL window. The window
can be windowed or fullscreen, any size you want, any resolution you want, and any color depth you want. The code is very
flexible and can be used for all your OpenGL projects. All my tutorials will be based on this code! I wrote the code to be flexible,
and powerful at the same time. All errors are reported. There should be no memory leaks, and the code is easy to read and easy
to modify. Thanks to Fredric Echols for his modifications to the code!
I'll start this tutorial by jumping right into the code. The first thing you will have to do is build a project in Visual C++. If you don't
know how to do that, you should not be learning OpenGL, you should be learning Visual C++. The downloadable code is Visual
C++ 6.0 code. Some versions of VC++ require that bool is changed to BOOL, true is changed to TRUE, and false is changed to
FALSE. By making the changes mentioned, I have been able to compile the code on Visual C++ 4.0 and 5.0 with no other
problems.
After you have created a new Win32 Application (NOT a console application) in Visual C++, you will need to link the OpenGL
libraries. In Visual C++ go to Project, Settings, and then click on the LINK tab. Under "Object/Library Modules" at the beginning of
the line (before kernel32.lib) add OpenGL32.lib GLu32.lib and GLaux.lib. Once you've done this click on OK. You're now ready to
write an OpenGL Windows program.
The first 4 lines include the header files for each library we are using. The lines look like this:
#include <windows.h>
// Header File For Windows
#include <gl\gl.h>
// Header File For The OpenGL32 Library
#include <gl\glu.h>
// Header File For The GLu32 Library
#include <gl\glaux.h>
// Header File For The GLaux Library
Next you need to set up all the variables you plan to use in your program. This program will create a blank OpenGL window, so
we won't need to set up a lot of variables just yet. The few variables that we do set up are very important, and will be used in just
about every OpenGL program you write using this code.
The first line sets up a Rendering Context. Every OpenGL program is linked to a Rendering Context. A Rendering Context is what
links OpenGL calls to the Device Context. The OpenGL Rendering Context is defined as hRC. In order for your program to draw
Neon Helium Productions

Jeff Molofee NeHe
[ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • aureola.keep.pl
  •