Jeff Molofee - NeHe's OpenGL Tutorials
Здесь есть возможность читать онлайн «Jeff Molofee - NeHe's OpenGL Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:NeHe's OpenGL Tutorials
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:3 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 60
- 1
- 2
- 3
- 4
- 5
NeHe's OpenGL Tutorials: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «NeHe's OpenGL Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
NeHe's OpenGL Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «NeHe's OpenGL Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
if (hourglass.fx==1) // If fx=1 Draw The Hourglass
{
glLoadIdentity(); // Reset The Modelview Matrix
glTranslatef(20.0f+(hourglass.x*60), 70.0f+(hourglass.y*40),0.0f); // Move To The Fine Hourglass Position
glRotatef(hourglass.spin, 0.0f, 0.0f, 1.0f); // Rotate Clockwise
glColor3ub(rand()%255, rand()%255, rand()%255); // Set Hourglass Color To Random Color
glBegin(GL_LINES) tells OpenGL we want to draw using lines. We start off by moving left and up 5 pixels from our current location. This gives us the top left point of our hourglass. OpenGL will start drawing the line from this location. The end of the line will be 5 pixels right and down from our original location. This gives us a line running from the top left to the bottom right. Immediately after that we draw a second line running from the top right to the bottom left. This gives us an 'X'. We finish off by connecting the bottom two points together, and then the top two points to create an hourglass type object :)
glBegin(GL_LINES); // Start Drawing Our Hourglass Using Lines
glVertex2d(-5,-5); // Top Left Of Hourglass
glVertex2d( 5, 5); // Bottom Right Of Hourglass
glVertex2d( 5,-5); // Top Right Of Hourglass
glVertex2d(-5, 5); // Bottom Left Of Hourglass
glVertex2d(-5, 5); // Bottom Left Of Hourglass
glVertex2d( 5, 5); // Bottom Right Of Hourglass
glVertex2d(-5,-5); // Top Left Of Hourglass
glVertex2d( 5,-5); // Top Right Of Hourglass
glEnd(); // Done Drawing The Hourglass
}
Now we draw our player. We reset the modelview matrix, and position the player on the screen. Notice we position the player using fx and fy. We want the player to move smoothly so we use fine positioning. After positioning the player, we rotate the player on it's z-axis using player.spin. We set the color to light green and begin drawing. Just like the code we used to draw the hourglass, we draw an 'X'. Starting at the top left to the bottom right, then from the top right to the bottom left.
glLoadIdentity(); // Reset The Modelview Matrix
glTranslatef(player.fx+20.0f,player.fy+70.0f,0.0f); // Move To The Fine Player Position
glRotatef(player.spin,0.0f,0.0f,1.0f); // Rotate Clockwise
glColor3f(0.0f,1.0f,0.0f); // Set Player Color To Light Green
glBegin(GL_LINES); // Start Drawing Our Player Using Lines
glVertex2d(-5,-5); // Top Left Of Player
glVertex2d( 5, 5); // Bottom Right Of Player
glVertex2d( 5,-5); // Top Right Of Player
glVertex2d(-5, 5); // Bottom Left Of Player
glEnd(); // Done Drawing The Player
Drawing low detail objects with lines can be a little frustrating. I didn't want the player to look boring so I added the next section of code to create a larger and quicker spinning blade on top of the player that we drew above. We rotate on the z-axis by player.spin times 0.5f. Because we are rotating again, it will appear as if this piece of the player is moving a little quicker than the first piece of the player.
After doing the new rotation, we set the color to a darker shade of green. So that it actually looks like the player is made up of different colors / pieces. We then draw a large '+' on top of the first piece of the player. It's larger because we're using –7 and +7 instead of –5 and +5. Also notice that instead of drawing from one corner to another, I'm drawing this piece of the player from left to right and top to bottom.
glRotatef(player.spin*0.5f,0.0f,0.0f,1.0f); // Rotate Clockwise
glColor3f(0.0f,0.75f,0.0f); // Set Player Color To Dark Green
glBegin(GL_LINES); // Start Drawing Our Player Using Lines
glVertex2d(-7, 0); // Left Center Of Player
glVertex2d( 7, 0); // Right Center Of Player
glVertex2d( 0,-7); // Top Center Of Player
glVertex2d( 0, 7); // Bottom Center Of Player
glEnd(); // Done Drawing The Player
All we have to do now is draw the enemies, and we're done drawing :) We start off by creating a loop that will loop through all the enemies visible on the current level. We calculate how many enemies to draw by multiplying our current game stage by the games internal level. Remember that each level has 3 stages, and the maximum value of the internal level is 3. So we can have a maximum of 9 enemies.
Inside the loop we reset the modelview matrix, and position the current enemy (enemy[loop1]). We position the enemy using it's fine x and y values (fx and fy). After positioning the current enemy we set the color to pink and start drawing.
The first line will run from 0, –7 (7 pixels up from the starting location) to –7,0 (7 pixels left of the starting location). The second line runs from –7,0 to 0,7 (7 pixels down from the starting location). The third line runs from 0,7 to 7,0 (7 pixels to the right of our starting location), and the last line runs from 7,0 back to the beginning of the first line (7 pixels up from the starting location). This creates a non spinning pink diamond on the screen.
for (loop1=0; loop1<(stage*level); loop1++) // Loop To Draw Enemies
{
glLoadIdentity(); // Reset The Modelview Matrix
glTranslatef(enemy[loop1].fx+20.0f,enemy[loop1].fy+70.0f,0.0f);
glColor3f(1.0f,0.5f,0.5f); // Make Enemy Body Pink
glBegin(GL_LINES); // Start Drawing Enemy
glVertex2d( 0,-7); // Top Point Of Body
glVertex2d(-7, 0); // Left Point Of Body
glVertex2d(-7, 0); // Left Point Of Body
glVertex2d( 0, 7); // Bottom Point Of Body
glVertex2d( 0, 7); // Bottom Point Of Body
glVertex2d( 7, 0); // Right Point Of Body
glVertex2d( 7, 0); // Right Point Of Body
glVertex2d( 0,-7); // Top Point Of Body
glEnd(); // Done Drawing Enemy Body
We don't want the enemy to look boring either so we'll add a dark red spinning blade ('X') on top of the diamond that we just drew. We rotate on the z-axis by enemy[loop1].spin, and then draw the 'X'. We start at the top left and draw a line to the bottom right. Then we draw a second line from the top right to the bottom left. The two lines cross eachother creating an 'X' (or blade … grin).
glRotatef(enemy[loop1].spin,0.0f,0.0f,1.0f); // Rotate The Enemy Blade
glColor3f(1.0f,0.0f,0.0f); // Make Enemy Blade Red
glBegin(GL_LINES); // Start Drawing Enemy Blade
glVertex2d(-7,-7); // Top Left Of Enemy
glVertex2d( 7, 7); // Bottom Right Of Enemy
glVertex2d(-7, 7); // Bottom Left Of Enemy
glVertex2d( 7,-7); // Top Right Of Enemy
glEnd(); // Done Drawing Enemy Blade
}
return TRUE; // Everything Went OK
}
I added the KillFont() command to the end of KillGLWindow(). This makes sure the font display list is destroyed when the window is destroyed.
GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}
if (hRC) // Do We Have A Rendering Context?
Интервал:
Закладка:
Похожие книги на «NeHe's OpenGL Tutorials»
Представляем Вашему вниманию похожие книги на «NeHe's OpenGL Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «NeHe's OpenGL Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.