ReactOS 0.4.15-dev-7934-g1dc8d80
cylfrac.c
Go to the documentation of this file.
1/*
2 * Copyright 2003 J Brown
3 * Copyright 2006 Andrey Korotaev <unC0Rr@inbox.ru>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
19
20#include <windows.h>
21#include <GL/gl.h>
22#include <GL/glu.h>
23#include <tchar.h>
24#include <scrnsave.h>
25#include "resource.h"
26
27#define APPNAME _T("Cylfrac")
28#define wfactor 0.9
29#define rotfactor 1.5
30#define FPS 100
31#define timerdelay 1000/FPS
32
38
40int cylquality = 8;
41
43
45
46float angle = 0;
47float colorh = 0.0;
48float rval, gval, bval;
49
51
52float _RGB(float H, float M1, float M2)
53{
54 if(H < 0.0) H += 360.0;
55 else if(H > 360.0) H -= 360.0;
56 if(H < 60) return M1 + (M2 - M1) * H / 60.0;
57 if((H >= 60 )&&(H < 180)) return M2;
58 if((H >= 180)&&(H < 240)) return M1 + (M2 - M1)*(240 - H) / 60.0;
59 return M1;
60}
61
62void HLStoRGB(float H, float L, float S,
63 float* R, float* G, float* B)
64{
65 float M1, M2;
66 if(S <= 0.5) M2 = S * (1 + L);
67 else M2 = S * (1 - L) + L;
68 M1 = 2 * S - M2;
69 if (L == 0.0)
70 {
71 *R = S;
72 *G = S;
73 *B = S;
74 } else {
75 *R = _RGB(H + 120.0, M1, M2);
76 *G = _RGB(H , M1, M2);
77 *B = _RGB(H - 120.0, M1, M2);
78 }
79}
80
81void DrawCylinder(int n, float rota, float width)
82{
85 glRotatef(rota, 0.0, 1.0, 0.0);
87 glTranslatef(0.0, 0.0, -n * 0.5);
89 if(n > 1)
90 {
91 float r = rota * rotfactor;
92 glRotatef(90.0, 1.0, 0.0, 0.0);
93 DrawCylinder(n - 1, r, width * wfactor);
94 glTranslatef(0.0, n, 0.0);
95 DrawCylinder(n - 1, -r, width * wfactor);
96 }
98}
99
100void DrawScene(HWND hwnd, HDC dc, int ticks)
101{
102 PAINTSTRUCT ps;
103 dc = BeginPaint(hwnd, &ps);
105 glRotatef(ticks * 0.01, 0.0, 1.0, -0.5);
106 angle += ticks * 0.01;
107 colorh += ticks * 0.003;
108 if (colorh > 360.0) colorh -= 360.0;
109 HLStoRGB(colorh, 1.0f, 0.7f, &rval, &gval, &bval);
110 DrawCylinder(lvls, angle, 0.2f);
112 EndPaint(hwnd, &ps);
113}
114
115void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
116{
117 InvalidateRect((HWND)dwUser, NULL, 0);
118}
119
121{
122 int npf;
124
125 ZeroMemory(&pfd, sizeof(pfd));
126 pfd.nSize = sizeof(pfd);
127 pfd.nVersion = 1;
129
130 npf = ChoosePixelFormat(dc, &pfd);
131 if(npf != 0)
132 SetPixelFormat(dc, npf, &pfd);
133}
134
136{
137 GLfloat lightpos[4] = {2.0f, 2.0f, -2.0f, 0.7f};
138 GLfloat ca = 1.0;
139 dc = GetDC(hwnd);
146 glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat *)&lightpos);
150}
151
153{
154 switch(msg) {
155 case WM_CREATE:
156 {
158 InitGL(hwnd);
161 }
162 break;
163 case WM_PAINT:
164 {
165 DWORD ticks = oldticks;
166 POINT currpoint;
168 DrawScene(hwnd, dc, oldticks - ticks);
169 if(fullscreen)
170 {
171 GetCursorPos(&currpoint);
172 if(abs(currpoint.x - initpoint.x) + (abs(currpoint.y - initpoint.y)) > 10)
173 PostMessage(hwnd, WM_CLOSE, 0, 0);
174 }
175 }
176 break;
177 case WM_DESTROY:
178 {
181 wglMakeCurrent(0, 0);
183 ReleaseDC(hwnd, dc);
184 DeleteDC(dc);
185 if (fullscreen)
188 }
189 break;
190 case WM_SIZE:
191 {
192 int width = LOWORD(lParam);
193 int height = HIWORD(lParam);
194 float fscale;
195 glViewport(0, 0, width, height);
198 fscale = 0.8/(float)lvls;
199 glScalef(fscale, fscale, fscale);
200 }
201 break;
202 default:
204 }
205 return 0;
206}
207
209{
210 return FALSE;
211}
212
214{
215 TCHAR szTitle[256];
216 TCHAR szText[256];
217
219 IDS_TITLE,
220 szTitle,
221 256);
222
224 IDS_TEXT,
225 szText,
226 256);
227
228 MessageBox(0,
229 szText,
230 szTitle,
232 return FALSE;
233}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
#define msg(x)
Definition: auth_time.c:54
#define IDS_TITLE
Definition: resource.h:30
HWND hWnd
Definition: settings.c:17
#define IDS_TEXT
Definition: resource.h:3
#define G(r, i, a, b, c, d)
Definition: blake2b-ref.c:117
Definition: ehthrow.cxx:54
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
float colorh
Definition: cylfrac.c:47
HDC dc
Definition: cylfrac.c:34
float rval
Definition: cylfrac.c:48
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: cylfrac.c:152
void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
Definition: cylfrac.c:115
int cylquality
Definition: cylfrac.c:40
void DrawCylinder(int n, float rota, float width)
Definition: cylfrac.c:81
float gval
Definition: cylfrac.c:48
#define wfactor
Definition: cylfrac.c:28
DWORD oldticks
Definition: cylfrac.c:36
HGLRC hrc
Definition: cylfrac.c:35
HINSTANCE hInstance
Definition: cylfrac.c:42
void MyPixelFormat(HDC dc)
Definition: cylfrac.c:120
void HLStoRGB(float H, float L, float S, float *R, float *G, float *B)
Definition: cylfrac.c:62
POINT initpoint
Definition: cylfrac.c:33
DWORD lvls
Definition: cylfrac.c:39
float _RGB(float H, float M1, float M2)
Definition: cylfrac.c:52
float bval
Definition: cylfrac.c:48
BOOL fullscreen
Definition: cylfrac.c:50
void InitGL(HWND hwnd)
Definition: cylfrac.c:135
MMRESULT TimerID
Definition: cylfrac.c:37
GLUquadricObj * cylinder
Definition: cylfrac.c:44
#define timerdelay
Definition: cylfrac.c:31
void DrawScene(HWND hwnd, HDC dc, int ticks)
Definition: cylfrac.c:100
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
Definition: cylfrac.c:213
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: cylfrac.c:208
#define rotfactor
Definition: cylfrac.c:29
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR ca[]
Definition: main.c:455
#define CALLBACK
Definition: compat.h:35
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
MMRESULT WINAPI timeKillEvent(UINT wID)
Definition: time.c:370
MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc, DWORD_PTR dwUser, UINT wFlags)
Definition: time.c:360
#define abs(i)
Definition: fconv.c:206
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
#define GL_POSITION
Definition: gl.h:329
GLAPI void GLAPIENTRY glEnable(GLenum cap)
float GLfloat
Definition: gl.h:161
#define GL_DEPTH_TEST
Definition: gl.h:301
GLAPI void GLAPIENTRY glPushMatrix(void)
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define GL_MODELVIEW
Definition: gl.h:245
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
GLAPI void GLAPIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
#define GL_COLOR_BUFFER_BIT
Definition: gl.h:716
#define GL_COLOR_MATERIAL
Definition: gl.h:340
GLAPI void GLAPIENTRY glPopMatrix(void)
#define GL_LINEAR_ATTENUATION
Definition: gl.h:322
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLAPI void GLAPIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
GLint GLint GLsizei width
Definition: gl.h:1546
#define GL_DEPTH_BUFFER_BIT
Definition: gl.h:710
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
#define GL_LIGHT0
Definition: gl.h:311
#define GL_LIGHTING
Definition: gl.h:310
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
GLdouble n
Definition: glext.h:7729
GLfloat angle
Definition: glext.h:10853
#define gluCylinder
Definition: glu_mangle.h:43
#define gluDeleteQuadric
Definition: glu_mangle.h:37
#define gluNewQuadric
Definition: glu_mangle.h:36
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
UINT MMRESULT
Definition: mmsystem.h:962
#define TIME_PERIODIC
Definition: mmsystem.h:422
static HDC
Definition: imagelist.c:92
#define H
static HMODULE hmodule
Definition: rasapi.c:29
static float(__cdecl *square_half_float)(float x
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
static HGLRC(WINAPI *pwglCreateContextAttribsARB)(HDC hDC
#define LOWORD(l)
Definition: pedump.c:82
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:92
#define S(x)
Definition: test.h:217
#define R(b, x)
Definition: sha2.c:134
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
Definition: movable.cpp:9
Definition: tftpd.h:60
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define HIWORD(l)
Definition: typedefs.h:247
BOOL WINAPI wglDeleteContext(HGLRC hglrc)
Definition: wgl.c:514
HGLRC WINAPI wglCreateContext(HDC hdc)
Definition: wgl.c:383
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
Definition: wgl.c:650
#define ZeroMemory
Definition: winbase.h:1712
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
int WINAPI ChoosePixelFormat(_In_ HDC hdc, _In_ const PIXELFORMATDESCRIPTOR *ppfd)
BOOL WINAPI SetPixelFormat(_In_ HDC, _In_ int, _In_ const PIXELFORMATDESCRIPTOR *)
#define PFD_SUPPORT_OPENGL
Definition: wingdi.h:306
BOOL WINAPI SwapBuffers(HDC)
Definition: wingl.c:187
#define PFD_DRAW_TO_WINDOW
Definition: wingdi.h:303
BOOL WINAPI DeleteDC(_In_ HDC)
#define PFD_DOUBLEBUFFER
Definition: wingdi.h:301
#define WM_PAINT
Definition: winuser.h:1620
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_CLOSE
Definition: winuser.h:1621
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1611
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2670
int WINAPI ShowCursor(_In_ BOOL)
Definition: cursoricon.c:2677
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI GetDC(_In_opt_ HWND)
#define MB_OK
Definition: winuser.h:790
#define MB_ICONWARNING
Definition: winuser.h:786
#define PostMessage
Definition: winuser.h:5832
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
#define WM_DESTROY
Definition: winuser.h:1609
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
char TCHAR
Definition: xmlstorage.h:189