-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinMain.h
2261 lines (1922 loc) · 63.4 KB
/
WinMain.h
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************
*WINMAIN.H, *
* Copyright © 2004, Jonathan Bradley Whited.*
*********************************************/
/*Content. */
/* Pragmas: 5. */
/* Inclusions: 8. */
/* Macros: 25. */
/* Namespaces: 1. */
/* Classes: 2. */
/* Constructors: 4. */
/* Destructors: 1. */
/* Member functions: 23. */
/* Member variables: 40. */
/* */
/*Purpose. */
/* EkoScape Version 1.0. */
/* */
/*Thanks... */
/* to Ryan Witmer at */
/* http://www.averagesoftware.com for */
/* making the Dantares engine. */
/* to http://www.gamehippo.com for all of */
/* those free games! */
/* to Jeff Molofee at */
/* http://www.nehe.gamedev.net for making*/
/* those OpenGL tutorials! */
/* to you! You must have a lot of time on */
/* your hands to even read this! */
#ifndef __cplusplus
#error "This is not a C++ compiler."
#endif
#ifndef _WINDOWS
#error "This is not a Windows compiler."
#endif
#ifndef WINMAIN_H
#define WINMAIN_H
/********
*Pragmas*
********/
#ifndef WINMAIN_H_NO_PRAGMAS
#pragma comment(lib,"dinput8.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"opengl32.lib")
#endif
#pragma message("Dantares Engine Version 0.82, Copyright © Ryan Witmer.")
#pragma message("EkoScape, Copyright © 2004, Jonathan Bradley Whited.")
/***********
*Inclusions*
***********/
#ifndef WINMAIN_H_NO_INCLUSIONS
#define INITGUID
#include "Dantares/Dantares.h"
#include <dinput.h>
#include <dmusici.h>
#include <fstream.h>
#include "Resource.h"
#include <stdio.h>
#include <time.h>
#include <windowsx.h>
#if DIRECTINPUT_VERSION < 0x0800
#error "This is not DirectX Version 8.0+."
#endif
/********************************
*#ifndef WINMAIN_H_NO_INCLUSIONS*
********************************/
#endif
/*******
*Macros*
*******/
#ifndef WINMAIN_H_NO_MACROS
/*CROBOT::m_iX*/
#define CRX_VELOCITY 1
/*CROBOT::m_iY*/
#define CRY_VELOCITY 1
/*CROBOT::m_ulType*/
//Do not use 0
#define CRT_GHOST (1)
#define CRT_NORMAL (2)
#define CRT_SNAKE (3)
#define CRT_WORM (4)
/*CWINMAIN::(char)(Array)*/
#define CWMCA_MAXIMUM (256)
/*CWINMAIN::BackgroundProcessing(...){...Refresh rate...}*/
//Refresh rate in milliseconds
// 60 frames/1 second = 16.6r milliseconds/1 frame
#define CWMBP_REFRESHRATE (17)
/*CWINMAIN::m_CDantares*/
//Facing (direction)
#define CWMDF_EAST (1)
#define CWMDF_NORTH (0)
#define CWMDF_SOUTH (2)
#define CWMDF_WEST (3)
//Initialization
#define CWMDI_CEILINGHEIGHT (.04f)
#define CWMDI_FLOORHEIGHT (-.04f)
#define CWMDI_SQUARESIZE (.125f)
//Maximum map sizes
#define CWMDM_MAXIMUMHEIGHT (200)
#define CWMDM_MAXIMUMWIDTH (200)
/*CWINMAIN::m_CRobots[]*/
#define CWMRS_MAXIMUM (200)
/*CWINMAIN::m_ulState*/
#define CWMS_INTRODUCTION (1)
#define CWMS_PLAYING (2)
/*Errors*/
#define ERROR_MESSAGEBOX \
\
MessageBox(NULL,"An unknown error occurred.","EkoScape Error.",MB_ICONERROR | MB_OK | MB_SYSTEMMODAL)
/*KEYDOWN(KEY)*/
#define KEYDOWN(KEY) (m_uchKey[(KEY)] != 0)
/*KEYUP(KEY)*/
#define KEYUP(KEY) (m_uchKey[(KEY)] == 0)
/*WM_TIMER*/
#define WMT_BACKGROUNDPROCESSING (101)
#define WMT_ROBOTDELAY (102)
#endif
/***********
*Namespaces*
***********/
#ifndef WINMAIN_H_NO_NAMESPACES
namespace WINMAIN
{
#endif
/******************
*Class definitions*
******************/
#ifndef WINMAIN_H_NO_CLASSES
class CROBOT
{
protected:
//////////////////////////////
//Member variable prototypes//
//////////////////////////////
int m_iX,
m_iY;
unsigned long m_ulType;
public:
//////////////////////////
//Constructor prototypes//
//////////////////////////
CROBOT();
CROBOT(CROBOT *p_pCRobot);
CROBOT(int p_iX,int p_iY,unsigned long p_ulType);
//////////////////////////////
//Member function prototypes//
//////////////////////////////
virtual bool Draw();
virtual unsigned long GetType();
virtual int GetX();
virtual int GetY();
virtual bool Move();
virtual bool operator =(CROBOT *p_pCRobot);
virtual bool Set(CROBOT *p_pCRobot);
virtual bool Set(int p_iX,int p_iY,unsigned long p_ulType);
virtual bool SetPosition(int p_iX,int p_iY);
virtual bool SetType(unsigned long p_ulType);
virtual bool SetX(int p_iX);
virtual bool SetY(int p_iY);
};
class CWINMAIN
{
public:
//////////////////////////
//Constructor prototypes//
//////////////////////////
CWINMAIN();
////////////////////////
//Destructor prototype//
////////////////////////
virtual ~CWINMAIN();
//////////////////////////////
//Member function prototypes//
//////////////////////////////
virtual bool BackgroundProcessing();
virtual bool BitmapGetBytes(HBITMAP *p_phBitmap,unsigned char *p_puszBytes);
virtual bool BitmapGetDIBSection(DIBSECTION *p_pDIBSection,HBITMAP *p_phBitmap);
virtual bool BitmapLoad(const char *p_pszFile,unsigned int *p_puiTexture,bool p_bFile = true);
virtual bool Create(unsigned long p_ulColorBitsPerPixel,unsigned long p_ulDepthBitsPerPixel,unsigned long p_ulHeight,unsigned long p_ulWidth);
virtual void Delete();
virtual bool MapCreate();
virtual bool MapLoad(const char *p_pszFile);
virtual WPARAM MessageLoop();
virtual bool MusicLoad(const char *p_pszFile,IDirectMusicSegment8 **p_ppIDMSegment8,bool p_bFile = true,const char *p_pszType = "");
static LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
//////////////////////////////
//Member variable prototypes//
//////////////////////////////
static bool m_bBackgroundProcessing;
static char m_cCellSpace,
m_cPlayerSpace,
m_cRobotSpace,
m_szAuthor[CWMCA_MAXIMUM],
m_szTitle[CWMCA_MAXIMUM];
static CROBOT m_CRobots[CWMRS_MAXIMUM];
static Dantares m_CDantares;
static HDC m_hDC;
static HGLRC m_hGLRC;
static HINSTANCE m_hInstance;
static HWND m_hWnd;
static IDirectMusicLoader8 *m_pIDMLoader8;
static IDirectMusicPerformance8 *m_pIDMPerformance8;
static IDirectMusicSegment8 *m_pIDMSt8Matrix;
static int m_iMapID,
**m_ppiMap,
**m_ppiMapNoObjects;
static LPDIRECTINPUT8 m_lpDirectInput8;
static LPDIRECTINPUTDEVICE8 m_lpDIDe8Keyboard;
static unsigned char m_uchKey[256];
static unsigned int m_uiTextureCeiling,
m_uiTextureCell,
m_uiTextureEnd,
m_uiTextureFloor,
m_uiTextureIntroduction,
m_uiTextureRobot,
m_uiTextureWall;
static unsigned long m_ulBitsPerPixel,
m_ulCells,
m_ulCellsTotal,
m_ulHeight,
m_ulMapHeight,
m_ulMapWidth,
m_ulRobotDelay,
m_ulState,
m_ulWidth;
};
/****************************
*Member variable definitions*
****************************/
bool CWINMAIN::m_bBackgroundProcessing = true;
char CWINMAIN::m_cCellSpace = 0,
CWINMAIN::m_cPlayerSpace = 0,
CWINMAIN::m_cRobotSpace = 0,
CWINMAIN::m_szAuthor[CWMCA_MAXIMUM] = "",
CWINMAIN::m_szTitle[CWMCA_MAXIMUM] = "";
CROBOT CWINMAIN::m_CRobots[CWMRS_MAXIMUM];
Dantares CWINMAIN::m_CDantares(CWMDI_SQUARESIZE,
CWMDI_FLOORHEIGHT,
CWMDI_CEILINGHEIGHT);
HDC CWINMAIN::m_hDC = NULL;
HGLRC CWINMAIN::m_hGLRC = NULL;
HINSTANCE CWINMAIN::m_hInstance = GetModuleHandle(NULL);
HWND CWINMAIN::m_hWnd = NULL;
IDirectMusicLoader8 *CWINMAIN::m_pIDMLoader8 = NULL;
IDirectMusicPerformance8 *CWINMAIN::m_pIDMPerformance8 = NULL;
IDirectMusicSegment8 *CWINMAIN::m_pIDMSt8Matrix = NULL;
int CWINMAIN::m_iMapID = -1,
**CWINMAIN::m_ppiMap = 0,
**CWINMAIN::m_ppiMapNoObjects = 0;
LPDIRECTINPUT8 CWINMAIN::m_lpDirectInput8 = NULL;
LPDIRECTINPUTDEVICE8 CWINMAIN::m_lpDIDe8Keyboard = NULL;
unsigned char CWINMAIN::m_uchKey[256];
unsigned int CWINMAIN::m_uiTextureCeiling = 0,
CWINMAIN::m_uiTextureCell = 0,
CWINMAIN::m_uiTextureEnd = 0,
CWINMAIN::m_uiTextureFloor = 0,
CWINMAIN::m_uiTextureIntroduction = 0,
CWINMAIN::m_uiTextureRobot = 0,
CWINMAIN::m_uiTextureWall = 0;
unsigned long CWINMAIN::m_ulBitsPerPixel = 0,
CWINMAIN::m_ulCells = 0,
CWINMAIN::m_ulCellsTotal = 0,
CWINMAIN::m_ulHeight = 0,
CWINMAIN::m_ulMapHeight = 0,
CWINMAIN::m_ulMapWidth = 0,
CWINMAIN::m_ulRobotDelay = 0,
CWINMAIN::m_ulState = CWMS_INTRODUCTION,
CWINMAIN::m_ulWidth = 0;
/************************
*Constructor definitions*
************************/
inline CROBOT::CROBOT() : m_iX(-1),m_iY(-1),m_ulType(0)
{
}
inline CROBOT::CROBOT(CROBOT *p_pCRobot)
{
m_iX = m_iY = -1;
m_ulType = 0;
if(p_pCRobot != 0)
{
SetType(p_pCRobot->GetType());
SetX(p_pCRobot->GetX());
SetY(p_pCRobot->GetY());
}
}
inline CROBOT::CROBOT(int p_iX,int p_iY,unsigned long p_ulType)
{
m_iX = m_iY = -1;
m_ulType = 0;
SetType(p_ulType);
SetX(p_iX);
SetY(p_iY);
}
inline CWINMAIN::CWINMAIN()
{
}
/***********************
*Destructor definitions*
***********************/
inline CWINMAIN::~CWINMAIN()
{
Delete();
}
/****************************
*Member function definitions*
****************************/
inline bool CROBOT::Draw()
{
//////////////////////////////////////
//Check for invalid member variables//
//////////////////////////////////////
if(!SetType(m_ulType) || !SetX(m_iX) || !SetY(m_iY))
{
return(false);
}
/////////////////////////////////////////////
//Check for invalid static member variables//
/////////////////////////////////////////////
if(CWINMAIN::m_CDantares.GetCurrentMap() < 0 ||
!CWINMAIN::m_CDantares.IsMap(CWINMAIN::m_iMapID) ||
CWINMAIN::m_ppiMap == 0)
{
return(false);
}
////////////////////
//Create variables//
////////////////////
int iType = 0;
switch(m_ulType)
{
case CRT_GHOST:
{
iType = '|';
}break;
case CRT_NORMAL:
{
iType = '!';
}break;
case CRT_SNAKE:
{
iType = 'Q';
}break;
case CRT_WORM:
{
iType = '?';
}break;
}
CWINMAIN::m_ppiMap[m_iX][m_iY] = iType;
CWINMAIN::m_CDantares.ChangeSquare(m_iX,m_iY,iType);
CWINMAIN::m_CDantares.MakeSpaceWalkable(m_iX,m_iY);
return(true);
}
inline unsigned long CROBOT::GetType()
{
return(m_ulType);
}
inline int CROBOT::GetX()
{
return(m_iX);
}
inline int CROBOT::GetY()
{
return(m_iY);
}
inline bool CROBOT::Move()
{
//////////////////////////////////////
//Check for invalid member variables//
//////////////////////////////////////
if(!SetType(m_ulType) || !SetX(m_iX) || !SetY(m_iY))
{
return(false);
}
/////////////////////////////////////////////
//Check for invalid static member variables//
/////////////////////////////////////////////
if(CWINMAIN::m_CDantares.GetCurrentMap() < 0 ||
!CWINMAIN::m_CDantares.IsMap(CWINMAIN::m_iMapID) ||
CWINMAIN::m_ppiMap == 0)
{
return(false);
}
////////////////////
//Create variables//
////////////////////
int iXOld = m_iX,
iYOld = m_iY,
iXY = 0;
m_iX = iXOld+((m_iX < CWINMAIN::m_CDantares.GetPlayerX()) ? (CRX_VELOCITY) : (-(CRX_VELOCITY)));
m_iY = iYOld+((m_iY < CWINMAIN::m_CDantares.GetPlayerY()) ? (CRY_VELOCITY) : (-(CRY_VELOCITY)));
if(m_iX < 0 || m_iX >= static_cast<int>(CWINMAIN::m_ulMapWidth))
{
m_iX = iXOld;
}
if(m_iY < 0 || m_iY >= static_cast<int>(CWINMAIN::m_ulMapHeight))
{
m_iY = iYOld;
}
switch(m_ulType)
{
case CRT_NORMAL:
case CRT_WORM:
{
switch(CWINMAIN::m_ppiMap[m_iX][iYOld])
{
//DeadSpace
//EndWall
//Wall
//White
case 'x':
case '&':
case '#':
case 'W':
{
}break;
default:
{
iXY = 1;
}break;
}
switch(CWINMAIN::m_ppiMap[iXOld][m_iY])
{
//DeadSpace
//EndWall
//Wall
//White
case 'x':
case '&':
case '#':
case 'W':
{
}break;
default:
{
iXY = (iXY == 1) ? 3 : 2;
}break;
}
switch(iXY)
{
case 0:
{
m_iX = iXOld;
m_iY = iYOld;
}break;
case 1:
{
m_iY = iYOld;
}break;
case 2:
{
m_iX = iXOld;
}break;
case 3:
{
if((rand()%2) == 0)
{
m_iX = iXOld;
}
else
{
m_iY = iYOld;
}
}break;
}
}break;
default:
{
if((rand()%2) == 0)
{
m_iX = iXOld;
}
else
{
m_iY = iYOld;
}
iXY = 4;
}break;
}
if(iXY != 0)
{
switch(m_ulType)
{
case CRT_GHOST:
case CRT_NORMAL:
{
CWINMAIN::m_ppiMap[iXOld][iYOld] = CWINMAIN::m_ppiMapNoObjects[iXOld][iYOld];
CWINMAIN::m_CDantares.ChangeSquare(iXOld,iYOld,CWINMAIN::m_ppiMapNoObjects[iXOld][iYOld]);
switch(CWINMAIN::m_ppiMap[iXOld][iYOld])
{
//DeadSpace
//EndWall
//Wall
//White
case 'x':
case '&':
case '#':
case 'W':
{
CWINMAIN::m_CDantares.MakeSpaceNonWalkable(iXOld,iYOld);
}break;
default:
{
CWINMAIN::m_CDantares.MakeSpaceWalkable(iXOld,iYOld);
}break;
}
}break;
}
}
return(true);
}
inline bool CROBOT::operator =(CROBOT *p_pCRobot)
{
return(Set(p_pCRobot));
}
inline bool CROBOT::Set(CROBOT *p_pCRobot)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_pCRobot == 0)
{
return(false);
}
if(!SetType(p_pCRobot->GetType()) || !SetX(p_pCRobot->GetX()) || !SetY(p_pCRobot->GetY()))
{
return(false);
}
return(true);
}
inline bool CROBOT::Set(int p_iX,int p_iY,unsigned long p_ulType)
{
if(!SetType(p_ulType) || !SetX(p_iX) || !SetY(p_iY))
{
return(false);
}
return(true);
}
inline bool CROBOT::SetPosition(int p_iX,int p_iY)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_iX < 0 ||
p_iX >= static_cast<int>(CWINMAIN::m_ulMapWidth) ||
p_iY < 0 ||
p_iY >= static_cast<int>(CWINMAIN::m_ulMapHeight))
{
return(false);
}
m_iX = p_iX;
m_iY = p_iY;
return(true);
}
inline bool CROBOT::SetType(unsigned long p_ulType)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
switch(p_ulType)
{
case CRT_GHOST:
case CRT_NORMAL:
case CRT_SNAKE:
case CRT_WORM:
{
m_ulType = p_ulType;
}break;
default:
{
return(false);
}break;
}
return(true);
}
inline bool CROBOT::SetX(int p_iX)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_iX < 0 ||
p_iX >= static_cast<int>(CWINMAIN::m_ulMapWidth))
{
return(false);
}
m_iX = p_iX;
return(true);
}
inline bool CROBOT::SetY(int p_iY)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_iY < 0 ||
p_iY >= static_cast<int>(CWINMAIN::m_ulMapHeight))
{
return(false);
}
m_iY = p_iY;
return(true);
}
inline bool CWINMAIN::BitmapGetBytes(HBITMAP *p_phBitmap,unsigned char *p_puszBytes)
{
//////////////////////////////////////
//Check for invalid member variables//
//////////////////////////////////////
if(m_hDC == NULL || m_hWnd == NULL)
{
return(false);
}
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_phBitmap == 0 || *p_phBitmap == NULL)
{
return(false);
}
try
{
strcat(reinterpret_cast<char *>(p_puszBytes),"");
}
catch(...)
{
return(false);
}
////////////////////
//Create variables//
////////////////////
BITMAPINFO BitmapInfo;
DIBSECTION DIBSection;
HBITMAP hBpOld = NULL;
HDC hDCBitmap = NULL;
//////////////////
//Get DIBSection//
//////////////////
ZeroMemory(&DIBSection,sizeof(DIBSECTION));
if(!BitmapGetDIBSection(&DIBSection,p_phBitmap))
{
return(false);
}
//////////////////
//Get BitmapInfo//
//////////////////
ZeroMemory(&BitmapInfo,sizeof(BITMAPINFO));
CopyMemory(&BitmapInfo.bmiHeader,&DIBSection.dsBmih,sizeof(BITMAPINFOHEADER));
////////////////////////////////
//Create hDCBitmap using m_hDC//
////////////////////////////////
if((hDCBitmap = CreateCompatibleDC(m_hDC)) == NULL)
{
return(false);
}
//////////////
//Get hBpOld//
//////////////
if((hBpOld = SelectBitmap(hDCBitmap,*p_phBitmap)) == NULL)
{
DeleteDC(hDCBitmap);
hDCBitmap = NULL;
return(false);
}
////////////////////
//Get *p_puszBytes//
////////////////////
try
{
if(GetDIBits(hDCBitmap,*p_phBitmap,0,BitmapInfo.bmiHeader.biHeight,
static_cast<LPVOID>(p_puszBytes),&BitmapInfo,DIB_RGB_COLORS) == 0)
{
SelectBitmap(hDCBitmap,hBpOld);
DeleteDC(hDCBitmap);
hDCBitmap = NULL;
return(false);
}
}
catch(...)
{
SelectBitmap(hDCBitmap,hBpOld);
DeleteDC(hDCBitmap);
hDCBitmap = NULL;
return(false);
}
////////////////////
//Delete variables//
////////////////////
if(SelectBitmap(hDCBitmap,hBpOld) == NULL)
{
DeleteDC(hDCBitmap);
hDCBitmap = NULL;
return(false);
}
if(DeleteDC(hDCBitmap) == FALSE)
{
hDCBitmap = NULL;
return(false);
}
hDCBitmap = NULL;
return(true);
}
inline bool CWINMAIN::BitmapGetDIBSection(DIBSECTION *p_pDIBSection,HBITMAP *p_phBitmap)
{
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_pDIBSection == 0 || p_phBitmap == 0 || *p_phBitmap == NULL)
{
return(false);
}
//////////////////////
//Get *p_pDIBSection//
//////////////////////
if(GetObject(static_cast<HGDIOBJ>(*p_phBitmap),sizeof(DIBSECTION),
static_cast<LPVOID>(p_pDIBSection)) == 0)
{
return(false);
}
return(true);
}
inline bool CWINMAIN::BitmapLoad(const char *p_pszFile,unsigned int *p_puiTexture,bool p_bFile)
{
//////////////////////////////////////
//Check for invalid member variables//
//////////////////////////////////////
if(m_hInstance == NULL)
{
return(false);
}
////////////////////////////////
//Check for invalid parameters//
////////////////////////////////
if(p_puiTexture == 0)
{
return(false);
}
////////////////////
//Create variables//
////////////////////
DIBSECTION DIBSection;
char *pszCommandLine = 0;
GLenum GLEnum = GL_BGR_EXT;
HBITMAP hBitmap = NULL;
unsigned char *puszBytes = 0;
///////////////////////
//Get *pszCommandLine//
///////////////////////
if((pszCommandLine = new char[lstrlen(GetCommandLine())+1]) == 0)
{
return(false);
}
strcpy(pszCommandLine,GetCommandLine());
if(*pszCommandLine == '"')
{
while(*pszCommandLine != '\0')
{
strcpy(pszCommandLine,pszCommandLine+1);
if(*pszCommandLine == '"')
{
strcpy(pszCommandLine,pszCommandLine+1);
if(*pszCommandLine == ' ')
{
strcpy(pszCommandLine,pszCommandLine+1);
}
break;
}
}
}
else
{
while(*pszCommandLine != '\0')
{
strcpy(pszCommandLine,pszCommandLine+1);
if(*pszCommandLine == ' ')
{
strcpy(pszCommandLine,pszCommandLine+1);
break;
}
}
}
//////////////
//Get GLEnum//
//////////////
if(strcmp(strupr(pszCommandLine),"GL_RGB") == 0)
{
GLEnum = GL_RGB;
}
////////////////////
//Delete variables//
////////////////////
delete [] pszCommandLine;
pszCommandLine = 0;
///////////////
//Get hBitmap//
///////////////
if(p_bFile)
{
if((hBitmap = static_cast<HBITMAP>(LoadImage(NULL,p_pszFile,IMAGE_BITMAP,0,0,
LR_CREATEDIBSECTION | LR_LOADFROMFILE))) == NULL)
{
return(false);
}
}
else
{
if((hBitmap = static_cast<HBITMAP>(LoadImage(m_hInstance,p_pszFile,IMAGE_BITMAP,0,0,
LR_CREATEDIBSECTION))) == NULL)
{
return(false);
}
}
//////////////////
//Get DIBSection//
//////////////////
ZeroMemory(&DIBSection,sizeof(DIBSECTION));
if(!BitmapGetDIBSection(&DIBSection,&hBitmap))
{
DeleteBitmap(hBitmap);
hBitmap = NULL;
return(false);
}
//////////////////
//Get *puszBytes//
//////////////////
if((puszBytes = new unsigned char[DIBSection.dsBmih.biSizeImage+1]) == 0)
{
DeleteBitmap(hBitmap);
hBitmap = NULL;
return(false);
}
if(!BitmapGetBytes(&hBitmap,puszBytes))
{
DeleteBitmap(hBitmap);
hBitmap = NULL;
delete [] puszBytes;
puszBytes = 0;
return(false);
}
////////////////////
//Delete variables//
////////////////////
DeleteBitmap(hBitmap);
hBitmap = NULL;
////////////////////////
//Create *p_puiTexture//
////////////////////////
glGenTextures(1,p_puiTexture);
glBindTexture(GL_TEXTURE_2D,*p_puiTexture);
glTexImage2D(GL_TEXTURE_2D,0,3,DIBSection.dsBmih.biWidth,DIBSection.dsBmih.biHeight,0,GLEnum,
GL_UNSIGNED_BYTE,static_cast<GLvoid *>(puszBytes));
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);