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

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

Интервал:

Закладка:

Сделать

gluLookAt can be very intimidating when you first use it. After reading the rough explanation above you may still be confused. My best advise is to play around with the values. Change the camera position. If you were to change the y position of the camera to say 120, you would see more of the top of the landscape, because you would be looking all the way down to 55.

I'm not sure if this will help, but I'm going to break into one of my highly flamed real life "example" explanations :) Lets say you are 6 feet and a bit tall. Lets also assume your eyes are at the 6 foot mark (your eyes represent the camera — 6 foot is 6 units on the y-axis). Now if you were standing in front of a wall that was only 2 feet tall (2 units on the y-axis), you would be looking DOWN at the wall and would be able to see the top of the wall. If the wall was 8 feet tall, you would be looking UP at the wall and you would NOT see the top of the wall. The view would change depending on if you were looking up or down (if you were higher than or lower than the object you are looking at). Hope that makes a bit of sense!

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 Matrix

// Position View Up Vector

gluLookAt(212, 60, 194, 186, 55, 171, 0, 1, 0); // This Determines The Camera's Position And View

This will scale down our terrain so it's a bit easier to view and not so big. We can change this scaleValue by using the UP and DOWN arrows on the keyboard. You will notice that we mupltiply the Y scaleValue by a HEIGHT_RATIO as well. This is so the terrain appears higher and gives it more definition.

glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);

If we pass the g_HeightMap data into our RenderHeightMap() function it will render the terrain in Quads. If you are going to make any use of this function, it might be a good idea to put in an (X, Y) parameter to draw it at, or just use OpenGL's matrix operations (glTranslatef() glRotate(), etc) to position the land exactly where you want it.

RenderHeightMap(g_HeightMap); // Render The Height Map

return TRUE; // Keep Going

}

The KillGLWindow() code is the same as lesson 1.

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window

{ }

The CreateGLWindow() code is also the same as lesson 1.

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { }

The only change in WndProc() is the addition of WM_LBUTTONDOWN. What it does is checks to see if the left mouse button was pressed. If it was, the rendering state is toggled from polygon mode to line mode, or from line mode to polygon mode.

LRESULT CALLBACK WndProc(HWND hWnd, // Handle For This Window

UINT uMsg, // Message For This Window

WPARAM wParam, // Additional Message Information

LPARAM lParam) // Additional Message Information

{

switch (uMsg) // Check For Windows Messages

{

case WM_ACTIVATE: // Watch For Window Activate Message

{

if (!HIWORD(wParam)) // Check Minimization State

{

active=TRUE; // Program Is Active

} else {

active=FALSE; // Program Is No Longer Active

}

return 0; // Return To The Message Loop

}

case WM_SYSCOMMAND: // Intercept System Commands

{

switch (wParam) // Check System Calls

{

case SC_SCREENSAVE: // Screensaver Trying To Start?

case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?

return 0; // Prevent From Happening

}

break; // Exit

}

case WM_CLOSE: // Did We Receive A Close Message?

{

PostQuitMessage(0); // Send A Quit Message

return 0; // Jump Back

}

case WM_LBUTTONDOWN: // Did We Receive A Left Mouse Click?

{

bRender = !bRender; // Change Rendering State Between Fill/Wire Frame

return 0; // Jump Back

}

case WM_KEYDOWN: // Is A Key Being Held Down?

{

keys[wParam] = TRUE; // If So, Mark It As TRUE

return 0; // Jump Back

}

case WM_KEYUP: // Has A Key Been Released?

{

keys[wParam] = FALSE; // If So, Mark It As FALSE

return 0; // Jump Back

}

case WM_SIZE: // Resize The OpenGL Window

{

ReSizeGLScene(LOWORD(lParam), HIWORD(lParam)); // LoWord=Width, HiWord=Height

return 0; // Jump Back

}

}

// Pass All Unhandled Messages To DefWindowProc

return DefWindowProc(hWnd, uMsg, wParam, lParam);

}

No major changes in this section of code. The only notable change is the title of the window. Everything else is the same up until we check for key presses.

int WINAPI WinMain(HINSTANCE hInstance, // Instance

HINSTANCE hPrevInstance, // Previous Instance

LPSTR lpCmdLine, // Command Line Parameters

int nCmdShow) // Window Show State

{

MSG msg; // Windows Message Structure

BOOL done=FALSE; // Bool Variable To Exit Loop

// Ask The User Which Screen Mode They Prefer

if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO|MB_ICONQUESTION) == IDNO) {

fullscreen=FALSE; // Windowed Mode

}

// Create Our OpenGL Window

if (!CreateGLWindow("NeHe & Ben Humphrey's Height Map Tutorial", 640, 480, 16, fullscreen)) {

return 0; // Quit If Window Was Not Created

}

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 if (active) // Not Time To Quit, Update Screen

{

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

}

if (keys[VK_F1]) // Is F1 Being Pressed?

{

keys[VK_F1]=FALSE; // If So Make Key FALSE

KillGLWindow(); // Kill Our Current Window

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

Интервал:

Закладка:

Сделать

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