ReactOS 0.4.15-dev-5672-gf73ac17
cylfrac.c File Reference
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <tchar.h>
#include <scrnsave.h>
#include "resource.h"
Include dependency graph for cylfrac.c:

Go to the source code of this file.

Macros

#define APPNAME   _T("Cylfrac")
 
#define wfactor   0.9
 
#define rotfactor   1.5
 
#define FPS   100
 
#define timerdelay   1000/FPS
 

Functions

float _RGB (float H, float M1, float M2)
 
void HLStoRGB (float H, float L, float S, float *R, float *G, float *B)
 
void DrawCylinder (int n, float rota, float width)
 
void DrawScene (HWND hwnd, HDC dc, int ticks)
 
void CALLBACK TimeProc (UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
 
void MyPixelFormat (HDC dc)
 
void InitGL (HWND hwnd)
 
LRESULT WINAPI ScreenSaverProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
BOOL WINAPI ScreenSaverConfigureDialog (HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
 
BOOL WINAPI RegisterDialogClasses (HANDLE hmodule)
 

Variables

POINT initpoint
 
HDC dc
 
HGLRC hrc
 
DWORD oldticks
 
MMRESULT TimerID
 
DWORD lvls = 7
 
int cylquality = 8
 
HINSTANCE hInstance
 
GLUquadricObjcylinder
 
float angle = 0
 
float colorh = 0.0
 
float rval
 
float gval
 
float bval
 
BOOL fullscreen = FALSE
 

Macro Definition Documentation

◆ APPNAME

#define APPNAME   _T("Cylfrac")

Definition at line 27 of file cylfrac.c.

◆ FPS

#define FPS   100

Definition at line 30 of file cylfrac.c.

◆ rotfactor

#define rotfactor   1.5

Definition at line 29 of file cylfrac.c.

◆ timerdelay

#define timerdelay   1000/FPS

Definition at line 31 of file cylfrac.c.

◆ wfactor

#define wfactor   0.9

Definition at line 28 of file cylfrac.c.

Function Documentation

◆ _RGB()

float _RGB ( float  H,
float  M1,
float  M2 
)

Definition at line 52 of file cylfrac.c.

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}
#define H

Referenced by HLStoRGB().

◆ DrawCylinder()

void DrawCylinder ( int  n,
float  rota,
float  width 
)

Definition at line 81 of file cylfrac.c.

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}
float rval
Definition: cylfrac.c:48
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
float bval
Definition: cylfrac.c:48
GLUquadricObj * cylinder
Definition: cylfrac.c:44
#define rotfactor
Definition: cylfrac.c:29
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glPushMatrix(void)
GLAPI void GLAPIENTRY glPopMatrix(void)
GLAPI void GLAPIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
GLint GLint GLsizei width
Definition: gl.h:1546
GLdouble n
Definition: glext.h:7729
#define gluCylinder
Definition: glu_mangle.h:43

Referenced by DrawCylinder(), and DrawScene().

◆ DrawScene()

void DrawScene ( HWND  hwnd,
HDC  dc,
int  ticks 
)

Definition at line 100 of file cylfrac.c.

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}
float colorh
Definition: cylfrac.c:47
HDC dc
Definition: cylfrac.c:34
void HLStoRGB(float H, float L, float S, float *R, float *G, float *B)
Definition: cylfrac.c:62
DWORD lvls
Definition: cylfrac.c:39
#define GL_COLOR_BUFFER_BIT
Definition: gl.h:716
#define GL_DEPTH_BUFFER_BIT
Definition: gl.h:710
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
GLfloat angle
Definition: glext.h:10853
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
BOOL WINAPI SwapBuffers(HDC)
Definition: wingl.c:187
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)

Referenced by ScreenSaverProc().

◆ HLStoRGB()

void HLStoRGB ( float  H,
float  L,
float  S,
float R,
float G,
float B 
)

Definition at line 62 of file cylfrac.c.

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}
#define G(r, i, a, b, c, d)
Definition: blake2b-ref.c:117
Definition: ehthrow.cxx:54
float _RGB(float H, float M1, float M2)
Definition: cylfrac.c:52
#define L(x)
Definition: ntvdm.h:50
#define S(x)
Definition: test.h:217
#define R(b, x)
Definition: sha2.c:134
Definition: movable.cpp:9

Referenced by DrawScene().

◆ InitGL()

void InitGL ( HWND  hwnd)

Definition at line 135 of file cylfrac.c.

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}
HGLRC hrc
Definition: cylfrac.c:35
void MyPixelFormat(HDC dc)
Definition: cylfrac.c:120
static const WCHAR ca[]
Definition: main.c:455
#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
#define GL_COLOR_MATERIAL
Definition: gl.h:340
#define GL_LINEAR_ATTENUATION
Definition: gl.h:322
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
#define GL_LIGHT0
Definition: gl.h:311
#define GL_LIGHTING
Definition: gl.h:310
#define gluNewQuadric
Definition: glu_mangle.h:36
HGLRC WINAPI wglCreateContext(HDC hdc)
Definition: wgl.c:383
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
Definition: wgl.c:650
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by ScreenSaverProc().

