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

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

Интервал:

Закладка:

Сделать

}

while(!done) // Loop That Runs While done=FALSE

{

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // Is There A Message Waiting?

{

if (msg.message==WM_QUIT) // Have We Received A Quit Message?

{

done=TRUE; // If So done=TRUE

} else // If Not, Deal With Window Messages

{

TranslateMessage(&msg); // Translate The Message

DispatchMessage(&msg); // Dispatch The Message

}

} else // If There Are No Messages

{

// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()

if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?

{

done=TRUE; // ESC or DrawGLScene Signalled A Quit

} else // Not Time To Quit, Update Screen

{

SwapBuffers(hDC); // Swap Buffers (Double Buffering)

}

}

}

// Shutdown

The last thing to do is add KillFont() to the end of KillGLWindow() just like I'm showing below. It's important to add this line. It cleans things up before we exit our program.

if (!UnregisterClass("OpenGL", hInstance)) // Are We Able To Unregister Class

{

MessageBox(NULL, "Could Not Unregister Class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);

hInstance=NULL; // Set hInstance To NULL

}

KillFont(); // Destroy The Font

}

I think I can officially say that my site now teaches every possible way to write text to the screen {grin}. All in all, I think this is a fairly good tutorial. The code can be used on any computer that can run OpenGL, it's easy to use, and writing text to the screen using this method requires very little processing power.

I'd like to thank Giuseppe D'Agata for the original version of this tutorial. I've modified it heavily, and converted it to the new base code, but without him sending me the code I probably wouldn't have written the tutorial. His version of the code had a few more options, such as spacing the characters, etc, but I make up for it with the extremely cool 3D object {grin}.

I hope everyone enjoys this tutorial. If you have questions, email Giuseppe D'Agata or myself.

Giuseppe D'Agata 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 Irix / GLUTCode For This Lesson. (Conversion by Rob Fletcher)

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

* 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 Visual C++ / OpenILCode For This Lesson. (Conversion by Denton Woods)

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

Lesson 18

Quadrics

Quadrics are a way of drawing complex objects that would usually take a few FOR loops and some background in trigonometry.

We'll be using the code from lesson seven. We will add 7 variables and modify the texture to add some variety :)

#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

bool light; // Lighting ON/OFF

bool lp; // L Pressed?

bool fp; // F Pressed?

bool sp; // Spacebar Pressed? ( NEW )

int part1; // Start Of Disc ( NEW )

int part2; // End Of Disc ( NEW )

int p1=0; // Increase 1 ( NEW )

int p2=1; // Increase 2 ( NEW )

GLfloat xrot; // X Rotation

GLfloat yrot; // Y Rotation

GLfloat xspeed; // X Rotation Speed

GLfloat yspeed; // Y Rotation Speed

GLfloat z=-5.0f; // Depth Into The Screen

GLUquadricObj *quadratic; // Storage For Our Quadratic Objects ( NEW )

GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values

GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values

GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position

GLuint filter; // Which Filter To Use

GLuint texture[3]; // Storage for 3 textures

GLuint object=0; // Which Object To Draw ( NEW )

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

Okay now move down to InitGL(), We're going to add 3 lines of code here to initialize our quadratic. Add these 3 lines after you enable light1 but before you return true. The first line of code initializes the Quadratic and creates a pointer to where it will be held in memory. If it can't be created it returns 0. The second line of code creates smooth normals on the quadratic so lighting will look great. Other possible values are GLU_NONE, and GLU_FLAT. Last we enable texture mapping on our quadratic. Texture mapping is kind of awkward and never goes the way you planned as you can tell from the crate texture.

quadratic=gluNewQuadric(); // Create A Pointer To The Quadric Object ( NEW )

gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals ( NEW )

gluQuadricTexture(quadratic, GL_TRUE); // Create Texture Coords ( NEW )

Now I decided to keep the cube in this tutorial so you can see how the textures are mapped onto the quadratic object. I decided to move the cube into its own function so when we write the draw function it will appear more clean. Everybody should recognize this code. =P

GLvoid glDrawCube() // Draw A Cube

{

glBegin(GL_QUADS); // Start Drawing Quads

// Front Face

glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Facing Forward

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, –1.0f, 1.0f); // Bottom Left Of The Texture and Quad

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, –1.0f, 1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad

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

Интервал:

Закладка:

Сделать

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