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

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

Интервал:

Закладка:

Сделать

Now that we have these variables down, we can proceed with steps two and three. This will be done in the display loop, as our program isn't complicated enough to merit a seperate function.

int DrawGLScene(GLvoid) // Draw The OpenGL Scene

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

glLoadIdentity(); // Reset The Current Matrix

GLfloat x_m, y_m, z_m, u_m, v_m; // Floating Point For Temp X, Y, Z, U And V Vertices

GLfloat xtrans = –xpos; // Used For Player Translation On The X Axis

GLfloat ztrans = –zpos; // Used For Player Translation On The Z Axis

GLfloat ytrans = –walkbias-0.25f; // Used For Bouncing Motion Up And Down

GLfloat sceneroty = 360.0f – yrot; // 360 Degree Angle For Player Direction

int numtriangles; // Integer To Hold The Number Of Triangles

glRotatef(lookupdown,1.0f,0,0); // Rotate Up And Down To Look Up And Down

glRotatef(sceneroty,0,1.0f,0); // Rotate Depending On Direction Player Is Facing

glTranslatef(xtrans, ytrans, ztrans); // Translate The Scene Based On Player Position

glBindTexture(GL_TEXTURE_2D, texture[filter]); // Select A Texture Based On filter

numtriangles = sector1.numtriangles; // Get The Number Of Triangles In Sector 1

// Process Each Triangle

for (int loop_m = 0; loop_m < numtriangles; loop_m++) // Loop Through All The Triangles

{

glBegin(GL_TRIANGLES); // Start Drawing Triangles

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

x_m = sector1.triangle[loop_m].vertex[0].x; // X Vertex Of 1st Point

y_m = sector1.triangle[loop_m].vertex[0].y; // Y Vertex Of 1st Point

z_m = sector1.triangle[loop_m].vertex[0].z; // Z Vertex Of 1st Point

u_m = sector1.triangle[loop_m].vertex[0].u; // U Texture Coord Of 1st Point

v_m = sector1.triangle[loop_m].vertex[0].v; // V Texture Coord Of 1st Point

glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m); // Set The TexCoord And Vertice

x_m = sector1.triangle[loop_m].vertex[1].x; // X Vertex Of 2nd Point

y_m = sector1.triangle[loop_m].vertex[1].y; // Y Vertex Of 2nd Point

z_m = sector1.triangle[loop_m].vertex[1].z; // Z Vertex Of 2nd Point

u_m = sector1.triangle[loop_m].vertex[1].u; // U Texture Coord Of 2nd Point

v_m = sector1.triangle[loop_m].vertex[1].v; // V Texture Coord Of 2nd Point

glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m); // Set The TexCoord And Vertice

x_m = sector1.triangle[loop_m].vertex[2].x; // X Vertex Of 3rd Point

y_m = sector1.triangle[loop_m].vertex[2].y; // Y Vertex Of 3rd Point

z_m = sector1.triangle[loop_m].vertex[2].z; // Z Vertex Of 3rd Point

u_m = sector1.triangle[loop_m].vertex[2].u; // U Texture Coord Of 3rd Point

v_m = sector1.triangle[loop_m].vertex[2].v; // V Texture Coord Of 3rd Point

glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m); // Set The TexCoord And Vertice

glEnd(); // Done Drawing Triangles

}

return TRUE; // Jump Back

}

And voilà! We have drawn our first frame. This isn't exactly Quake but hey, we aren't exactly Carmack's or Abrash's. While running the program, you may want to press F, B, PgUp and PgDown to see added effects. PgUp/Down simply tilts the camera up and down (the same process as panning from side to side.) The texture included is simply a mud texture with a bumpmap of my school ID picture; that is, if NeHe decided to keep it :-).

So now you're probably thinking where to go next. Don't even consider using this code to make a full-blown 3D engine, since that's not what it's designed for. You'll probably want more than one sector in your game, especially if you're going to implement portals. You'll also want to have polygons with more than 3 vertices, again, essential for portal engines. My current implementation of this code allows for multiple sector loading and does backface culling (not drawing polygons that face away from the camera). I'll write a tutorial on that soon, but as it uses alot of math, I'm going to write a tutorial on matrices first.

NeHe (05/01/00):

I've added FULL comments to each of the lines listed in this tutorial. Hopefully things make more sense now. Only a few of the lines had comments after them, now they all do :)

Please, if you have any problems with the code/tutorial (this is my first tutorial, so my explanations are a little vague), don't hesitate to email me mailto:iam@cadvision.comUntil next time…

Lionel Brits (ßetelgeuse) 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 IrixCode For This Lesson. (Conversion by Rob Fletcher)

* 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 Visual BasicCode For This Lesson. (Conversion by Jarred Capellman)

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

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

Lesson 11

Well greetings all. For those of you that want to see what we are doing here, you can check it out at the end of my demo/hack Worthless! I am bosco and I will do my best to teach you guys how to do the animated, sine-wave picture. This tutorial is based on NeHe's tutorial #6 and you should have at least that much knowledge. You should download the source package and place the bitmap I've included in a directory called data where your source code is. Or use your own texture if it's an appropriate size to be used as a texture with OpenGL.

First things first. Open Tutorial #6 in Visual C++ and add the following include statement right after the other #include statements. The #include below allows us to work with complex math such as sine and cosine.

#include // For The Sin() Function

We'll use the array points to store the individual x, y & z coordinates of our grid. The grid is 45 points by 45 points, which in turn makes 44 quads x 44 quads. wiggle_count will be used to keep track of how fast the texture waves. Every three frames looks pretty good, and the variable hold will store a floating point value to smooth out the waving of the flag. These lines can be added at the top of the program, somewhere under the last #include line, and before the GLuint texture[1] line.

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

Интервал:

Закладка:

Сделать

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