Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen3dtext.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2000 Jeff Molofee http://nehe.gamedev.net/ (Original code) 00003 * Copyright 2006 Eric Kohl 00004 * Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net) - minor modifications , converted to screensaver 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00019 */ 00020 00021 #include "3dtext.h" 00022 00023 static HGLRC hRC; // Permanent Rendering Context 00024 static HDC hDC; // Private GDI Device Context 00025 00026 GLuint base; // Base Display List For The Font Set 00027 GLfloat rot; // Used To Rotate The Text 00028 GLfloat extentX = 0.0f; 00029 GLfloat extentY = 0.0f; 00030 00031 #define APPNAME _T("3DText") 00032 00033 HINSTANCE hInstance; 00034 BOOL fullscreen = FALSE; 00035 00036 // Build Our Bitmap Font 00037 GLvoid BuildFont(GLvoid) 00038 { 00039 // Address Buffer For Font Storage 00040 GLYPHMETRICSFLOAT gmf[256]; 00041 // Windows Font Handle 00042 HFONT font; 00043 size_t i; 00044 TCHAR c; 00045 GLfloat cellOriginX = 0.0f; 00046 GLfloat stringOriginX; 00047 GLfloat stringExtentX = 0.0f; 00048 GLfloat stringExtentY = 0.0f; 00049 00050 // Storage For 256 Characters 00051 base = glGenLists(256); 00052 00053 font = CreateFont(-12, 00054 0, // Width Of Font 00055 0, // Angle Of Escapement 00056 0, // Orientation Angle 00057 FW_BOLD, // Font Weight 00058 FALSE, // Italic 00059 FALSE, // Underline 00060 FALSE, // Strikeout 00061 DEFAULT_CHARSET, // Character Set Identifier 00062 OUT_TT_PRECIS, // Output Precision 00063 CLIP_DEFAULT_PRECIS, // Clipping Precision 00064 ANTIALIASED_QUALITY, // Output Quality 00065 FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch 00066 _T("Tahoma")); // Font Name 00067 00068 // Selects The Font We Created 00069 SelectObject(hDC, font); 00070 00071 wglUseFontOutlines(hDC, // Select The Current DC 00072 0, // Starting Character 00073 255, // Number Of Display Lists To Build 00074 base, // Starting Display Lists 00075 0.0f, // Deviation From The True Outlines 00076 0.2f, // Font Thickness In The Z Direction 00077 WGL_FONT_POLYGONS, // Use Polygons, Not Lines 00078 gmf); // Address Of Buffer To Recieve Data 00079 00080 // Calculate the string extent 00081 for (i = 0; i < _tcslen(m_Text); i++) 00082 { 00083 c = m_Text[i]; 00084 00085 stringOriginX = cellOriginX + gmf[c].gmfptGlyphOrigin.x; 00086 00087 stringExtentX = stringOriginX + gmf[c].gmfBlackBoxX; 00088 if (gmf[c].gmfBlackBoxY > stringExtentY) 00089 stringExtentY = gmf[c].gmfBlackBoxY; 00090 00091 cellOriginX = cellOriginX + gmf[c].gmfCellIncX; 00092 } 00093 00094 extentX = stringExtentX; 00095 extentY = stringExtentY; 00096 } 00097 00098 // Delete The Font 00099 GLvoid KillFont(GLvoid) 00100 { 00101 // Delete all 256 characters 00102 glDeleteLists(base, 256); 00103 } 00104 00105 // Custom GL "Print" Routine 00106 GLvoid glPrint(LPTSTR text) 00107 { 00108 // If there's no text, do nothing 00109 if (text == NULL) 00110 return; 00111 00112 // Pushes The Display List Bits 00113 glPushAttrib(GL_LIST_BIT); 00114 00115 // Sets The Base Character to 32 00116 glListBase(base); 00117 00118 // Draws The Display List Text 00119 glCallLists(_tcslen(text), 00120 #ifdef UNICODE 00121 GL_UNSIGNED_SHORT, 00122 #else 00123 GL_UNSIGNED_BYTE, 00124 #endif 00125 text); 00126 00127 // Pops The Display List Bits 00128 glPopAttrib(); 00129 } 00130 00131 // Will Be Called Right After The GL Window Is Created 00132 GLvoid InitGL(GLsizei Width, GLsizei Height) 00133 { 00134 // Clear The Background Color To Black 00135 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 00136 00137 // Enables Clearing Of The Depth Buffer 00138 glClearDepth(1.0); 00139 00140 // The Type Of Depth Test To Do 00141 glDepthFunc(GL_LESS); 00142 00143 // Enables Depth Testing 00144 glEnable(GL_DEPTH_TEST); 00145 00146 // Enables Smooth Color Shading 00147 glShadeModel(GL_SMOOTH); 00148 00149 // Select The Projection Matrix 00150 glMatrixMode(GL_PROJECTION); 00151 00152 // Reset The Projection Matrix 00153 glLoadIdentity(); 00154 00155 // Calculate The Aspect Ratio Of The Window 00156 gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f); 00157 00158 // Select The Modelview Matrix 00159 glMatrixMode(GL_MODELVIEW); 00160 00161 // Build The Font 00162 BuildFont(); 00163 00164 // Enable Default Light (Quick And Dirty) 00165 glEnable(GL_LIGHT0); 00166 00167 // Enable Lighting 00168 glEnable(GL_LIGHTING); 00169 00170 // Enable Coloring Of Material 00171 glEnable(GL_COLOR_MATERIAL); 00172 } 00173 00174 // Handles Window Resizing 00175 GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) 00176 { 00177 // Is Window Too Small (Divide By Zero Error) 00178 if (Height == 0) 00179 { 00180 // If So Make It One Pixel Tall 00181 Height = 1; 00182 } 00183 00184 // Reset The Current Viewport And Perspective Transformation 00185 glViewport(0, 0, Width, Height); 00186 00187 // Select The Projection Matrix 00188 glMatrixMode(GL_PROJECTION); 00189 00190 // Reset The Projection Matrix 00191 glLoadIdentity(); 00192 00193 // Calculate The Aspect Ratio Of The Window 00194 gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f); 00195 00196 // Select The Modelview Matrix 00197 glMatrixMode(GL_MODELVIEW); 00198 } 00199 00200 // Handles Rendering 00201 GLvoid DrawGLScene(GLvoid) 00202 { 00203 // Save ticks count of previous frame here 00204 static DWORD dwTicks = 0; 00205 00206 // Clear The Screen And The Depth Buffer 00207 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00208 00209 // Reset The View 00210 glLoadIdentity(); 00211 00212 // Move One Unit Into The Screen 00213 glTranslatef(0.0f, 0.0f, -10.0f); 00214 00215 // Rotate On The X Axis 00216 glRotatef(rot, 1.0f, 0.0f, 0.0f); 00217 00218 // Rotate On The Y Axis 00219 glRotatef(rot * 1.2f, 0.0f, 1.0f, 0.0f); 00220 00221 // Rotate On The Z Axis 00222 glRotatef(rot * 1.4f, 0.0f, 0.0f, 1.0f); 00223 00224 // Move to the Left and Down before drawing 00225 glTranslatef(-(extentX / 2.0f), 00226 -(extentY / 2.0f), 00227 0.0f); 00228 00229 // Pulsing Colors Based On The Rotation 00230 glColor3f((1.0f * (GLfloat)(cos(rot / 20.0f))), 00231 (1.0f * (GLfloat)(sin(rot / 25.0f))), 00232 (1.0f - 0.5f * (GLfloat)(cos(rot / 17.0f)))); 00233 00234 // Print GL Text To The Screen 00235 glPrint(m_Text); 00236 00237 // Make The Text Blue 00238 glColor3f(0.0f, 0.0f, 1.0f); 00239 00240 // Increase The Rotation Variable 00241 if(dwTicks) 00242 rot += (GetTickCount() - dwTicks) / 20.0f; 00243 dwTicks = GetTickCount(); 00244 } 00245 00246 LRESULT CALLBACK 00247 ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 00248 { 00249 RECT Screen; // Used Later On To Get The Size Of The Window 00250 GLuint PixelFormat; // Pixel Format Storage 00251 static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor 00252 { 00253 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 00254 1, // Version Number (?) 00255 PFD_DRAW_TO_WINDOW | // Format Must Support Window 00256 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL 00257 PFD_DOUBLEBUFFER, // Must Support Double Buffering 00258 PFD_TYPE_RGBA, // Request An RGBA Format 00259 16, // Select A 16Bit Color Depth 00260 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) 00261 0, // No Alpha Buffer 00262 0, // Shift Bit Ignored (?) 00263 0, // No Accumulation Buffer 00264 0, 0, 0, 0, // Accumulation Bits Ignored (?) 00265 16, // 16Bit Z-Buffer (Depth Buffer) 00266 0, // No Stencil Buffer 00267 0, // No Auxiliary Buffer (?) 00268 PFD_MAIN_PLANE, // Main Drawing Layer 00269 0, // Reserved (?) 00270 0, 0, 0 // Layer Masks Ignored (?) 00271 }; 00272 00273 switch (message) 00274 { 00275 case WM_CREATE: 00276 LoadSettings(); 00277 00278 // Gets A Device Context For The Window 00279 hDC = GetDC(hWnd); 00280 00281 // Finds The Closest Match To The Pixel Format We Set Above 00282 PixelFormat = ChoosePixelFormat(hDC, &pfd); 00283 00284 // No Matching Pixel Format? 00285 if (!PixelFormat) 00286 { 00287 MessageBox(0, _TEXT("Can't Find A Suitable PixelFormat."), _TEXT("Error"),MB_OK | MB_ICONERROR); 00288 00289 // This Sends A 'Message' Telling The Program To Quit 00290 PostQuitMessage(0); 00291 break; 00292 } 00293 00294 // Can We Set The Pixel Mode? 00295 if (!SetPixelFormat(hDC, PixelFormat, &pfd)) 00296 { 00297 MessageBox(0, _TEXT("Can't Set The PixelFormat."), _TEXT("Error"), MB_OK | MB_ICONERROR); 00298 00299 // This Sends A 'Message' Telling The Program To Quit 00300 PostQuitMessage(0); 00301 break; 00302 } 00303 00304 // Grab A Rendering Context 00305 hRC = wglCreateContext(hDC); 00306 00307 // Did We Get One? 00308 if (!hRC) 00309 { 00310 MessageBox(0, _TEXT("Can't Create A GL Rendering Context."), _TEXT("Error"), MB_OK | MB_ICONERROR); 00311 00312 // This Sends A 'Message' Telling The Program To Quit 00313 PostQuitMessage(0); 00314 break; 00315 } 00316 00317 // Can We Make The RC Active? 00318 if (!wglMakeCurrent(hDC, hRC)) 00319 { 00320 MessageBox(0, _TEXT("Can't Activate GLRC."), _TEXT("Error"), MB_OK | MB_ICONERROR); 00321 00322 // This Sends A 'Message' Telling The Program To Quit 00323 PostQuitMessage(0); 00324 break; 00325 } 00326 00327 // Grab Screen Info For The Current Window 00328 GetClientRect(hWnd, &Screen); 00329 00330 // Initialize The GL Screen Using Screen Info 00331 InitGL(Screen.right, Screen.bottom); 00332 break; 00333 00334 case WM_DESTROY: 00335 // Disable Fullscreen Mode 00336 ChangeDisplaySettings(NULL, 0); 00337 00338 // Deletes The Font Display List 00339 KillFont(); 00340 00341 // Make The DC Current 00342 wglMakeCurrent(hDC, NULL); 00343 00344 // Kill The RC 00345 wglDeleteContext(hRC); 00346 00347 // Free The DC 00348 ReleaseDC(hWnd, hDC); 00349 break; 00350 00351 case WM_PAINT: 00352 DrawGLScene(); 00353 SwapBuffers(hDC); 00354 break; 00355 00356 case WM_SIZE: // Resizing The Screen 00357 // Resize To The New Window Size 00358 ReSizeGLScene(LOWORD(lParam), HIWORD(lParam)); 00359 break; 00360 00361 default: 00362 // Pass Windows Messages to the default screensaver window procedure 00363 return DefScreenSaverProc(hWnd, message, wParam, lParam); 00364 } 00365 00366 return 0; 00367 } 00368 00369 // 00370 // Dialogbox procedure for Configuration window 00371 // 00372 BOOL CALLBACK ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00373 { 00374 switch (uMsg) 00375 { 00376 case WM_INITDIALOG: 00377 LoadSettings(); 00378 SetDlgItemText(hDlg, IDC_MESSAGE_TEXT, m_Text); 00379 return TRUE; 00380 00381 case WM_COMMAND: 00382 switch (LOWORD(wParam)) 00383 { 00384 case IDOK: 00385 GetDlgItemText(hDlg, IDC_MESSAGE_TEXT, m_Text, MAX_PATH); 00386 SaveSettings(); 00387 00388 /* Fall through */ 00389 00390 case IDCANCEL: 00391 EndDialog(hDlg, IDCANCEL); 00392 break; 00393 } 00394 return FALSE; 00395 00396 case WM_CLOSE: 00397 EndDialog(hDlg, 0); 00398 break; 00399 00400 default: 00401 return FALSE; 00402 } 00403 00404 return TRUE; 00405 } 00406 00407 BOOL WINAPI RegisterDialogClasses(HANDLE hInst) 00408 { 00409 return TRUE; 00410 } Generated on Fri May 25 2012 04:15:49 for ReactOS by
1.7.6.1
|