File: main.cpp

package info (click to toggle)
libpolyclipping 6.4.2-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,844 kB
  • sloc: pascal: 6,282; cpp: 5,906; cs: 5,464; javascript: 2,634; python: 2,148; ruby: 11; makefile: 8
file content (621 lines) | stat: -rw-r--r-- 19,339 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
#include <windows.h>
#include <commctrl.h>
#include <gl/gl.h>
#include <gl/glu.h>
//#include <gl/glut.h>
#include <ctime>
#include <cmath>
#include <sstream>
#include <fstream>
#include <iomanip>
#include "../clipper.hpp"

using namespace std;
using namespace ClipperLib;

enum poly_color_type { pctSubject, pctClip, pctSolution };

//global vars ...
HWND		 hWnd;
HWND     hStatus; 
HDC			 hDC;
HGLRC		 hRC;
ClipType     ct = ctIntersection;
PolyFillType pft = pftEvenOdd;
JoinType jt = jtRound;
bool show_clipping = true;
Paths sub, clp, sol;
int VertCount = 5;
int scale = 10;
double delta = 0.0;

const LPCWSTR helpText = 
L"Clipper Demo tips...\n\n"
L"I - for Intersection operations.\n"
L"U - for Union operations.\n"
L"D - for Difference operations.\n"
L"X - for XOR operations.\n"
L"------------------------------\n"
L"Q - Toggle clipping on/off.\n"
L"------------------------------\n"
L"E - for EvenOdd fills.\n"
L"Z - for NonZero fills.\n"
L"P - for Positive fills.\n"
L"N - for Negative fills.\n"
L"------------------------------\n"
L"nn<ENTER> - number of vertices (3..50).\n"
L"------------------------------\n"
L"UP arrow - Expand Solution.\n"
L"DN arrow - Contract Solution.\n"
L"LT or RT arrow - Reset Solution.\n"
L"------------------------------\n"
L"M - Miter OffsetPolygons.\n"
L"S - Square OffsetPolygons.\n"
L"R - Round OffsetPolygons.\n"
L"------------------------------\n"
L"SPACE, ENTER or click to refresh.\n"
L"F1 - to see this help dialog again.\n"
L"Esc - to quit.\n";

typedef std::vector< GLdouble* > Vectors;
Vectors vectors;

//------------------------------------------------------------------------------
// heap memory management for GLUtesselator ...
//------------------------------------------------------------------------------

GLdouble* NewVector(GLdouble x, GLdouble y)
{
  GLdouble *vert = new GLdouble[3];
  vert[0] = x;
  vert[1] = y;
  vert[2] = 0;
  vectors.push_back(vert);
  return vert;
}
//------------------------------------------------------------------------------

void ClearVectors()
{
  for (Vectors::size_type i = 0; i < vectors.size(); ++i)
    delete[] vectors[i];
  vectors.clear(); 
}

//------------------------------------------------------------------------------
// GLUtesselator callback functions ...
//------------------------------------------------------------------------------

void CALLBACK BeginCallback(GLenum type)   
{   
    glBegin(type);   
} 
//------------------------------------------------------------------------------

void CALLBACK EndCallback()   
{   
    glEnd();   
}
//------------------------------------------------------------------------------

void CALLBACK VertexCallback(GLvoid *vertex)   
{   
	glVertex3dv( (const double *)vertex );   
} 
//------------------------------------------------------------------------------

void CALLBACK CombineCallback(GLdouble coords[3], 
  GLdouble*[4], GLfloat[4], GLdouble **dataOut )   
{   
  GLdouble *vert = NewVector(coords[0], coords[1]);
	*dataOut = vert;
}   
//------------------------------------------------------------------------------

wstring str2wstr(const std::string &s) {
	int slength = (int)s.length() + 1;
	int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); 
	wchar_t* buf = new wchar_t[len];
  MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
  std::wstring r(buf);
  delete[] buf;
  return r;
}
//------------------------------------------------------------------------------

void CALLBACK ErrorCallback(GLenum errorCode)   
{   
	std::wstring s = str2wstr( (char *)gluErrorString(errorCode) );
	SetWindowText(hWnd, s.c_str());
}   

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

