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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

glTranslated(mouse_x,window.bottom-mouse_y,0.0f); // Move To The Current Mouse Position

Object(16,16,8); // Draw The Crosshair

This section of code put the title at the top of the screen, and displays the level and score in the bottom left and right corners of the screen. The reason I put this code here is because it's easier to position the text accurately in ortho mode.

// Game Stats / Title

glPrint(240,450,"NeHe Productions"); // Print Title

glPrint(10,10,"Level: %i",level); // Print Level

glPrint(250,10,"Score: %i",score); // Print Score

This section checks to see if the player has missed more than 10 objects. If so, we set the number of misses (miss) to 9 and we set game to TRUE. Setting the game to TRUE means the game is over!

if (miss>9) // Have We Missed 10 Objects?

{

miss=9; // Limit Misses To 10

game=TRUE; // Game Over TRUE

}

In the code below, we check to see if game is TRUE. If game is TRUE, we print the GAME OVER messages. If game is false, we print the players morale (out of 10). The morale is calculated by subtracting the players misses (miss) from 10. The more the player misses, the lower his morale.

if (game) // Is Game Over?

glPrint(490,10,"GAME OVER"); // Game Over Message

else glPrint(490,10,"Morale: %i/10",10-miss); // Print Morale #/10

The last thing we do is select the projection matrix, restore (pop) our matrix back to it's previous state, set the matrix mode to modelview and flush the buffer to make sure all objects have been rendered.

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix

glPopMatrix(); // Restore The Old Projection Matrix

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

glFlush(); // Flush The GL Rendering Pipeline

}

This tutorial is the result of many late nights, and many many hours of coding & writing HTML. By the end of this tutorial you should have a good understanding of how picking, sorting, alpha blending and alpha testing works. Picking allows you to create interactive point and click software. Everything from games, to fancy GUI's. The best feature of picking is that you don't have to keep track of where your objects are. You assign a name and check for hits. It's that easy! With alpha blending and alpha testing you can make your objects completely solid, or full of holes. The results are great, and you don't have to worry about objects showing through your textures, unless you want them to! As always, I hope you have enjoyed this tutorial, and hope to see some cool games, or projects based on code from this tutorial. If you have any questions or you find mistakes in the tutorial please let me know… I'm only human :)

I could have spent alot more time adding things like physics, more graphics, more sound, etc. This is just a tutorial though! I didn't write it to impress you with bells and whistles. I wrote it to teach you OpenGL with as little confusion as possible. I hope to see some cool modifications to the code. If you add something cool the the tutorial send me the demo. If it's a cool modification I'll post it to the downloads page. If I get enough modifications I may set up a page dedicated to modified versions of this tutorial! I am here to give you a starting point. The rest is up to you :)

Jeff Molofee (NeHe)

* DOWNLOAD Visual C++Code For This Lesson.

* DOWNLOAD DelphiCode For This Lesson. (Conversion by Hugh Waite)

Lesson 33

Loading Uncompressed and RunLength Encoded TGA images By Evan "terminate" Pipho.

I've seen lots of people ask around in #gamdev, the gamedev forums, and other places about TGA loading. The following code and explanation will show you how to load both uncompressed TGA files and RLE compressed files. This particular tutorial is geared toward OpenGL, but I plan to make it more universal in the future.

We will begin with the two header files. The first file will hold our texture structure, the second, structures and variables used by the loading code.

Like every header file we need some inclusion guards to prevent the file from being included multiple times.

At the top of the file add these lines:

#ifndef __TEXTURE_H__ // See If The Header Has Been Defined Yet

#define __TEXTURE_H__ // If Not, Define It.

Then scroll all the way down to the bottom and add:

#endif // __TEXTURE_H__ End Inclusion Guard

These three lines prevent the file from being included more than once into a file. The rest of the code in the file will be between the first two, and the last line.

Into this header file we we will insert the standard headers we will need for everything we do. Add the following lines after the #define __TGA_H__ command.

#pragma comment(lib, "OpenGL32.lib") // Link To Opengl32.lib

#include // Standard Windows header

#include // Standard Header For File I/O

#include // Standard Header For OpenGL

The first header is the standard windows header, the second is for the file I/O functions we will be using later, and the 3rd is the standard OpenGL header file for OpenGL32.lib.

We will need a place to store image data and specifications for generating a texture usable by OpenGL. We will use the following structure.

typedef struct {

GLubyte* imageData; // Hold All The Color Values For The Image.

GLuint bpp; // Hold The Number Of Bits Per Pixel.

GLuint width; // The Width Of The Entire Image.

GLuint height; // The Height Of The Entire Image.

GLuint texID; // Texture ID For Use With glBindTexture.

GLuint type; // Data Stored In * ImageData (GL_RGB Or GL_RGBA)

} Texture;

Now for the other, longer head file. Again we will need some includsion guards, same as the last one.

Next come two more structures used during processing of the TGA file.

typedef struct {

GLubyte Header[12]; // File Header To Determine File Type

} TGAHeader;

typedef struct {

GLubyte header[6]; // Holds The First 6 Useful Bytes Of The File

GLuint bytesPerPixel; // Number Of BYTES Per Pixel (3 Or 4)

GLuint imageSize; // Amount Of Memory Needed To Hold The Image

GLuint type; // The Type Of Image, GL_RGB Or GL_RGBA

GLuint Height; // Height Of Image

GLuint Width; // Width Of Image

GLuint Bpp; // Number Of BITS Per Pixel (24 Or 32)

} TGA;

Now we declare some instances of our two structures so we can use them within our code.

TGAHeader tgaheader; // Used To Store Our File Header

TGA tga; // Used To Store File Information

We need to define a couple file headers so we can tell the program what kinds of file headers are on valid images. The first 12 bytes will be 0 0 2 0 0 0 0 0 0 0 0 0 if it is uncompressed TGA image and 0 0 10 0 0 0 0 0 0 0 0 0 if it an RLE compressed one. These two values allow us to check to see if the file we are reading is valid.

// Uncompressed TGA Header

GLubyte uTGAcompare[12] = {0,0, 2,0,0,0,0,0,0,0,0,0};

// Compressed TGA Header

GLubyte cTGAcompare[12] = {0,0,10,0,0,0,0,0,0,0,0,0};

Finally we declare a pair of functions to use in the loading process.

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

Интервал:

Закладка:

Сделать

Похожие книги на «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