◆ MyPixelFormat()

void MyPixelFormat ( HDC  dc)

Definition at line 120 of file cylfrac.c.

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}
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
#define ZeroMemory
Definition: winbase.h:1670
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
#define PFD_DRAW_TO_WINDOW
Definition: wingdi.h:303
#define PFD_DOUBLEBUFFER
Definition: wingdi.h:301

Referenced by InitGL().

◆ RegisterDialogClasses()

BOOL WINAPI RegisterDialogClasses ( HANDLE  hmodule)

Definition at line 213 of file cylfrac.c.

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}
#define IDS_TITLE
Definition: resource.h:30
#define IDS_TEXT
Definition: resource.h:3
#define FALSE
Definition: types.h:117
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
static HMODULE hmodule
Definition: rasapi.c:29
#define MB_OK
Definition: winuser.h:784
#define MB_ICONWARNING
Definition: winuser.h:780
#define LoadString
Definition: winuser.h:5809
#define MessageBox
Definition: winuser.h:5812
char TCHAR
Definition: xmlstorage.h:189

◆ ScreenSaverConfigureDialog()

BOOL WINAPI ScreenSaverConfigureDialog ( HWND  hWnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)

Definition at line 208 of file cylfrac.c.

209{
210 return FALSE;
211}

◆ ScreenSaverProc()

LRESULT WINAPI ScreenSaverProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 152 of file cylfrac.c.

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}
#define msg(x)
Definition: auth_time.c:54
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
Definition: cylfrac.c:115
DWORD oldticks
Definition: cylfrac.c:36
POINT initpoint
Definition: cylfrac.c:33
BOOL fullscreen
Definition: cylfrac.c:50
void InitGL(HWND hwnd)
Definition: cylfrac.c:135
MMRESULT TimerID
Definition: cylfrac.c:37
#define timerdelay
Definition: cylfrac.c:31
void DrawScene(HWND hwnd, HDC dc, int ticks)
Definition: cylfrac.c:100
#define TRUE
Definition: types.h:120
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 long DWORD
Definition: ntddk_ex.h:95
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)
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
#define gluDeleteQuadric
Definition: glu_mangle.h:37
#define TIME_PERIODIC
Definition: mmsystem.h:422
static float(__cdecl *square_half_float)(float x
#define LOWORD(l)
Definition: pedump.c:82
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:95
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
BOOL WINAPI DeleteDC(_In_ HDC)
#define WM_PAINT
Definition: winuser.h:1610
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_CLOSE
Definition: winuser.h:1611
#define WM_CREATE
Definition: winuser.h:1598
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1601
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2639
int WINAPI ShowCursor(_In_ BOOL)
Definition: cursoricon.c:2646
#define PostMessage
Definition: winuser.h:5822
#define WM_DESTROY
Definition: winuser.h:1599

◆ TimeProc()

void CALLBACK TimeProc ( UINT  uID,
UINT  uMsg,
DWORD_PTR  dwUser,
DWORD_PTR  dw1,
DWORD_PTR  dw2 
)

Definition at line 115 of file cylfrac.c.

116{
117 InvalidateRect((HWND)dwUser, NULL, 0);
118}
#define NULL
Definition: types.h:112
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)

Referenced by ScreenSaverProc().

Variable Documentation

◆ angle

float angle = 0

Definition at line 46 of file cylfrac.c.

◆ bval

◆ colorh

float colorh = 0.0

Definition at line 47 of file cylfrac.c.

Referenced by DrawScene().

◆ cylinder

◆ cylquality

int cylquality = 8

Definition at line 40 of file cylfrac.c.

Referenced by DrawCylinder().

◆ dc

HDC dc

Definition at line 34 of file cylfrac.c.

Referenced by DrawScene(), InitGL(), MyPixelFormat(), and ScreenSaverProc().

◆ fullscreen

BOOL fullscreen = FALSE

Definition at line 50 of file cylfrac.c.

Referenced by ScreenSaverProc().

◆ gval

float gval

Definition at line 48 of file cylfrac.c.

Referenced by DrawCylinder(), and DrawScene().

◆ hInstance

HINSTANCE hInstance

Definition at line 42 of file cylfrac.c.

◆ hrc

HGLRC hrc

Definition at line 35 of file cylfrac.c.

Referenced by InitGL(), and ScreenSaverProc().

◆ initpoint

POINT initpoint

Definition at line 33 of file cylfrac.c.

Referenced by ScreenSaverProc().

◆ lvls

DWORD lvls = 7

Definition at line 39 of file cylfrac.c.

Referenced by DrawScene(), and ScreenSaverProc().

◆ oldticks

DWORD oldticks

Definition at line 36 of file cylfrac.c.

Referenced by ScreenSaverProc().

◆ rval

◆ TimerID

MMRESULT TimerID

Definition at line 37 of file cylfrac.c.

Referenced by DDOffscreenBufferTest(), DDPrimarySurfaceTest(), and ScreenSaverProc().