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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
MessageBox(NULL, "Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL, "Could Not Release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}
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
}
}
The CreateGLWindow() and WndProc() code hasn't changed. So I'll skip over it.
BOOL CreateGLWindow() // Creates The GL Window
LRESULT CALLBACK WndProc() // Handle For This Window
In WinMain() there are a few changes. First thing to note is the new caption on the title bar :)
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("Piotr Cieslak & NeHe's Morphing Points 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 && keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signaled A Quit
} else // Not Time To Quit, Update Screen
{
DrawGLScene(); // Draw The Scene (Don't Draw When Inactive 1% CPU Use)
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
The code below watches for key presses. By now you should understand the code fairly easily. If page up is pressed we increase zspeed. This causes the object to spin faster on the z axis in a positive direction.
If page down is pressed we decrease zspeed. This causes the object to spin faster on the z axis in a negative direction.
If the down arrow is pressed we increase xspeed. This causes the object to spin faster on the x axis in a positive direction.
If the up arrow is pressed we decrease xspeed. This causes the object to spin faster on the x axis in a negative direction.
If the right arrow is pressed we increase yspeed. This causes the object to spin faster on the y axis in a positive direction.
If the left arrow is pressed we decrease yspeed. This causes the object to spin faster on the y axis in a negative direction.
if(keys[VK_PRIOR]) // Is Page Up Being Pressed?
zspeed+=0.01f; // Increase zspeed
if(keys[VK_NEXT]) // Is Page Down Being Pressed?
zspeed-=0.01f; // Decrease zspeed
if(keys[VK_DOWN]) // Is Page Up Being Pressed?
xspeed+=0.01f; // Increase xspeed
if(keys[VK_UP]) // Is Page Up Being Pressed?
xspeed-=0.01f; // Decrease xspeed
if(keys[VK_RIGHT]) // Is Page Up Being Pressed?
yspeed+=0.01f; // Increase yspeed
if(keys[VK_LEFT]) // Is Page Up Being Pressed?
yspeed-=0.01f; // Decrease yspeed
The following keys physically move the object. 'Q' moves it into the screen, 'Z' moves it towards the viewer, 'W' moves the object up, 'S' moves it down, 'D' moves it right, and 'A' moves it left.
if (keys['Q']) // Is Q Key Being Pressed?
cz-=0.01f; // Move Object Away From Viewer
if (keys['Z']) // Is Z Key Being Pressed?
cz+=0.01f; // Move Object Towards Viewer
if (keys['W']) // Is W Key Being Pressed?
cy+=0.01f; // Move Object Up
if (keys['S']) // Is S Key Being Pressed?
cy-=0.01f; // Move Object Down
if (keys['D']) // Is D Key Being Pressed?
cx+=0.01f; // Move Object Right
if (keys['A']) // Is A Key Being Pressed?
cx-=0.01f; // Move Object Left
Now we watch to see if keys 1 through 4 are pressed. If 1 is pressed and key is not equal to 1 (not the current object already) and morph is false (not already in the process of morphing), we set key to 1, so that our program knows we just selected object 1. We then set morph to TRUE, letting our program know it's time to start morphing, and last we set the destination object (dest) to equal object 1 (morph1).
Pressing keys 2, 3, and 4 does the same thing. If 2 is pressed we set dest to morph2, and we set key to equal 2. Pressing 3, sets dest to morph3 and key to 3.
By setting key to the value of the key we just pressed on the keyboard, we prevent the user from trying to morph from a sphere to a sphere or a cone to a cone!
if (keys['1'] && (key!=1) && !morph) // Is 1 Pressed, key Not Equal To 1 And Morph False?
{
key=1; // Sets key To 1 (To Prevent Pressing 1 2x In A Row)
morph=TRUE; // Set morph To True (Starts Morphing Process)
dest=&morph1; // Destination Object To Morph To Becomes morph1
}
if (keys['2'] && (key!=2) && !morph) // Is 2 Pressed, key Not Equal To 2 And Morph False?
{
key=2; // Sets key To 2 (To Prevent Pressing 2 2x In A Row)
morph=TRUE; // Set morph To True (Starts Morphing Process)
dest=&morph2; // Destination Object To Morph To Becomes morph2
}
if (keys['3'] && (key!=3) && !morph) // Is 3 Pressed, key Not Equal To 3 And Morph False?
{
key=3; // Sets key To 3 (To Prevent Pressing 3 2x In A Row)
morph=TRUE; // Set morph To True (Starts Morphing Process)
dest=&morph3; // Destination Object To Morph To Becomes morph3
}
if (keys['4'] && (key!=4) && !morph) // Is 4 Pressed, key Not Equal To 4 And Morph False?
{
key=4; // Sets key To 4 (To Prevent Pressing 4 2x In A Row)
morph=TRUE; // Set morph To True (Starts Morphing Process)
dest=&morph4; // Destination Object To Morph To Becomes morph4
Интервал:
Закладка:
Похожие книги на «NeHe's OpenGL Tutorials»
Представляем Вашему вниманию похожие книги на «NeHe's OpenGL Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «NeHe's OpenGL Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.