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

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

Интервал:

Закладка:

Сделать

glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red

glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)

glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)

glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)

glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)

The back face is a quad the same as the front face, but it's set deeper into the screen. Notice the Z axis is now minus one for all of the points.

glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow

glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)

glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)

glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back)

glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back)

Now we only have two more quads to draw and we're done. As usual, you'll notice one axis is always the same for all the points. In this case the X axis is always minus one. That's because we're always drawing to the left of center because this is the left face.

glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue

glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)

glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)

glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)

glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)

This is the last face to complete the cube. The X axis is always one. Drawing is counter clockwise. If you wanted to, you could leave this face out, and make a box :)

Or if you felt like experimenting, you could always try changing the color of each point on the cube to make it blend the same way the pyramid blends. You can see an example of a blended cube by downloading Evil's first GL demo from my web page. Run it and press TAB. You'll see a beautifully colored cube, with colors flowing across all the faces.

glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet

glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)

glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)

glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)

glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)

glEnd(); // Done Drawing The Quad

rtri+=0.2f; // Increase The Rotation Variable For The Triangle

rquad-=0.15f; // Decrease The Rotation Variable For The Quad

return TRUE; // Keep Going

}

By the end of this tutorial, you should have a better understanding of how objects are created in 3D space. You have to think of the OpenGL screen as a giant piece of graph paper, with many transparent layers behind it. Almost like a giant cube made of of points. Some of the points move left to right, some move up and down, and some move further back in the cube. If you can visualize the depth into the screen, you shouldn't have any problems designing new 3D objects.

If you're having a hard time understanding 3D space, don't get frustrated. It can be difficult to grasp right off the start. An object like the cube is a good example to learn from. If you notice, the back face is drawn exactly the same as the front face, it's just further into the screen. Play around with the code, and if you just can't grasp it, email me, and I'll try to answer your questions.

Jeff Molofee (NeHe)

* DOWNLOAD Visual C++Code For This Lesson.

* DOWNLOAD ASMCode For This Lesson. (Conversion by Foolman)

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

* DOWNLOAD Code Warrior 5Code For This Lesson. (Conversion by Scott Lupton)

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

* DOWNLOAD DelphiCode For This Lesson. (Conversion by Peter De Jaegher)

* 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 Power BasicCode For This Lesson. (Conversion by Angus Law)

* DOWNLOAD PythonCode For This Lesson. (Conversion by Tony Colston)

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

* DOWNLOAD Visual BasicCode For This Lesson. (Conversion by Ross Dawson)

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

Lesson 06

Learning how to texture map has many benefits. Lets say you wanted a missile to fly across the screen. Up until this tutorial we'd probably make the entire missile out of polygons, and fancy colors. With texture mapping, you can take a real picture of a missile and make the picture fly across the screen. Which do you think will look better? A photograph or an object made up of triangles and squares? By using texture mapping, not only will it look better, but your program will run faster. The texture mapped missile would only be one quad moving across the screen. A missile made out of polygons could be made up of hundreds or thousands of polygons. The single texture mapped quad will use alot less processing power.

Lets start off by adding five new lines of code to the top of lesson one. The first new line is #include . Adding this header file allows us to work with files. In order to use fopen() later in the code we need to include this line. Then we add three new floating point variables… xrot, yrot and zrot. These variables will be used to rotate the cube on the x axis, the y axis, and the z axis. The last line GLuint texture[1] sets aside storage space for one texture. If you wanted to load in more than one texture, you would change the number one to the number of textures you wish to load.

#include // Header File For Windows

#include // Header File For Standard Input/Output ( NEW )

#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

bool fullscreen=TRUE; // Fullscreen Flag

GLfloat xrot; // X Rotation ( NEW )

GLfloat yrot; // Y Rotation ( NEW )

GLfloat zrot; // Z Rotation ( NEW )

GLuint texture[1]; // Storage For One Texture ( NEW )

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc

Now immediately after the above code, and before ReSizeGLScene(), we want to add the following section of code. The job of this code is to load in a bitmap file. If the file doesn't exist NULL is sent back meaning the texture couldn't be loaded. Before I start explaining the code there are a few VERY important things you need to know about the images you plan to use as textures. The image height and width MUST be a power of 2. The width and height must be at least 64 pixels, and for compatability reasons, shouldn't be more than 256 pixels. If the image you want to use is not 64, 128 or 256 pixels on the width or height, resize it in an art program. There are ways around this limitation, but for now we'll just stick to standard texture sizes.

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

Интервал:

Закладка:

Сделать

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