// Set up pixel format for graphics initialization
void SetupPixelFormat()
{
    PIXELFORMATDESCRIPTOR pfd;
    ZeroMemory( &pfd, sizeof(pfd));
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    int pfIdx = ChoosePixelFormat(hDC, &pfd);
    if (pfIdx != 0) SetPixelFormat(hDC, pfIdx, &pfd);
}
//------------------------------------------------------------------------------

// Initialize OpenGL graphics
void InitGraphics()
{
  hDC = GetDC(hWnd);
  SetupPixelFormat();
  hRC = wglCreateContext(hDC);
  wglMakeCurrent(hDC, hRC);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glTranslatef (0.375, 0.375, 0);
}
//------------------------------------------------------------------------------

void MakeRandomPoly(Path &p, int width, int height, int edgeCount)
{
	p.resize(edgeCount);
	for (int i = 0; i < edgeCount; i++)
	{
		p[i].X = (rand()%(width -20) +10)*scale;
		p[i].Y = (rand()%(height -20) +10)*scale;
	}
}
//------------------------------------------------------------------------------

void ResizeGraphics(int width, int height)
{
  //setup 2D projection with origin at top-left corner ...
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, width, height, 0, 0, 1);
	glViewport(0, 0, width, height);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
//------------------------------------------------------------------------------

void DrawPolygon(Paths &pgs, poly_color_type pct)
{
	switch (pct)
	{
		case pctSubject: glColor4f(0.0f, 0.0f, 1.0f, 0.062f); break;
		case pctClip: glColor4f(1.0f, 1.0f, 0.0f, 0.062f); break;
		default: glColor4f(0.0f, 1.0f, 0.0f, 0.25f);
	}

	GLUtesselator* tess = gluNewTess();
  gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK*)())&BeginCallback);    
  gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK*)())&VertexCallback);    
  gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK*)())&EndCallback);   
  gluTessCallback(tess, GLU_TESS_COMBINE, (void (CALLBACK*)())&CombineCallback);   
  gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK*)())&ErrorCallback);
  gluTessNormal(tess, 0.0, 0.0, 1.0);
	
	switch (pft)
  {
    case pftEvenOdd: 
      gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); 
      break;
    case pftNonZero: 
      gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); 
      break;
    case pftPositive: 
      gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); 
      break;
    default: //case pftNegative
      if (pct == pctSolution)
        gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
      else
        gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NEGATIVE);
  }

	gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); //GL_FALSE
	gluTessBeginPolygon(tess, NULL); 
	for (Paths::size_type i = 0; i < pgs.size(); ++i)
	{
		gluTessBeginContour(tess);
		for (Path::size_type j = 0; j < pgs[i].size(); ++j)
		{
      GLdouble *vert = 
        NewVector((GLdouble)pgs[i][j].X/scale, (GLdouble)pgs[i][j].Y/scale);
			gluTessVertex(tess, vert, vert); 
		}
		gluTessEndContour(tess); 
	}
	gluTessEndPolygon(tess);
  ClearVectors();

	switch (pct)
	{
		case pctSubject: 
      glColor4f(0.0f, 0.6f, 1.0f, 0.5f); 
      break;
		case pctClip: 
      glColor4f(1.0f, 0.6f, 0.0f, 0.5f); 
      break;
		default: 
      glColor4f(0.0f, 0.4f, 0.0f, 1.0f);
	}
	if (pct == pctSolution) glLineWidth(1.0f); else glLineWidth(0.8f);

  gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); 
	gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE);
	for (Paths::size_type i = 0; i < pgs.size(); ++i)
	{
    gluTessBeginPolygon(tess, NULL); 
		gluTessBeginContour(tess);
		for (Path::size_type j = 0; j < pgs[i].size(); ++j)
		{
			GLdouble *vert = 
        NewVector((GLdouble)pgs[i][j].X/scale, (GLdouble)pgs[i][j].Y/scale);
			gluTessVertex(tess, vert, vert); 
		}

    switch (pct)
	  {
		  case pctSubject: 
        glColor4f(0.0f, 0.0f, 0.8f, 0.5f); 
        break;
		  case pctClip: 
        glColor4f(0.6f, 0.0f, 0.0f, 0.5f); 
	  }
		gluTessEndContour(tess);
	  gluTessEndPolygon(tess);
	}

	//final cleanup ...
	gluDeleteTess(tess);
  ClearVectors();
}
//------------------------------------------------------------------------------

