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

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

Интервал:

Закладка:

Сделать

// Back Face

glNormal3f( 0.0f, 0.0f,-1.0f); // Normal Facing Away

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

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

// Top Face

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

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

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

// Bottom Face

glNormal3f( 0.0f,-1.0f, 0.0f); // Normal Facing Down

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

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

// Right face

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

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

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

// Left Face

glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Facing Left

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

glEnd(); // Done Drawing Quads

}

Next is the DrawGLScene function, here I just wrote a simple if statement to draw the different objects. Also I used a static variable (a local variable that keeps its value everytime it is called) for a cool effect when drawing the partial disk. I'm going to rewrite the whole DrawGLScene function for clarity.

You'll notice that when I talk about the parameters being used I ignore the actual first parameter (quadratic). This parameter is used for all the objects we draw aside from the cube, so I ignore it when I talk about the parameters.

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing

{

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

glLoadIdentity(); // Reset The View

glTranslatef(0.0f,0.0f,z); // Translate Into The Screen

glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis

glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis

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

// This Section Of Code Is New ( NEW )

switch(object) // Check object To Find Out What To Draw

{

case 0: // Drawing Object 1

glDrawCube(); // Draw Our Cube

break; // Done

The second object we create is going to be a Cylinder. The first parameter (1.0f) is the radius of the cylinder at base (bottom). The second parameter (1.0f) is the radius of the cylinder at the top. The third parameter ( 3.0f) is the height of the cylinder (how long it is). The fouth parameter (32) is how many subdivisions there are "around" the Z axis, and finally, the fifth parameter (32) is the amount of subdivisions "along" the Z axis. The more subdivisions there are the more detailed the object is. By increase the amount of subdivisions you add more polygons to the object. So you end up sacrificing speed for quality. Most of the time it's easy to find a happy medium.

case 1: // Drawing Object 2

glTranslatef(0.0f,0.0f,-1.5f); // Center The Cylinder

gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32); // Draw Our Cylinder

break; // Done

The third object we create will be a CD shaped disc. The first parameter (0.5f) is the inner radius of the disk. This value can be zero, meaning there will be no hole in the middle. The larger the inner radius is, the bigger the hole in the middle of the disc will be. The second parameter (1.5f) is the outer radius. This value should be larger than the inner radius. If you make this value a little bit larger than the inner radius you will end up with a thing ring. If you make this value alot larger than the inner radius you will end up with a thick ring. The third parameter (32) is the number of slices that make up the disc. Think of slices like the slices in a pizza. The more slices you have, the smoother the outer edge of the disc will be. Finally the fourth parameter (32) is the number of rings that make up the disc. The rings are are similar to the tracks on a record. Circles inside circles. These ring subdivide the disc from the inner radius to the outer radius, adding more detail. Again, the more subdivisions there are, the slow it will run.

case 2: // Drawing Object 3

gluDisk(quadratic,0.5f,1.5f,32,32); // Draw A Disc (CD Shape)

break; // Done

Our fourth object is an object that I know many of you have been dying to figure out. The Sphere! This one is quite simple. The first parameter is the radius of the sphere. In case you're not familiar with radius/diameter, etc, the radius is the distance from the center of the object to the outside of the object. In this case our radius is 1.3f. Next we have our subdivision "around" the Z axis (32), and our subdivision "along" the Z axis (32). The more subdivisions you have the smoother the sphere will look. Spheres usually require quite a few subdivisions to make them look smooth.

case 3: // Drawing Object 4

gluSphere(quadratic,1.3f,32,32); // Draw A Sphere

break; // Done

Our fifth object is created using the same command that we used to create a Cylinder. If you remember, when we were creating the Cylinder the first two parameters controlled the radius of the cylinder at the bottom and the top. To make a cone it makes sense that all we'd have to do is make the radius at one end Zero. This will create a point at one end. So in the code below, we make the radius at the top of the cylinder equal zero. This creates our point, which also creates our cone.

case 4: // Drawing Object 5

glTranslatef(0.0f,0.0f,-1.5f); // Center The Cone

gluCylinder(quadratic, 1.0f, 0.0f, 3.0f, 32, 32); // A Cone With A Bottom Radius Of .5 And A Height Of 2

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

Интервал:

Закладка:

Сделать

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