ReactOS  0.4.13-dev-656-g74bcf30
butterflies.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <scrnsave.h>
3 #include <tchar.h>
4 #include <math.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <GL/gl.h>
8 #include <GL/glu.h>
9 #include <GL/glext.h>
10 #include "resource.h"
11 
12 HINSTANCE hInstance; // Holds The Instance Of The Application
13 
14 GLuint texture[3]; //stores texture objects and display list
15 
16 LPCTSTR registryPath = _T("Software\\Microsoft\\ScreenSavers\\Butterflies");
18 
19 
20 struct object // Create A Structure Called Object
21 {
22  int tex; // Integer Used To Select Our Texture
23  float x; // X Position
24  float y; // Y Position
25  float z; // Z Position
26  float yi; // Y Increase Speed (Fall Speed)
27  float spinz; // Z Axis Spin
28  float spinzi; // Z Axis Spin Speed
29  float flap; // Flapping Triangles :)
30  float fi; // Flap Direction (Increase Value)
31 };
32 
33 struct object obj[50];
34 //object obj[50]; // Create 50 Objects Using The Object Structure
35 
37 {
38  dRotate = TRUE;
39 }
40 
41 void ReadRegistry(){
42  LONG result;
43  HKEY skey;
44  DWORD valtype, valsize, val;
45 
46  SetDefaults();
47 
49  if(result != ERROR_SUCCESS)
50  return;
51 
52  valsize=sizeof(val);
53 
54  result = RegQueryValueEx(skey, _T("Rotate"), 0, &valtype, (LPBYTE)&val, &valsize);
55  if(result == ERROR_SUCCESS)
56  dRotate = val;
57  RegCloseKey(skey);
58 }
59 
61  LONG result;
62  HKEY skey;
63  DWORD val, disp;
64 
66  if(result != ERROR_SUCCESS)
67  return;
68 
69  val = dRotate;
70  RegSetValueEx(skey, _T("Rotate"), 0, REG_DWORD, (CONST BYTE*)&val, sizeof(val));
71 
72  RegCloseKey(skey);
73 }
74 
75 void SetObject(int loop) // Sets The Initial Value Of Each Object (Random)
76 {
77  obj[loop].tex=rand()%3; // Texture Can Be One Of 3 Textures
78  obj[loop].x=rand()%34-17.0f; // Random x Value From -17.0f To 17.0f
79  obj[loop].y=18.0f; // Set y Position To 18 (Off Top Of Screen)
80  obj[loop].z=-((rand()%30000/1000.0f)+10.0f); // z Is A Random Value From -10.0f To -40.0f
81  obj[loop].spinzi=(rand()%10000)/5000.0f-1.0f; // spinzi Is A Random Value From -1.0f To 1.0f
82  obj[loop].flap=0.0f; // flap Starts Off At 0.0f;
83  obj[loop].fi=0.05f+(rand()%100)/1000.0f; // fi Is A Random Value From 0.05f To 0.15f
84  obj[loop].yi=0.001f+(rand()%1000)/10000.0f; // yi Is A Random Value From 0.001f To 0.101f
85 }
86 
87 void LoadGLTextures() // Creates Textures From Bitmaps In The Resource File
88 {
89  HBITMAP hBMP; // Handle Of The Bitmap
90  BITMAP BMP; // Bitmap Structure
91  int loop;
92 
93  // The ID Of The 3 Bitmap Images We Want To Load From The Resource File
94  byte Texture[]={ IDB_BUTTERFLY1, IDB_BUTTERFLY2, IDB_BUTTERFLY3 };
95 
96  glGenTextures(sizeof(Texture), &texture[0]); // Generate 3 Textures (sizeof(Texture)=3 ID's)
97  for (loop=0; loop<sizeof(Texture); loop++) // Loop Through All The ID's (Bitmap Images)
98  {
100  if (hBMP) // Does The Bitmap Exist?
101  { // If So...
102  GetObject(hBMP,sizeof(BMP), &BMP); // Get The Object
103  // hBMP: Handle To Graphics Object
104  // sizeof(BMP): Size Of Buffer For Object Information
105  // Buffer For Object Information
106  glPixelStorei(GL_UNPACK_ALIGNMENT,4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
107  glBindTexture(GL_TEXTURE_2D, texture[loop]); // Bind Our Texture
110 
111  // Generate Mipmapped Texture (3 Bytes, Width, Height And Data From The BMP)
112  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
113  }
114  }
115 }
116 
118 {
119  HDC hDC = GetDC(hWnd);
120  HGLRC hRC = 0;
122  int nFormat;
123 
125 
126  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
127  pfd.nVersion = 1;
129  pfd.cColorBits = 24;
130  pfd.cDepthBits = 24;
131 
132  nFormat = ChoosePixelFormat(hDC, &pfd);
133  DescribePixelFormat(hDC, nFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
134  SetPixelFormat(hDC, nFormat, &pfd);
135 
138 
139  ReleaseDC(hWnd, hDC);
140 
141  return hRC;
142 }
143 
145 {
146  int loop;
147 
148  if (height==0) // Prevent A Divide By Zero By
149  {
150  height=1; // Making Height Equal One
151  }
152 
153  glViewport(0,0,width,height); // Reset The Current Viewport
154 
155  glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
156  glLoadIdentity(); // Reset The Projection Matrix
157 
158  // Calculate The Aspect Ratio Of The Window
159  gluPerspective (45.0f, (GLfloat)(width)/(GLfloat)(height),1.0f, 1000.0f);
160 
161  glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
162  glLoadIdentity();
163  // Start Of User Initialization
164  LoadGLTextures(); // Load The Textures From Our Resource File
165 
166  glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
167  glClearDepth (1.0f); // Depth Buffer Setup
168  glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
169  glDisable(GL_DEPTH_TEST); // Disable Depth Testing
170  glShadeModel (GL_SMOOTH); // Select Smooth Shading
171  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
172  glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
173  glBlendFunc(GL_ONE,GL_SRC_ALPHA); // Set Blending Mode (Cheap / Quick)
175 
176 
177  for (loop=0; loop<50; loop++) // Loop To Initialize 50 Objects
178  {
179  SetObject(loop); // Call SetObject To Assign New Random Values
180  }
181 
182 }
183 
184 void Display()
185 {
186  int loop;
187  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
188 
189  for (loop=0; loop<50; loop++) // Loop Of 50 (Draw 50 Objects)
190  {
191  glLoadIdentity (); // Reset The Modelview Matrix
192  glBindTexture(GL_TEXTURE_2D, texture[obj[loop].tex]); // Bind Our Texture
193  glTranslatef(obj[loop].x,obj[loop].y,obj[loop].z); // Position The Object
194  glRotatef(45.0f,1.0f,0.0f,0.0f); // Rotate On The X-Axis
195  if (dRotate)
196  {
197  glRotatef((obj[loop].spinz),0.0f,0.0f,1.0f); // Spin On The Z-Axis
198  }
199  glBegin(GL_TRIANGLES); // Begin Drawing Triangles
200  // First Triangle _____
201  glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // (2)| / (1)
202  glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, obj[loop].flap); // | /
203  glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // (3)|/
204 
205  // Second Triangle
206  glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // /|(1)
207  glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // / |
208  glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, obj[loop].flap); // (2)/____|(3)
209 
210  glEnd(); // Done Drawing Triangles
211 
212  obj[loop].y-=obj[loop].yi; // Move Object Down The Screen
213  obj[loop].spinz+=obj[loop].spinzi; // Increase Z Rotation By spinzi
214  obj[loop].flap+=obj[loop].fi; // Increase flap Value By fi
215 
216  if (obj[loop].y<-18.0f) // Is Object Off The Screen?
217  {
218  SetObject(loop); // If So, Reassign New Values
219  }
220 
221  if ((obj[loop].flap>1.0f) || (obj[loop].flap<-1.0f)) // Time To Change Flap Direction?
222  {
223  obj[loop].fi=-obj[loop].fi; // Change Direction By Making fi = -fi
224  }
225  }
226 
227  Sleep(15); // Create A Short Delay (15 Milliseconds)
228 
229  glFlush ();
230 
231 }
232 
234 
235  switch(msg){
236  case WM_CTLCOLORSTATIC:
237  if(((HWND)lpm == GetDlgItem(hdlg, WEBPAGE1)) || ((HWND)lpm == GetDlgItem(hdlg, WEBPAGE2)))
238  {
239  SetTextColor((HDC)wpm, RGB(0,0,255));
242  }
243  break;
244  case WM_COMMAND:
245  switch(LOWORD(wpm)){
246  case IDOK:
247  EndDialog(hdlg, LOWORD(wpm));
248  break;
249  case WEBPAGE1:
250  ShellExecute(NULL, _T("open"), _T("http://nehe.gamedev.net"), NULL, NULL, SW_SHOWNORMAL);
251  break;
252  case WEBPAGE2:
253  ShellExecute(NULL, _T("open"), _T("http://www.thaputer.com"), NULL, NULL, SW_SHOWNORMAL);
254  break;
255  }
256  }
257  return FALSE;
258 }
259 
262 {
263  static HGLRC hRC;
264  static DWORD timer = 1;
265  HDC hDC;
266  RECT WindowRect;
267  int width;
268  int height;
269 
270  switch (message)
271  {
272  case WM_CREATE:
273  ReadRegistry();
275  GetClientRect (hWnd, &WindowRect);
276  width = WindowRect.right - WindowRect.left;
277  height = WindowRect.bottom - WindowRect.top;
279  SetTimer(hWnd, timer, 5, NULL);
280  break;
281  case WM_TIMER:
282  hDC = GetDC(hWnd);
283  Display();
284  SwapBuffers(hDC);
285  ReleaseDC(hWnd, hDC);
286  break;
287  case WM_DESTROY:
290  break;
291  }
292 
294 }
295 
298 {
299  switch (message)
300  {
301  case WM_INITDIALOG:
302  ReadRegistry();
303  CheckDlgButton(hDlg, ROTATE, dRotate);
304  return TRUE;
305  case WM_COMMAND:
306  switch (LOWORD(wParam))
307  {
308  case IDOK:
310  WriteRegistry();
311  EndDialog(hDlg, TRUE);
312  return TRUE;
313  case IDCANCEL:
314  EndDialog(hDlg, TRUE);
315  break;
316  case IDABOUT:
318  break;
319  }
320  }
321 
322  return FALSE;
323 }
324 
326 {
327  return TRUE;
328 }
329 
static HGLRC hRC
Definition: 3dtext.c:32
#define RegQueryValueEx
Definition: winreg.h:524
INT_PTR CALLBACK AboutProc(HWND hdlg, UINT msg, WPARAM wpm, LPARAM lpm)
Definition: butterflies.c:233
float x
Definition: butterflies.c:23
#define GL_BGR_EXT
Definition: glext.h:3114
#define GL_TRIANGLES
Definition: gl.h:194
#define GL_COLOR_BUFFER_BIT
Definition: gl.h:716
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
static HGLRC(WINAPI *pwglCreateContextAttribsARB)(HDC hDC
disp
Definition: i386-dis.c:3181
#define MAKEINTRESOURCE
Definition: winuser.h:591
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
GLint GLint GLsizei width
Definition: gl.h:1546
#define gluBuild2DMipmaps
Definition: glu_mangle.h:35
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define GL_LEQUAL
Definition: gl.h:296
#define IDOK
Definition: winuser.h:824
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define GL_ONE
Definition: gl.h:375
BOOL WINAPI wglDeleteContext(HGLRC hglrc)
Definition: wgl.c:514
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: butterflies.c:260
#define ERROR_SUCCESS
Definition: deptool.c:10
#define GL_BLEND
Definition: gl.h:371
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
void LoadGLTextures()
Definition: butterflies.c:87
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
HDC WINAPI GetDC(_In_opt_ HWND)
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define KEY_READ
Definition: nt_native.h:1023
#define GL_DEPTH_BUFFER_BIT
Definition: gl.h:710
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1754
LPCTSTR registryPath
Definition: butterflies.c:16
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
GLAPI void GLAPIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
HWND hWnd
Definition: settings.c:17
void InitOpenGL(GLsizei width, GLsizei height)
Definition: butterflies.c:144
LONG top
Definition: windef.h:292
void SetObject(int loop)
Definition: butterflies.c:75
#define ZeroMemory
Definition: winbase.h:1635
#define IDABOUT
Definition: resource.h:5
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
Definition: butterflies.c:325
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
float fi
Definition: butterflies.c:30
UINT_PTR WPARAM
Definition: windef.h:207
#define GL_PERSPECTIVE_CORRECTION_HINT
Definition: gl.h:578
LONG left
Definition: windef.h:291
int32_t INT_PTR
Definition: typedefs.h:62
GLAPI void GLAPIENTRY glGenTextures(GLsizei n, GLuint *textures)
#define GL_SMOOTH
Definition: gl.h:339
LONG right
Definition: windef.h:293
HINSTANCE hInstance
Definition: butterflies.c:12
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
BOOL WINAPI SetPixelFormat(_In_ HDC, _In_ int, _In_ const PIXELFORMATDESCRIPTOR *)
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
Definition: image.c:4224
#define WEBPAGE1
Definition: resource.h:13
GLAPI void GLAPIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
#define GL_UNPACK_ALIGNMENT
Definition: gl.h:632
#define PFD_DOUBLEBUFFER
Definition: wingdi.h:300
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
#define DialogBox
Definition: winuser.h:5659
#define gluPerspective
Definition: glu_mangle.h:28
#define COLOR_3DFACE
Definition: winuser.h:919
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
float yi
Definition: butterflies.c:26
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
int GLsizei
Definition: gl.h:160
#define WEBPAGE2
Definition: resource.h:14
#define ShellExecute
Definition: shellapi.h:689
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
int WINAPI DescribePixelFormat(_In_ HDC hdc, _In_ int iPixelFormat, _In_ UINT nBytes, _Out_writes_bytes_opt_(nBytes) LPPIXELFORMATDESCRIPTOR ppfd)
GLdouble GLdouble z
Definition: glext.h:5874
#define ROTATE
Definition: resource.h:12
smooth NULL
Definition: ftsmooth.c:416
float y
Definition: butterflies.c:24
LONG_PTR LPARAM
Definition: windef.h:208
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
float z
Definition: butterflies.c:25
void WriteRegistry()
Definition: butterflies.c:60
GLAPI void GLAPIENTRY glPixelStorei(GLenum pname, GLint param)
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_DESTROY
Definition: winuser.h:1591
GLuint GLfloat * val
Definition: glext.h:7180
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:649
BOOL WINAPI SwapBuffers(HDC)
Definition: wingl.c:187
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat f
Definition: glext.h:7540
#define _T(x)
Definition: vfdio.h:22
HGLRC InitOGLWindow(HWND hWnd)
Definition: butterflies.c:117
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
GLenum GLuint texture
Definition: glext.h:6295
DWORD COLORREF
Definition: windef.h:285
float flap
Definition: butterflies.c:29
#define WM_TIMER
Definition: winuser.h:1724
BOOL dRotate
Definition: butterflies.c:17
#define RGB(r, g, b)
Definition: wingdi.h:2918
#define WINAPI
Definition: msvc.h:8
int WINAPI ChoosePixelFormat(_In_ HDC hdc, _In_ const PIXELFORMATDESCRIPTOR *ppfd)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GL_LINEAR
Definition: gl.h:421
#define GetObject
Definition: wingdi.h:4446
GLAPI void GLAPIENTRY glHint(GLenum target, GLenum mode)
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
GLAPI void GLAPIENTRY glBegin(GLenum mode)
void ReadRegistry()
Definition: butterflies.c:41
float spinz
Definition: butterflies.c:27
#define GL_PROJECTION
Definition: gl.h:246
#define GL_NICEST
Definition: gl.h:585
GLAPI void GLAPIENTRY glEnable(GLenum cap)
unsigned char BYTE
Definition: mem.h:68
#define IDB_BUTTERFLY2
Definition: resource.h:8
#define WM_COMMAND
Definition: winuser.h:1722
int tex
Definition: butterflies.c:22
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
Definition: wgl.c:650
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:886
static HDC hDC
Definition: 3dtext.c:33
void SetDefaults()
Definition: butterflies.c:36
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegOpenKeyEx
Definition: winreg.h:520
#define SW_SHOWNORMAL
Definition: winuser.h:764
float spinzi
Definition: butterflies.c:28
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int GLuint
Definition: gl.h:159
#define GetModuleHandle
Definition: winbase.h:3641
#define GL_DEPTH_TEST
Definition: gl.h:301
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:648
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
GLAPI void GLAPIENTRY glFlush(void)
Definition: bl.h:1331
#define LR_CREATEDIBSECTION
Definition: winuser.h:1088
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define GL_MODELVIEW
Definition: gl.h:245
unsigned int UINT
Definition: ndis.h:50
GLAPI void GLAPIENTRY glTexCoord2f(GLfloat s, GLfloat t)
#define GL_LINEAR_MIPMAP_LINEAR
Definition: gl.h:670
#define IMAGE_BITMAP
Definition: winuser.h:211
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define GL_TEXTURE_2D
Definition: gl.h:645
#define BST_CHECKED
Definition: winuser.h:197
float GLfloat
Definition: gl.h:161
#define msg(x)
Definition: auth_time.c:54
#define WM_CREATE
Definition: winuser.h:1590
#define IDB_BUTTERFLY1
Definition: resource.h:7
#define IDD_DLG_ABOUT
Definition: resource.h:11
struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR
#define IDB_BUTTERFLY3
Definition: resource.h:9
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:95
GLAPI void GLAPIENTRY glClearDepth(GLclampd depth)
LONG bottom
Definition: windef.h:294
GLAPI void GLAPIENTRY glEnd(void)
#define GL_SRC_ALPHA
Definition: gl.h:378
#define LoadImage
Definition: winuser.h:5713
static HBITMAP
Definition: button.c:44
#define PFD_SUPPORT_OPENGL
Definition: wingdi.h:305
#define IDCANCEL
Definition: winuser.h:825
LONG_PTR LRESULT
Definition: windef.h:209
#define PFD_DRAW_TO_WINDOW
Definition: wingdi.h:302
BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: butterflies.c:296
HBRUSH WINAPI GetSysColorBrush(_In_ int)
GLuint64EXT * result
Definition: glext.h:11304
#define REG_DWORD
Definition: sdbapi.c:596
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
GLAPI void GLAPIENTRY glDepthFunc(GLenum func)
#define CONST
Definition: pedump.c:81
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
HGLRC WINAPI wglCreateContext(HDC hdc)
Definition: wgl.c:383
void Display()
Definition: butterflies.c:184