void DrawGraphics()
{
	//this can take a few moments ...
	HCURSOR hWaitCursor = LoadCursor(NULL, IDC_WAIT);
	SetCursor(hWaitCursor);
	SetClassLong(hWnd, GCL_HCURSOR, (DWORD)hWaitCursor);

	//fill background with a light off-gray color ...
	glClearColor(1,1,1,1);
	glClear(GL_COLOR_BUFFER_BIT);

  //glRasterPos2f(110, 340);
  //glColor4f(0.0f, 1.0f, 0.0f, 1.0f); 
  //char * text = "Positive Fills";
  //for (int i = 0; i < strlen(text); ++i)
  //  glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, text[i]);
	
  DrawPolygon(sub, pctSubject);
	DrawPolygon(clp, pctClip);
  if (show_clipping)
    DrawPolygon(sol, pctSolution);
  wstringstream ss;
  if (!show_clipping)
    ss << L"Clipper Demo - NO CLIPPING"; 
  else
	  switch (ct)
	  {
		  case ctUnion: 
        ss << L"Clipper Demo - UNION"; 
        break;
		  case ctDifference: 
        ss << L"Clipper Demo - DIFFERENCE"; 
        break;
		  case ctXor: 
        ss << L"Clipper Demo - XOR"; 
        break;
		  default: 
        ss << L"Clipper Demo - INTERSECTION"; 
	  }

	switch(pft)
  {
    case pftEvenOdd: 
      ss << L"  (EvenOdd filled polygons with "; 
      break;
    case pftNonZero: 
      ss << L"  (NonZero filled polygons with "; 
      break;
    case pftPositive: 
      ss << L"  (Positive filled polygons with "; 
      break;
    default: 
      ss << L"  (Negative filled polygons with "; 
  }
  ss << VertCount << " vertices each.)";
	SetWindowText(hWnd, ss.str().c_str());

	HCURSOR hArrowCursor = LoadCursor(NULL, IDC_ARROW);
	SetCursor(hArrowCursor);
	SetClassLong(hWnd, GCL_HCURSOR, (DWORD)hArrowCursor);
}
//------------------------------------------------------------------------------

inline long64 Round(double val)
{
  if ((val < 0)) return (long64)(val - 0.5); else return (long64)(val + 0.5);
}
//------------------------------------------------------------------------------

//bool LoadFromFile(Polygons &ppg, char * filename, double scale= 1,
//  int xOffset = 0, int yOffset = 0)
//{
//  ppg.clear();
//  ifstream infile(filename);
//  if (!infile.is_open()) return false;
//  int polyCnt, vertCnt;
//  double X, Y;
//  
//  infile >> polyCnt;
//  infile.ignore(80, '\n');
//  if (infile.good() && polyCnt > 0)
//  {
//    ppg.resize(polyCnt);
//    for (int i = 0; i < polyCnt; i++) 
//    {
//      infile >> vertCnt;
//      infile.ignore(80, '\n');
//      if (!infile.good() || vertCnt < 0) break;
//      ppg[i].resize(vertCnt);
//      for (int j = 0; infile.good() && j < vertCnt; j++) 
//      {
//        infile >> X;
//        while (infile.peek() == ' ') infile.ignore();
//        if (infile.peek() == ',') infile.ignore();
//        while (infile.peek() == ' ') infile.ignore();
//        infile >> Y;
//        ppg[i][j].X = Round((X + xOffset) * scale);
//        ppg[i][j].Y = Round((Y + yOffset) * scale);
//        infile.ignore(80, '\n');
//      }
//    }
//  }
//  infile.close();
//  return true;
//}
//------------------------------------------------------------------------------

void SaveToFile(const char *filename, Paths &pp, double scale = 1)
{
  ofstream of(filename);
  if (!of.is_open()) return;
  of << pp.size() << "\n";
  for (Paths::size_type i = 0; i < pp.size(); ++i)
  {
    of << pp[i].size() << "\n";
    if (scale > 1.01 || scale < 0.99) 
      of << fixed << setprecision(6);
    for (Path::size_type j = 0; j < pp[i].size(); ++j)
      of << (double)pp[i][j].X /scale << ", " << (double)pp[i][j].Y /scale << ",\n";
  }
  of.close();
}
//---------------------------------------------------------------------------

void UpdatePolygons(bool updateSolutionOnly)
{
	if (VertCount < 0) VertCount = -VertCount;
  if (VertCount > 50) VertCount = 50;
  if (VertCount < 3) VertCount = 3;

  Clipper c;
	if (!updateSolutionOnly)
	{
    delta = 0.0;

    RECT r;
    GetWindowRect(hStatus, &r);
    int statusHeight = r.bottom - r.top;
    GetClientRect(hWnd, &r);

    sub.resize(1);
    clp.resize(1);
    
 
    MakeRandomPoly(sub[0], r.right, r.bottom - statusHeight, VertCount);
    MakeRandomPoly(clp[0], r.right, r.bottom - statusHeight, VertCount);

    //SaveToFile("subj.txt", sub);
    //SaveToFile("clip.txt", clp);
	}

  c.AddPaths(sub, ptSubject, true);
  c.AddPaths(clp, ptClip, true);
	
  c.Execute(ct, sol, pft, pft);
  SaveToFile("solution.txt", sol);

  if (delta != 0.0)
  {
    ClipperOffset co;
    co.AddPaths(sol, jt, etClosedPolygon);
    co.Execute(sol, delta);
  }

	InvalidateRect(hWnd, NULL, false); 
}
//------------------------------------------------------------------------------

void DoNumericKeyPress(int  num)
{
  if (VertCount >= 0) VertCount = -num;
  else if (VertCount > -10) VertCount = VertCount*10 - num;
  else Beep(1000, 100);
}
//------------------------------------------------------------------------------

LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM  lParam)
{
	int clientwidth, clientheight;
  switch (uMsg)
  {

	  case WM_SIZE:
		  clientwidth = LOWORD(lParam);
		  clientheight = HIWORD(lParam);
		  ResizeGraphics(clientwidth, clientheight);
		  SetWindowPos(hStatus, NULL, 0, 
        clientheight, clientwidth, 0, SWP_NOACTIVATE | SWP_NOZORDER);
          return 0;

	  case WM_PAINT:
		  HDC hdc;
		  PAINTSTRUCT ps;
		  hdc = BeginPaint(hWnd, &ps);
		  //do the drawing ...
		  DrawGraphics();
		  SwapBuffers(hdc);
		  EndPaint(hWnd, &ps);		
		  return 0;

    case WM_CLOSE: 
        DestroyWindow(hWnd);
        return 0;
 
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;

	  case WM_HELP:
      MessageBox(hWnd, helpText, L"Clipper Demo - Help", 0);
      return 0;

    case WM_COMMAND:
      switch(LOWORD(wParam))
      {
          case 1: case 27: PostQuitMessage(0); break; //escape
          case 98: MessageBox(hWnd, helpText, L"Clipper Demo - Help", 0); break;
          case 99: MessageBox(hWnd, L"After closing this dialog,\ntype the required number of vertices (3-50) then <Enter> ...", L"Clipper Demo", 0);
          case 101: show_clipping = true; ct = ctIntersection; UpdatePolygons(true); break;
          case 102: show_clipping = true; ct = ctUnion; UpdatePolygons(true); break;
          case 103: show_clipping = true; ct = ctDifference; UpdatePolygons(true); break;
          case 104: show_clipping = true; ct = ctXor; UpdatePolygons(true); break;
			    case 105: pft = pftEvenOdd; UpdatePolygons(true); break;
			    case 106: pft = pftNonZero; UpdatePolygons(true); break;
          case 107: pft = pftPositive; UpdatePolygons(true); break;
          case 108: pft = pftNegative; UpdatePolygons(true); break;
			    case 109: show_clipping = !show_clipping; UpdatePolygons(true); break;
          case 110: case 111: case 112: case 113: case 114:
          case 115: case 116: case 117: case 118: case 119: 
            DoNumericKeyPress(LOWORD(wParam) - 110); 
            break;
          case 120: UpdatePolygons(false); break; //space, return
          case 131: if (delta < 20*scale) {delta += scale; UpdatePolygons(true);} break;
          case 132: if (delta > -20*scale) {delta -= scale; UpdatePolygons(true);} break;
          case 133: if (delta != 0.0) {delta = 0.0; UpdatePolygons(true);} break;
          case 141: {jt = jtMiter; if (delta != 0.0) UpdatePolygons(true);} break;
          case 142: {jt = jtSquare; if (delta != 0.0) UpdatePolygons(true);} break;
          case 143: {jt = jtRound; if (delta != 0.0) UpdatePolygons(true);} break;
          default: return DefWindowProc (hWnd, uMsg, wParam, lParam); 
      }
      return 0; 

    case WM_LBUTTONUP:
		  UpdatePolygons(false);
		  return 0;

    // Default event handler
    default: return DefWindowProc (hWnd, uMsg, wParam, lParam); 
  }  
}
//------------------------------------------------------------------------------

int WINAPI WinMain (HINSTANCE hInstance, 
  HINSTANCE, LPSTR, int nCmdShow)
{

    const LPCWSTR appname = TEXT("Clipper Demo");

    WNDCLASS wndclass;
    MSG      msg;
 
    // Define the window class
    wndclass.style         = 0;
    wndclass.lpfnWndProc   = (WNDPROC)MainWndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon(hInstance, appname);
    wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wndclass.lpszMenuName  = appname;
    wndclass.lpszClassName = appname;
 
    // Register the window class
    if (!RegisterClass(&wndclass)) return FALSE;

    HMENU menu = LoadMenu(hInstance, MAKEINTRESOURCE(1));
    HACCEL accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(1));

    int windowSizeX = 540, windowSizeY = 400;

    int dx = GetSystemMetrics(SM_XVIRTUALSCREEN);
    int dy = GetSystemMetrics(SM_YVIRTUALSCREEN);
    dx += ((GetSystemMetrics(SM_CXSCREEN) -windowSizeX) /2);
    dy += ((GetSystemMetrics(SM_CYSCREEN) -windowSizeY) /2);

    // Create the window
    hWnd = CreateWindow(
            appname,
            appname,
            WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
            dx, dy, windowSizeX, windowSizeY,
            NULL,
            menu,
            hInstance,
            NULL);
 
    if (!hWnd) return FALSE;

	//replace the main window icon with Resource Icon #1 ...
  HANDLE small_ico = LoadImage(hInstance, MAKEINTRESOURCE(1), IMAGE_ICON, 16, 16, 0);
	HANDLE big_ico = LoadImage(hInstance, MAKEINTRESOURCE(1), IMAGE_ICON, 32, 32, 0);
	SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)small_ico);
	SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)big_ico);

	InitCommonControls();
	hStatus = CreateWindowEx(0, L"msctls_statusbar32", NULL, WS_CHILD | WS_VISIBLE,
		0, 0, 0, 0, hWnd, (HMENU)0, hInstance, NULL);
	SetWindowText(hStatus, L" Copyright  Angus Johnson 2011");

  // Initialize OpenGL
  InitGraphics();

	srand((unsigned)time(0)); 
	UpdatePolygons(false);

  // Display the window
  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);

  // Event loop
    for (;;)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
        {
            if (!GetMessage(&msg, NULL, 0, 0)) break;

            if (!TranslateAccelerator(hWnd, accel, &msg))
            {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
            }
        }
    }
	  wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hRC);
    ReleaseDC(hWnd, hDC);
    return TRUE;
}
//------------------------------------------------------------------------------