mirror of
https://github.com/reactos/reactos.git
synced 2024-10-04 08:25:53 +00:00
[FORMATTING] Fix indentation and move comments
svn path=/trunk/; revision=31542
This commit is contained in:
parent
68981a6100
commit
4f648ef5d9
|
@ -18,10 +18,10 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
#include <windows.h> // Header File For Windows
|
||||
#include <math.h> // Header File For Windows Math Library
|
||||
#include <GL/gl.h> // Header File For The OpenGL32 Library
|
||||
#include <GL/glu.h> // Header File For The GLu32 Library
|
||||
#include <windows.h>
|
||||
#include <math.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
@ -38,14 +38,18 @@ GLfloat rot; // Used To Rotate The Text
|
|||
HINSTANCE hInstance;
|
||||
BOOL fullscreen = FALSE;
|
||||
|
||||
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
|
||||
// Build Our Bitmap Font
|
||||
GLvoid BuildFont(GLvoid)
|
||||
{
|
||||
GLYPHMETRICSFLOAT gmf[256]; // Address Buffer For Font Storage
|
||||
HFONT font; // Windows Font ID
|
||||
// Address Buffer For Font Storage
|
||||
GLYPHMETRICSFLOAT gmf[256];
|
||||
// Windows Font Handle
|
||||
HFONT font;
|
||||
|
||||
base = glGenLists(256); // Storage For 256 Characters
|
||||
// Storage For 256 Characters
|
||||
base = glGenLists(256);
|
||||
|
||||
font = CreateFont( -12, // Height Of Font
|
||||
font = CreateFont(-12,
|
||||
0, // Width Of Font
|
||||
0, // Angle Of Escapement
|
||||
0, // Orientation Angle
|
||||
|
@ -60,7 +64,8 @@ GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
|
|||
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
|
||||
_T("Tahoma")); // Font Name
|
||||
|
||||
SelectObject(hDC, font); // Selects The Font We Created
|
||||
// Selects The Font We Created
|
||||
SelectObject(hDC, font);
|
||||
|
||||
wglUseFontOutlines(hDC, // Select The Current DC
|
||||
0, // Starting Character
|
||||
|
@ -72,88 +77,149 @@ GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
|
|||
gmf); // Address Of Buffer To Recieve Data
|
||||
}
|
||||
|
||||
GLvoid KillFont(GLvoid) // Delete The Font
|
||||
// Delete The Font
|
||||
GLvoid KillFont(GLvoid)
|
||||
{
|
||||
glDeleteLists(base, 256); // Delete All 256 Characters
|
||||
// Delete all 256 characters
|
||||
glDeleteLists(base, 256);
|
||||
}
|
||||
|
||||
GLvoid glPrint(LPTSTR text) // Custom GL "Print" Routine
|
||||
// Custom GL "Print" Routine
|
||||
GLvoid glPrint(LPTSTR text)
|
||||
{
|
||||
if (text == NULL) // If There's No Text
|
||||
return; // Do Nothing
|
||||
// If there's no text, do nothing
|
||||
if (text == NULL)
|
||||
return;
|
||||
|
||||
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
|
||||
glListBase(base); // Sets The Base Character to 32
|
||||
// Pushes The Display List Bits
|
||||
glPushAttrib(GL_LIST_BIT);
|
||||
|
||||
// Sets The Base Character to 32
|
||||
glListBase(base);
|
||||
|
||||
// Draws The Display List Text
|
||||
glCallLists(_tcslen(text),
|
||||
#ifdef UNICODE
|
||||
GL_UNSIGNED_SHORT
|
||||
GL_UNSIGNED_SHORT,
|
||||
#else
|
||||
GL_UNSIGNED_BYTE
|
||||
GL_UNSIGNED_BYTE,
|
||||
#endif
|
||||
, text); // Draws The Display List Text
|
||||
text);
|
||||
|
||||
glPopAttrib(); // Pops The Display List Bits
|
||||
// Pops The Display List Bits
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
GLvoid InitGL(GLsizei Width, GLsizei Height) // Will Be Called Right After The GL Window Is Created
|
||||
// Will Be Called Right After The GL Window Is Created
|
||||
GLvoid InitGL(GLsizei Width, GLsizei Height)
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Clear The Background Color To Black
|
||||
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
|
||||
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
|
||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
||||
// Clear The Background Color To Black
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
|
||||
glLoadIdentity(); // Reset The Projection Matrix
|
||||
// Enables Clearing Of The Depth Buffer
|
||||
glClearDepth(1.0);
|
||||
|
||||
// The Type Of Depth Test To Do
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
// Enables Depth Testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Enables Smooth Color Shading
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
// Select The Projection Matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
// Reset The Projection Matrix
|
||||
glLoadIdentity();
|
||||
|
||||
// Calculate The Aspect Ratio Of The Window
|
||||
gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
||||
// Select The Modelview Matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
BuildFont(); // Build The Font
|
||||
glEnable(GL_LIGHT0); // Enable Default Light (Quick And Dirty)
|
||||
glEnable(GL_LIGHTING); // Enable Lighting
|
||||
glEnable(GL_COLOR_MATERIAL); // Enable Coloring Of Material
|
||||
// Build The Font
|
||||
BuildFont();
|
||||
|
||||
// Enable Default Light (Quick And Dirty)
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Enable Lighting
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// Enable Coloring Of Material
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) // Handles Window Resizing
|
||||
// Handles Window Resizing
|
||||
GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height)
|
||||
{
|
||||
if (Height==0) // Is Window Too Small (Divide By Zero Error)
|
||||
Height=1; // If So Make It One Pixel Tall
|
||||
// Is Window Too Small (Divide By Zero Error)
|
||||
if (Height == 0)
|
||||
{
|
||||
// If So Make It One Pixel Tall
|
||||
Height = 1;
|
||||
}
|
||||
|
||||
// Reset The Current Viewport And Perspective Transformation
|
||||
glViewport(0, 0, Width, Height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
|
||||
glLoadIdentity(); // Reset The Projection Matrix
|
||||
// Select The Projection Matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
// Reset The Projection Matrix
|
||||
glLoadIdentity();
|
||||
|
||||
// Calculate The Aspect Ratio Of The Window
|
||||
gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);
|
||||
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
||||
|
||||
// Select The Modelview Matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
GLvoid DrawGLScene(GLvoid) // Handles Rendering
|
||||
// Handles Rendering
|
||||
GLvoid DrawGLScene(GLvoid)
|
||||
{
|
||||
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,-10.0f); // Move One Unit Into The Screen
|
||||
glRotatef(rot,1.0f,0.0f,0.0f); // Rotate On The X Axis
|
||||
glRotatef(rot*1.2f,0.0f,1.0f,0.0f); // Rotate On The Y Axis
|
||||
glRotatef(rot*1.4f,0.0f,0.0f,1.0f); // Rotate On The Z Axis
|
||||
glTranslatef(-3.5f,0.0f,0.0f); // Move To The Left Before Drawing
|
||||
// Clear The Screen And The Depth Buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Reset The View
|
||||
glLoadIdentity();
|
||||
|
||||
// Move One Unit Into The Screen
|
||||
glTranslatef(0.0f, 0.0f, -10.0f);
|
||||
|
||||
// Rotate On The X Axis
|
||||
glRotatef(rot, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
// Rotate On The Y Axis
|
||||
glRotatef(rot * 1.2f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
// Rotate On The Z Axis
|
||||
glRotatef(rot * 1.4f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Move to the Left and Down before drawing
|
||||
glTranslatef(-3.5f, 0.0f, 0.0f);
|
||||
|
||||
// Pulsing Colors Based On The Rotation
|
||||
glColor3f(
|
||||
(1.0f*(cos(rot/20.0f))),
|
||||
glColor3f((1.0f * (cos(rot / 20.0f))),
|
||||
(1.0f * (sin(rot / 25.0f))),
|
||||
(1.0f - 0.5f * (cos(rot / 17.0f))));
|
||||
glPrint(m_Text); // Print GL Text To The Screen
|
||||
glColor3f(0.0f,0.0f,1.0f); // Make The Text Blue
|
||||
rot+=0.1f; // Increase The Rotation Variable
|
||||
|
||||
// Print GL Text To The Screen
|
||||
glPrint(m_Text);
|
||||
|
||||
// Make The Text Blue
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Increase The Rotation Variable
|
||||
rot += 0.1f;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc( HWND hWnd,
|
||||
LRESULT CALLBACK
|
||||
WndProc(HWND hWnd,
|
||||
UINT message,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
|
@ -185,68 +251,96 @@ LRESULT CALLBACK WndProc( HWND hWnd,
|
|||
0, 0, 0 // Layer Masks Ignored (?)
|
||||
};
|
||||
|
||||
switch (message) // Tells Windows We Want To Check The Message
|
||||
switch (message)
|
||||
{
|
||||
case WM_CREATE: // Window Creation
|
||||
hDC = GetDC(hWnd); // Gets A Device Context For The Window
|
||||
PixelFormat = ChoosePixelFormat(hDC, &pfd); // Finds The Closest Match To The Pixel Format We Set Above
|
||||
case WM_CREATE:
|
||||
// Gets A Device Context For The Window
|
||||
hDC = GetDC(hWnd);
|
||||
|
||||
if (!PixelFormat) // No Matching Pixel Format?
|
||||
// Finds The Closest Match To The Pixel Format We Set Above
|
||||
PixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||
|
||||
// No Matching Pixel Format?
|
||||
if (!PixelFormat)
|
||||
{
|
||||
MessageBox(0, _TEXT("Can't Find A Suitable PixelFormat."), _TEXT("Error"),MB_OK | MB_ICONERROR);
|
||||
PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit
|
||||
break; // Prevents The Rest Of The Code From Running
|
||||
|
||||
// This Sends A 'Message' Telling The Program To Quit
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Can We Set The Pixel Mode?
|
||||
// Can We Set The Pixel Mode?
|
||||
if (!SetPixelFormat(hDC, PixelFormat, &pfd))
|
||||
{
|
||||
MessageBox(0, _TEXT("Can't Set The PixelFormat."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||
PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit
|
||||
break; // Prevents The Rest Of The Code From Running
|
||||
|
||||
// This Sends A 'Message' Telling The Program To Quit
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
hRC = wglCreateContext(hDC); // Grab A Rendering Context
|
||||
if(!hRC) // Did We Get One?
|
||||
// Grab A Rendering Context
|
||||
hRC = wglCreateContext(hDC);
|
||||
|
||||
// Did We Get One?
|
||||
if (!hRC)
|
||||
{
|
||||
MessageBox(0, _TEXT("Can't Create A GL Rendering Context."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||
PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit
|
||||
break; // Prevents The Rest Of The Code From Running
|
||||
|
||||
// This Sends A 'Message' Telling The Program To Quit
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!wglMakeCurrent(hDC, hRC)) // Can We Make The RC Active?
|
||||
// Can We Make The RC Active?
|
||||
if (!wglMakeCurrent(hDC, hRC))
|
||||
{
|
||||
MessageBox(0, _TEXT("Can't Activate GLRC."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||
PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit
|
||||
break; // Prevents The Rest Of The Code From Running
|
||||
|
||||
// This Sends A 'Message' Telling The Program To Quit
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
GetClientRect(hWnd, &Screen); // Grab Screen Info For The Current Window
|
||||
InitGL(Screen.right, Screen.bottom); // Initialize The GL Screen Using Screen Info
|
||||
// Grab Screen Info For The Current Window
|
||||
GetClientRect(hWnd, &Screen);
|
||||
|
||||
// Initialize The GL Screen Using Screen Info
|
||||
InitGL(Screen.right, Screen.bottom);
|
||||
break;
|
||||
|
||||
case WM_DESTROY: // Windows Being Destroyed
|
||||
case WM_CLOSE: // Windows Being Closed
|
||||
{
|
||||
ChangeDisplaySettings(NULL, 0); // Disable Fullscreen Mode
|
||||
KillFont(); // Deletes The Font Display List
|
||||
case WM_DESTROY:
|
||||
case WM_CLOSE:
|
||||
// Disable Fullscreen Mode
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
|
||||
wglMakeCurrent(hDC,NULL); // Make The DC Current
|
||||
wglDeleteContext(hRC); // Kill The RC
|
||||
ReleaseDC(hWnd,hDC); // Free The DC
|
||||
// Deletes The Font Display List
|
||||
KillFont();
|
||||
|
||||
PostQuitMessage(0); // Quit The Program
|
||||
}
|
||||
// Make The DC Current
|
||||
wglMakeCurrent(hDC, NULL);
|
||||
|
||||
// Kill The RC
|
||||
wglDeleteContext(hRC);
|
||||
|
||||
// Free The DC
|
||||
ReleaseDC(hWnd, hDC);
|
||||
|
||||
// Quit The Program
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
DrawGLScene();
|
||||
SwapBuffers(hDC);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_NOTIFY:
|
||||
case WM_SYSKEYDOWN:
|
||||
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
case WM_RBUTTONDOWN:
|
||||
|
@ -254,7 +348,6 @@ LRESULT CALLBACK WndProc( HWND hWnd,
|
|||
case WM_MBUTTONDOWN:
|
||||
case WM_MBUTTONUP:
|
||||
case WM_MOUSEMOVE:
|
||||
{
|
||||
// If we've got a parent then we must be a preview
|
||||
if (GetParent(hWnd) != 0)
|
||||
return 0;
|
||||
|
@ -272,22 +365,25 @@ LRESULT CALLBACK WndProc( HWND hWnd,
|
|||
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
||||
|
||||
ptLast = ptCursor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_SIZE: // Resizing The Screen
|
||||
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // Resize To The New Window Size
|
||||
// Resize To The New Window Size
|
||||
ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
|
||||
break;
|
||||
|
||||
default:
|
||||
return (DefWindowProc(hWnd, message, wParam, lParam)); // Pass Windows Messages
|
||||
}
|
||||
return (0);
|
||||
// Pass Windows Messages
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
void InitSaver(HWND hwndParent)
|
||||
return 0;
|
||||
}
|
||||
|
||||
VOID InitSaver(HWND hwndParent)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
|
||||
ZeroMemory(&wc, sizeof(wc));
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
|
@ -297,6 +393,7 @@ void InitSaver(HWND hwndParent)
|
|||
if (hwndParent != 0)
|
||||
{
|
||||
RECT rect;
|
||||
|
||||
GetClientRect(hwndParent, &rect);
|
||||
CreateWindow(APPNAME, APPNAME,
|
||||
WS_VISIBLE | WS_CHILD,
|
||||
|
@ -306,7 +403,9 @@ void InitSaver(HWND hwndParent)
|
|||
hwndParent, 0,
|
||||
hInstance, NULL);
|
||||
fullscreen = FALSE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
HWND hwnd;
|
||||
hwnd = CreateWindow(APPNAME, APPNAME,
|
||||
WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST,
|
||||
|
@ -335,8 +434,9 @@ VOID ParseCommandLine(LPTSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
|
|||
if (ch == _T('-') || ch == _T('/'))
|
||||
ch = *szCmdLine++;
|
||||
|
||||
//convert to lower case
|
||||
if (ch >= _T('A') && ch <= _T('Z'))
|
||||
ch += _T('a') - _T('A'); //convert to lower case
|
||||
ch += _T('a') - _T('A');
|
||||
|
||||
*chOption = ch;
|
||||
ch = *szCmdLine++;
|
||||
|
@ -347,14 +447,17 @@ VOID ParseCommandLine(LPTSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
|
|||
while (ch == _T(' ') || ch == _T('\t'))
|
||||
ch = *szCmdLine++;
|
||||
|
||||
if(isdigit(ch))
|
||||
if (_istdigit(ch))
|
||||
{
|
||||
unsigned int i = _ttoi(szCmdLine - 1);
|
||||
*hwndParent = (HWND)i;
|
||||
}
|
||||
else
|
||||
{
|
||||
*hwndParent = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Dialogbox procedure for Configuration window
|
||||
|
@ -366,6 +469,7 @@ BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
case WM_INITDIALOG:
|
||||
SetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text);
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
|
@ -374,14 +478,17 @@ BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
SaveSettings();
|
||||
EndDialog(hwnd, IDOK);
|
||||
break;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hwnd, IDCANCEL);
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
case WM_CLOSE:
|
||||
EndDialog(hwnd, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -389,15 +496,16 @@ BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void Configure(void)
|
||||
VOID Configure(VOID)
|
||||
{
|
||||
DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL , (DLGPROC)ConfigDlgProc);
|
||||
}
|
||||
|
||||
int CALLBACK _tWinMain (HINSTANCE hInst,
|
||||
INT CALLBACK
|
||||
_tWinMain(HINSTANCE hInst,
|
||||
HINSTANCE hPrev,
|
||||
LPTSTR lpCmdLine,
|
||||
int iCmdShow)
|
||||
INT iCmdShow)
|
||||
{
|
||||
HWND hwndParent = 0;
|
||||
UCHAR chOption;
|
||||
|
@ -411,15 +519,15 @@ int CALLBACK _tWinMain (HINSTANCE hInst,
|
|||
|
||||
switch (chOption)
|
||||
{
|
||||
case 's':
|
||||
case _T('s'):
|
||||
InitSaver(0);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case _T('p'):
|
||||
InitSaver(hwndParent);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
case _T('c'):
|
||||
default:
|
||||
Configure();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue