mirror of
https://github.com/reactos/reactos.git
synced 2024-07-17 18:06:11 +00:00
[FORMATTING] Fix indentation and move comments
svn path=/trunk/; revision=31542
This commit is contained in:
parent
68981a6100
commit
4f648ef5d9
|
@ -18,416 +18,524 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <windows.h> // Header File For Windows
|
#include <windows.h>
|
||||||
#include <math.h> // Header File For Windows Math Library
|
#include <math.h>
|
||||||
#include <GL/gl.h> // Header File For The OpenGL32 Library
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h> // Header File For The GLu32 Library
|
#include <GL/glu.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "3dtext.h"
|
#include "3dtext.h"
|
||||||
|
|
||||||
static HGLRC hRC; // Permanent Rendering Context
|
static HGLRC hRC; // Permanent Rendering Context
|
||||||
static HDC hDC; // Private GDI Device Context
|
static HDC hDC; // Private GDI Device Context
|
||||||
|
|
||||||
GLuint base; // Base Display List For The Font Set
|
GLuint base; // Base Display List For The Font Set
|
||||||
GLfloat rot; // Used To Rotate The Text
|
GLfloat rot; // Used To Rotate The Text
|
||||||
|
|
||||||
#define APPNAME _T("3DText")
|
#define APPNAME _T("3DText")
|
||||||
|
|
||||||
HINSTANCE hInstance;
|
HINSTANCE hInstance;
|
||||||
BOOL fullscreen = FALSE;
|
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
|
// Address Buffer For Font Storage
|
||||||
HFONT font; // Windows Font ID
|
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, // Width Of Font
|
||||||
0, // Angle Of Escapement
|
0, // Angle Of Escapement
|
||||||
0, // Orientation Angle
|
0, // Orientation Angle
|
||||||
FW_BOLD, // Font Weight
|
FW_BOLD, // Font Weight
|
||||||
FALSE, // Italic
|
FALSE, // Italic
|
||||||
FALSE, // Underline
|
FALSE, // Underline
|
||||||
FALSE, // Strikeout
|
FALSE, // Strikeout
|
||||||
DEFAULT_CHARSET, // Character Set Identifier
|
DEFAULT_CHARSET, // Character Set Identifier
|
||||||
OUT_TT_PRECIS, // Output Precision
|
OUT_TT_PRECIS, // Output Precision
|
||||||
CLIP_DEFAULT_PRECIS, // Clipping Precision
|
CLIP_DEFAULT_PRECIS, // Clipping Precision
|
||||||
ANTIALIASED_QUALITY, // Output Quality
|
ANTIALIASED_QUALITY, // Output Quality
|
||||||
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
|
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
|
||||||
_T("Tahoma")); // Font Name
|
_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
|
wglUseFontOutlines(hDC, // Select The Current DC
|
||||||
0, // Starting Character
|
0, // Starting Character
|
||||||
255, // Number Of Display Lists To Build
|
255, // Number Of Display Lists To Build
|
||||||
base, // Starting Display Lists
|
base, // Starting Display Lists
|
||||||
0.0f, // Deviation From The True Outlines
|
0.0f, // Deviation From The True Outlines
|
||||||
0.2f, // Font Thickness In The Z Direction
|
0.2f, // Font Thickness In The Z Direction
|
||||||
WGL_FONT_POLYGONS, // Use Polygons, Not Lines
|
WGL_FONT_POLYGONS, // Use Polygons, Not Lines
|
||||||
gmf); // Address Of Buffer To Recieve Data
|
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
|
// If there's no text, do nothing
|
||||||
return; // Do Nothing
|
if (text == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
|
// Pushes The Display List Bits
|
||||||
glListBase(base); // Sets The Base Character to 32
|
glPushAttrib(GL_LIST_BIT);
|
||||||
|
|
||||||
glCallLists(_tcslen(text),
|
// Sets The Base Character to 32
|
||||||
|
glListBase(base);
|
||||||
|
|
||||||
|
// Draws The Display List Text
|
||||||
|
glCallLists(_tcslen(text),
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
GL_UNSIGNED_SHORT
|
GL_UNSIGNED_SHORT,
|
||||||
#else
|
#else
|
||||||
GL_UNSIGNED_BYTE
|
GL_UNSIGNED_BYTE,
|
||||||
#endif
|
#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
|
// Clear The Background Color To Black
|
||||||
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
|
|
||||||
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
|
||||||
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
|
// Enables Clearing Of The Depth Buffer
|
||||||
glLoadIdentity(); // Reset The Projection Matrix
|
glClearDepth(1.0);
|
||||||
|
|
||||||
// Calculate The Aspect Ratio Of The Window
|
// The Type Of Depth Test To Do
|
||||||
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
|
glDepthFunc(GL_LESS);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
// Enables Depth Testing
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
BuildFont(); // Build The Font
|
// Enables Smooth Color Shading
|
||||||
glEnable(GL_LIGHT0); // Enable Default Light (Quick And Dirty)
|
glShadeModel(GL_SMOOTH);
|
||||||
glEnable(GL_LIGHTING); // Enable Lighting
|
|
||||||
glEnable(GL_COLOR_MATERIAL); // Enable Coloring Of Material
|
// 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);
|
||||||
|
|
||||||
|
// Select The Modelview Matrix
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
// 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)
|
// Is Window Too Small (Divide By Zero Error)
|
||||||
Height=1; // If So Make It One Pixel Tall
|
if (Height == 0)
|
||||||
|
{
|
||||||
|
// If So Make It One Pixel Tall
|
||||||
|
Height = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset The Current Viewport And Perspective Transformation
|
// Reset The Current Viewport And Perspective Transformation
|
||||||
glViewport(0, 0, Width, Height);
|
glViewport(0, 0, Width, Height);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
|
// Select The Projection Matrix
|
||||||
glLoadIdentity(); // Reset The Projection Matrix
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
|
||||||
// Calculate The Aspect Ratio Of The Window
|
// Reset The Projection Matrix
|
||||||
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
|
||||||
|
// Calculate The Aspect Ratio Of The Window
|
||||||
|
gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);
|
||||||
|
|
||||||
|
// 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
|
// Clear The Screen And The Depth Buffer
|
||||||
glLoadIdentity(); // Reset The View
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
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
|
// Reset The View
|
||||||
glRotatef(rot*1.2f,0.0f,1.0f,0.0f); // Rotate On The Y Axis
|
glLoadIdentity();
|
||||||
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
|
// Move One Unit Into The Screen
|
||||||
// Pulsing Colors Based On The Rotation
|
glTranslatef(0.0f, 0.0f, -10.0f);
|
||||||
glColor3f(
|
|
||||||
(1.0f*(cos(rot/20.0f))),
|
// Rotate On The X Axis
|
||||||
(1.0f*(sin(rot/25.0f))),
|
glRotatef(rot, 1.0f, 0.0f, 0.0f);
|
||||||
(1.0f-0.5f*(cos(rot/17.0f))));
|
|
||||||
glPrint(m_Text); // Print GL Text To The Screen
|
// Rotate On The Y Axis
|
||||||
glColor3f(0.0f,0.0f,1.0f); // Make The Text Blue
|
glRotatef(rot * 1.2f, 0.0f, 1.0f, 0.0f);
|
||||||
rot+=0.1f; // Increase The Rotation Variable
|
|
||||||
|
// 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))),
|
||||||
|
(1.0f * (sin(rot / 25.0f))),
|
||||||
|
(1.0f - 0.5f * (cos(rot / 17.0f))));
|
||||||
|
|
||||||
|
// 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
|
||||||
UINT message,
|
WndProc(HWND hWnd,
|
||||||
WPARAM wParam,
|
UINT message,
|
||||||
LPARAM lParam)
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
static POINT ptLast;
|
static POINT ptLast;
|
||||||
static POINT ptCursor;
|
static POINT ptCursor;
|
||||||
static BOOL fFirstTime = TRUE;
|
static BOOL fFirstTime = TRUE;
|
||||||
RECT Screen; // Used Later On To Get The Size Of The Window
|
RECT Screen; // Used Later On To Get The Size Of The Window
|
||||||
GLuint PixelFormat; // Pixel Format Storage
|
GLuint PixelFormat; // Pixel Format Storage
|
||||||
static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor
|
static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor
|
||||||
{
|
{
|
||||||
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
||||||
1, // Version Number (?)
|
1, // Version Number (?)
|
||||||
PFD_DRAW_TO_WINDOW | // Format Must Support Window
|
PFD_DRAW_TO_WINDOW | // Format Must Support Window
|
||||||
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
|
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
|
||||||
PFD_DOUBLEBUFFER, // Must Support Double Buffering
|
PFD_DOUBLEBUFFER, // Must Support Double Buffering
|
||||||
PFD_TYPE_RGBA, // Request An RGBA Format
|
PFD_TYPE_RGBA, // Request An RGBA Format
|
||||||
16, // Select A 16Bit Color Depth
|
16, // Select A 16Bit Color Depth
|
||||||
0, 0, 0, 0, 0, 0, // Color Bits Ignored (?)
|
0, 0, 0, 0, 0, 0, // Color Bits Ignored (?)
|
||||||
0, // No Alpha Buffer
|
0, // No Alpha Buffer
|
||||||
0, // Shift Bit Ignored (?)
|
0, // Shift Bit Ignored (?)
|
||||||
0, // No Accumulation Buffer
|
0, // No Accumulation Buffer
|
||||||
0, 0, 0, 0, // Accumulation Bits Ignored (?)
|
0, 0, 0, 0, // Accumulation Bits Ignored (?)
|
||||||
16, // 16Bit Z-Buffer (Depth Buffer)
|
16, // 16Bit Z-Buffer (Depth Buffer)
|
||||||
0, // No Stencil Buffer
|
0, // No Stencil Buffer
|
||||||
0, // No Auxiliary Buffer (?)
|
0, // No Auxiliary Buffer (?)
|
||||||
PFD_MAIN_PLANE, // Main Drawing Layer
|
PFD_MAIN_PLANE, // Main Drawing Layer
|
||||||
0, // Reserved (?)
|
0, // Reserved (?)
|
||||||
0, 0, 0 // Layer Masks Ignored (?)
|
0, 0, 0 // Layer Masks Ignored (?)
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (message) // Tells Windows We Want To Check The Message
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_CREATE: // Window Creation
|
case WM_CREATE:
|
||||||
hDC = GetDC(hWnd); // Gets A Device Context For The Window
|
// Gets A Device Context For The Window
|
||||||
PixelFormat = ChoosePixelFormat(hDC, &pfd); // Finds The Closest Match To The Pixel Format We Set Above
|
hDC = GetDC(hWnd);
|
||||||
|
|
||||||
if (!PixelFormat) // No Matching Pixel Format?
|
// Finds The Closest Match To The Pixel Format We Set Above
|
||||||
{
|
PixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Can We Set The Pixel Mode?
|
// No Matching Pixel Format?
|
||||||
{
|
if (!PixelFormat)
|
||||||
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
|
MessageBox(0, _TEXT("Can't Find A Suitable PixelFormat."), _TEXT("Error"),MB_OK | MB_ICONERROR);
|
||||||
break; // Prevents The Rest Of The Code From Running
|
|
||||||
}
|
|
||||||
|
|
||||||
hRC = wglCreateContext(hDC); // Grab A Rendering Context
|
// This Sends A 'Message' Telling The Program To Quit
|
||||||
if(!hRC) // Did We Get One?
|
PostQuitMessage(0);
|
||||||
{
|
break;
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!wglMakeCurrent(hDC, hRC)) // Can We Make The RC Active?
|
// Can We Set The Pixel Mode?
|
||||||
{
|
if (!SetPixelFormat(hDC, PixelFormat, &pfd))
|
||||||
MessageBox(0,_TEXT("Can't Activate GLRC."),_TEXT("Error"),MB_OK|MB_ICONERROR);
|
{
|
||||||
PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit
|
MessageBox(0, _TEXT("Can't Set The PixelFormat."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||||
break; // Prevents The Rest Of The Code From Running
|
|
||||||
}
|
|
||||||
|
|
||||||
GetClientRect(hWnd, &Screen); // Grab Screen Info For The Current Window
|
// This Sends A 'Message' Telling The Program To Quit
|
||||||
InitGL(Screen.right, Screen.bottom); // Initialize The GL Screen Using Screen Info
|
PostQuitMessage(0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_DESTROY: // Windows Being Destroyed
|
// Grab A Rendering Context
|
||||||
case WM_CLOSE: // Windows Being Closed
|
hRC = wglCreateContext(hDC);
|
||||||
{
|
|
||||||
ChangeDisplaySettings(NULL, 0); // Disable Fullscreen Mode
|
|
||||||
KillFont(); // Deletes The Font Display List
|
|
||||||
|
|
||||||
wglMakeCurrent(hDC,NULL); // Make The DC Current
|
// Did We Get One?
|
||||||
wglDeleteContext(hRC); // Kill The RC
|
if (!hRC)
|
||||||
ReleaseDC(hWnd,hDC); // Free The DC
|
{
|
||||||
|
MessageBox(0, _TEXT("Can't Create A GL Rendering Context."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||||
|
|
||||||
PostQuitMessage(0); // Quit The Program
|
// This Sends A 'Message' Telling The Program To Quit
|
||||||
}
|
PostQuitMessage(0);
|
||||||
break;
|
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:
|
|
||||||
case WM_RBUTTONUP:
|
|
||||||
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;
|
|
||||||
|
|
||||||
if(fFirstTime)
|
// Can We Make The RC Active?
|
||||||
{
|
if (!wglMakeCurrent(hDC, hRC))
|
||||||
GetCursorPos(&ptLast);
|
{
|
||||||
fFirstTime = FALSE;
|
MessageBox(0, _TEXT("Can't Activate GLRC."), _TEXT("Error"), MB_OK | MB_ICONERROR);
|
||||||
}
|
|
||||||
|
|
||||||
GetCursorPos(&ptCursor);
|
// This Sends A 'Message' Telling The Program To Quit
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// if the mouse has moved more than 3 pixels then exit
|
// Grab Screen Info For The Current Window
|
||||||
if(abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3)
|
GetClientRect(hWnd, &Screen);
|
||||||
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
|
||||||
|
|
||||||
ptLast = ptCursor;
|
// Initialize The GL Screen Using Screen Info
|
||||||
|
InitGL(Screen.right, Screen.bottom);
|
||||||
|
break;
|
||||||
|
|
||||||
return 0;
|
case WM_DESTROY:
|
||||||
}
|
case WM_CLOSE:
|
||||||
case WM_SIZE: // Resizing The Screen
|
// Disable Fullscreen Mode
|
||||||
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // Resize To The New Window Size
|
ChangeDisplaySettings(NULL, 0);
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
// Deletes The Font Display List
|
||||||
return (DefWindowProc(hWnd, message, wParam, lParam)); // Pass Windows Messages
|
KillFont();
|
||||||
}
|
|
||||||
return (0);
|
// 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:
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (fFirstTime)
|
||||||
|
{
|
||||||
|
GetCursorPos(&ptLast);
|
||||||
|
fFirstTime = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCursorPos(&ptCursor);
|
||||||
|
|
||||||
|
// if the mouse has moved more than 3 pixels then exit
|
||||||
|
if (abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3)
|
||||||
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
||||||
|
|
||||||
|
ptLast = ptCursor;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_SIZE: // Resizing The Screen
|
||||||
|
// Resize To The New Window Size
|
||||||
|
ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Pass Windows Messages
|
||||||
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitSaver(HWND hwndParent)
|
VOID InitSaver(HWND hwndParent)
|
||||||
{
|
{
|
||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
ZeroMemory(&wc, sizeof(wc));
|
|
||||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
||||||
wc.lpfnWndProc = WndProc;
|
|
||||||
wc.lpszClassName = APPNAME;
|
|
||||||
RegisterClass(&wc);
|
|
||||||
|
|
||||||
if (hwndParent != 0)
|
ZeroMemory(&wc, sizeof(wc));
|
||||||
{
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
RECT rect;
|
wc.lpfnWndProc = WndProc;
|
||||||
GetClientRect(hwndParent, &rect);
|
wc.lpszClassName = APPNAME;
|
||||||
CreateWindow(APPNAME, APPNAME,
|
RegisterClass(&wc);
|
||||||
WS_VISIBLE | WS_CHILD,
|
|
||||||
0, 0,
|
if (hwndParent != 0)
|
||||||
rect.right,
|
{
|
||||||
rect.bottom,
|
RECT rect;
|
||||||
hwndParent, 0,
|
|
||||||
hInstance, NULL);
|
GetClientRect(hwndParent, &rect);
|
||||||
fullscreen = FALSE;
|
CreateWindow(APPNAME, APPNAME,
|
||||||
} else {
|
WS_VISIBLE | WS_CHILD,
|
||||||
HWND hwnd;
|
0, 0,
|
||||||
hwnd = CreateWindow(APPNAME, APPNAME,
|
rect.right,
|
||||||
WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST,
|
rect.bottom,
|
||||||
0, 0,
|
hwndParent, 0,
|
||||||
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
|
hInstance, NULL);
|
||||||
HWND_DESKTOP, 0,
|
fullscreen = FALSE;
|
||||||
hInstance, NULL);
|
}
|
||||||
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
|
else
|
||||||
ShowCursor(FALSE);
|
{
|
||||||
fullscreen = TRUE;
|
HWND hwnd;
|
||||||
}
|
hwnd = CreateWindow(APPNAME, APPNAME,
|
||||||
|
WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST,
|
||||||
|
0, 0,
|
||||||
|
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
|
||||||
|
HWND_DESKTOP, 0,
|
||||||
|
hInstance, NULL);
|
||||||
|
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
|
||||||
|
ShowCursor(FALSE);
|
||||||
|
fullscreen = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Look for any options Windows has passed to us:
|
// Look for any options Windows has passed to us:
|
||||||
//
|
//
|
||||||
// -a <hwnd> (set password)
|
// -a <hwnd> (set password)
|
||||||
// -s (screensave)
|
// -s (screensave)
|
||||||
// -p <hwnd> (preview)
|
// -p <hwnd> (preview)
|
||||||
// -c <hwnd> (configure)
|
// -c <hwnd> (configure)
|
||||||
//
|
//
|
||||||
VOID ParseCommandLine(LPTSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
|
VOID ParseCommandLine(LPTSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
|
||||||
{
|
{
|
||||||
TCHAR ch = *szCmdLine++;
|
TCHAR ch = *szCmdLine++;
|
||||||
|
|
||||||
if(ch == _T('-') || ch == _T('/'))
|
if (ch == _T('-') || ch == _T('/'))
|
||||||
ch = *szCmdLine++;
|
ch = *szCmdLine++;
|
||||||
|
|
||||||
if(ch >= _T('A') && ch <= _T('Z'))
|
//convert to lower case
|
||||||
ch += _T('a') - _T('A'); //convert to lower case
|
if (ch >= _T('A') && ch <= _T('Z'))
|
||||||
|
ch += _T('a') - _T('A');
|
||||||
|
|
||||||
*chOption = ch;
|
*chOption = ch;
|
||||||
ch = *szCmdLine++;
|
ch = *szCmdLine++;
|
||||||
|
|
||||||
if(ch == _T(':'))
|
if (ch == _T(':'))
|
||||||
ch = *szCmdLine++;
|
ch = *szCmdLine++;
|
||||||
|
|
||||||
while(ch == _T(' ') || ch == _T('\t'))
|
while (ch == _T(' ') || ch == _T('\t'))
|
||||||
ch = *szCmdLine++;
|
ch = *szCmdLine++;
|
||||||
|
|
||||||
if(isdigit(ch))
|
if (_istdigit(ch))
|
||||||
{
|
{
|
||||||
unsigned int i = _ttoi(szCmdLine - 1);
|
unsigned int i = _ttoi(szCmdLine - 1);
|
||||||
*hwndParent = (HWND)i;
|
*hwndParent = (HWND)i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*hwndParent = NULL;
|
{
|
||||||
|
*hwndParent = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Dialogbox procedure for Configuration window
|
// Dialogbox procedure for Configuration window
|
||||||
//
|
//
|
||||||
BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch(uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
SetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text);
|
SetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch(LOWORD(wParam))
|
switch (LOWORD(wParam))
|
||||||
{
|
{
|
||||||
case IDOK:
|
case IDOK:
|
||||||
GetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text, MAX_PATH);
|
GetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text, MAX_PATH);
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
EndDialog(hwnd, IDOK);
|
EndDialog(hwnd, IDOK);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDCANCEL:
|
case IDCANCEL:
|
||||||
EndDialog(hwnd, IDCANCEL);
|
EndDialog(hwnd, IDCANCEL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
case WM_CLOSE:
|
|
||||||
EndDialog(hwnd, 0);
|
case WM_CLOSE:
|
||||||
break;
|
EndDialog(hwnd, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configure(void)
|
VOID Configure(VOID)
|
||||||
{
|
{
|
||||||
DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL , (DLGPROC)ConfigDlgProc);
|
DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL , (DLGPROC)ConfigDlgProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK _tWinMain (HINSTANCE hInst,
|
INT CALLBACK
|
||||||
HINSTANCE hPrev,
|
_tWinMain(HINSTANCE hInst,
|
||||||
LPTSTR lpCmdLine,
|
HINSTANCE hPrev,
|
||||||
int iCmdShow)
|
LPTSTR lpCmdLine,
|
||||||
|
INT iCmdShow)
|
||||||
{
|
{
|
||||||
HWND hwndParent = 0;
|
HWND hwndParent = 0;
|
||||||
UCHAR chOption;
|
UCHAR chOption;
|
||||||
MSG Message;
|
MSG Message;
|
||||||
|
|
||||||
hInstance = hInst;
|
hInstance = hInst;
|
||||||
|
|
||||||
ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
|
ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
|
||||||
|
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
|
|
||||||
switch(chOption)
|
switch (chOption)
|
||||||
{
|
{
|
||||||
case 's':
|
case _T('s'):
|
||||||
InitSaver(0);
|
InitSaver(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case _T('p'):
|
||||||
InitSaver(hwndParent);
|
InitSaver(hwndParent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case _T('c'):
|
||||||
default:
|
default:
|
||||||
Configure();
|
Configure();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (GetMessage(&Message, 0, 0, 0))
|
while (GetMessage(&Message, 0, 0, 0))
|
||||||
DispatchMessage(&Message);
|
DispatchMessage(&Message);
|
||||||
|
|
||||||
return Message.wParam;
|
return Message.wParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue