Jeff Molofee - NeHe's OpenGL Tutorials

Здесь есть возможность читать онлайн «Jeff Molofee - NeHe's OpenGL Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

NeHe's OpenGL Tutorials: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «NeHe's OpenGL Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

NeHe's OpenGL Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «NeHe's OpenGL Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Move down to LoadGLTextures(). Find the line that says: if (TextureImage[0]=LoadBMP("Data/Crate.bmp")). Change it to the line below. We're using a stained glass type texture for this tutorial instead of the crate texture.

if (TextureImage[0]=LoadBMP("Data/glass.bmp")) // Load The Glass Bitmap ( MODIFIED )

Add the following two lines somewhere in the InitGL() section of code. What this line does is sets the drawing brightness of the object to full brightness with 50% alpha (opacity). This means when blending is enabled, the object will be 50% transparent. The second line sets the type of blending we're going to use.

Rui Martins Adds:An alpha value of 0.0 would mean that the material is completely transparent. A value of 1.0 would be totally opaque.

glColor4f(1.0f,1.0f,1.0f,0.5f); // Full Brightness, 50% Alpha ( NEW )

glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW )

Look for the following section of code, it can be found at the very bottom of lesson seven.

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

{

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

}

Right under the above code, we want to add the following lines. The lines below watch to see if the 'B' key has been pressed. If it has been pressed, the computer checks to see if blending is off or on. If blending is on, the computer turns it off. If blending was off, the computer will turn it on.

if (keys['B'] && !bp) // Is B Key Pressed And bp FALSE?

{

bp=TRUE; // If So, bp Becomes TRUE

blend = !blend; // Toggle blend TRUE / FALSE

if(blend) // Is blend TRUE?

{

glEnable(GL_BLEND); // Turn Blending On

glDisable(GL_DEPTH_TEST); // Turn Depth Testing Off

} else // Otherwise

{

glDisable(GL_BLEND); // Turn Blending Off

glEnable(GL_DEPTH_TEST); // Turn Depth Testing On

}

}

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

{

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

}

But how can we specify the color if we are using a texture map? Simple, in modulated texture mode, each pixel that is texture mapped is multiplied by the current color. So, if the color to be drawn is (0.5, 0.6, 0.4), we multiply it times the color and we get (0.5, 0.6, 0.4, 0.2) (alpha is assumed to be 1.0 if not specified).

Thats it! Blending is actually quite simple to do in OpenGL.

Note (11/13/99)

I (NeHe) have modified the blending code so the output of the object looks more like it should. Using Alpha values for the source and destination to do the blending will cause artifacting. Causing back faces to appear darker, along with side faces. Basically the object will look very screwy. The way I do blending may not be the best way, but it works, and the object appears to look like it should when lighting is enabled. Thanks to Tom for the initial code, the way he was blending was the proper way to blend with alpha values, but didn't look as attractive as people expected :)

The code was modified once again to address problems that some video cards had with glDepthMask(). It seems this command would not effectively enable and disable depth buffer testing on some cards, so I've changed back to the old fashioned glEnable and Disable of Depth Testing.

Alpha From Texture Map.

The alpha value that is used for transparency can be read from a texture map just like color, to do this, you will need to get alpha into the image you want to load, and then use GL_RGBA for the color format in calls to glTexImage2D().

Questions?

If you have any questions, feel free to contact me at stanis@cs.wisc.edu.

Tom Stanis Jeff Molofee (NeHe)

* DOWNLOAD Visual C++Code For This Lesson.

* DOWNLOAD Borland C++Code For This Lesson. (Conversion by Patrick Salmons)

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

* DOWNLOAD DelphiCode For This Lesson. (Conversion by Marc Aarts)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

* DOWNLOAD Visual FortranCode For This Lesson. (Conversion by Jean-Philippe Perois)

Lesson 09

Welcome to Tutorial 9. By now you should have a very good understanding of OpenGL. You've learned everything from setting up an OpenGL Window, to texture mapping a spinning object while using lighting and blending. This will be the first semi-advanced tutorial. You'll learn the following: Moving bitmaps around the screen in 3D, removing the black pixels around the bitmap (using blending), adding color to a black & white texture and finally you'll learn how to create fancy colors and simple animation by mixing different colored textures together.

We'll be modifying the code from lesson one for this tutorial. We'll start off by adding a few new variables to the beginning of the program. I'll rewrite the entire section of code so it's easier to see where the changes are being made.

#include // Header File For Windows

#include // Header File For Standard Input/Output

#include // Header File For The OpenGL32 Library

#include // Header File For The GLu32 Library

#include // Header File For The GLaux Library

HDC hDC=NULL; // Private GDI Device Context

HGLRC hRC=NULL; // Permanent Rendering Context

HWND hWnd=NULL; // Holds Our Window Handle

HINSTANCE hInstance; // Holds The Instance Of The Application

bool keys[256]; // Array Used For The Keyboard Routine

bool active=TRUE; // Window Active Flag Set To TRUE By Default

bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

The following lines are new. twinkle and tp are BOOLean variables meaning they can be TRUE or FALSE. twinkle will keep track of whether or not the twinkle effect has been enabled. tp is used to check if the 'T' key has been pressed or released. (pressed tp=TRUE, relased tp=FALSE).

BOOL twinkle; // Twinkling Stars

BOOL tp; // 'T' Key Pressed?

num will keep track of how many stars we draw to the screen. It's defined as a CONSTant. This means it can never change within the code. The reason we define it as a constant is because you can not redefine an array. So if we've set up an array of only 50 stars and we decided to increase num to 51 somewhere in the code, the array can not grow to 51, so an error would occur. You can change this value to whatever you want it to be in this line only. Don't try to change the value of num later on in the code unless you want disaster to occur.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «NeHe's OpenGL Tutorials»

Представляем Вашему вниманию похожие книги на «NeHe's OpenGL Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Jeff Jacobson - Sleep Tight
Jeff Jacobson
Jeff Salyards - Veil of the Deserters
Jeff Salyards
Jeff LaSala - The Darkwood Mask
Jeff LaSala
Jeff Lindsay - Dexter's Final Cut
Jeff Lindsay
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
Отзывы о книге «NeHe's OpenGL Tutorials»

Обсуждение, отзывы о книге «NeHe's OpenGL Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x