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
| #pragma once
#include <windows.h>
#include <windowsx.h>
#include <vector>
#include <windowsx.h>
#include <string.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <stdio.h>
#include <fstream>
#include <process.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#pragma comment(lib,"OpenGL32.lib ")
#pragma comment(lib,"GLu32.lib ")
CRITICAL_SECTION cs;
unsigned char WarningLevel;
HDC DC=NULL; // Private GDI Device Context
HGLRC RC=NULL; // Permanent Rendering Context
HWND Window=NULL; // Holds Our Window Handle
HINSTANCE Instance; // Holds The Instance Of The Application
HDC DC2=NULL; // Private GDI Device Context
HGLRC RC2=NULL; // Permanent Rendering Context
HWND Window2=NULL; // Holds Our Window Handle
HINSTANCE Instance2; // Holds The Instance Of The Application
bool Active;
bool Active2;
MSG msg;
MSG msg2;
LRESULT WindowProcess(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
LRESULT WindowProcess2(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
void Warning(wchar_t iwarning[],char ilevel=1){
if(ilevel>=WarningLevel){
if(ilevel==5){
MessageBox(NULL,iwarning,L"Crytical Error",MB_OK|MB_ICONERROR);
}else{
MessageBox(NULL,iwarning,L"Warning or Error",MB_OK|MB_ICONERROR);
}
}
}
void CreateWindow1(int iwidth, int iheight, wchar_t ititle[]){
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)iwidth; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)iheight; // Set Bottom Value To Requested Height
Instance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WindowProcess; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = Instance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = L"Window"; // Set The Class Name
if (!RegisterClass(&wc)){
Warning(L"Failed To Register The Window Class.",5);
}
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(Window=CreateWindowEx( dwExStyle, // Extended Style For The Window
L"Window", // Class Name
ititle, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
Instance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
Warning(L"Window Creation Error.",5);
}
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!(DC=GetDC(Window))){
Warning(L"Can't Create A GL Device Context.",5); // Return FALSE
}
if (!(PixelFormat=ChoosePixelFormat(DC,&pfd))){
Warning(L"Can't Find A Suitable PixelFormat.",5);
}
if(!SetPixelFormat(DC,PixelFormat,&pfd)){
Warning(L"Can't Set The PixelFormat.",5);
}
if (!(RC=wglCreateContext(DC))){
Warning(L"Can't Create A GL Rendering Context.",5);
}
if(!wglMakeCurrent(DC,RC)){
Warning(L"Can't Activate The GL Rendering Context.",5);
}
Active=1;
ShowWindow(Window,SW_SHOW); // Show The Window
SetForegroundWindow(Window); // Slightly Higher Priority
SetFocus(Window); // Sets Keyboard Focus To The Window
}
void CreateWindow2(int iwidth, int iheight, wchar_t ititle[]){
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)iwidth; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)iheight; // Set Bottom Value To Requested Height
Instance2 = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WindowProcess2; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = Instance2; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = L"k"; // Set The Class Name
if (!RegisterClass(&wc)){
Warning(L"Failed To Register The Window Class.",5);
}
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(Window2=CreateWindowEx( dwExStyle, // Extended Style For The Window
L"k", // Class Name
ititle, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
800, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
Instance2, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
Warning(L"Window Creation Error.",5);
}
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!(DC2=GetDC(Window2))){
Warning(L"Can't Create A GL Device Context.",5); // Return FALSE
}
if (!(PixelFormat=ChoosePixelFormat(DC2,&pfd))){
Warning(L"Can't Find A Suitable PixelFormat.",5);
}
if(!SetPixelFormat(DC2,PixelFormat,&pfd)){
Warning(L"Can't Set The PixelFormat.",5);
}
if (!(RC2=wglCreateContext(DC2))){
Warning(L"Can't Create A GL Rendering Context.",5);
}
if(!wglMakeCurrent(DC2,RC2)){
Warning(L"Can't Activate The GL Rendering Context.",5);
}
Active2=1;
ShowWindow(Window2,SW_SHOW); // Show The Window
SetForegroundWindow(Window2); // Slightly Higher Priority
SetFocus(Window2); // Sets Keyboard Focus To The Window
}
LRESULT WindowProcess(HWND iWindow,UINT iMassage,WPARAM iWParam, LPARAM iLParam){
unsigned int i1,i2;
if(iMassage==WM_ACTIVATE){
if (!HIWORD(iWParam)){
Active=1;
}else{
Active=0;
}
return 0;
}else if(iMassage==WM_SYSCOMMAND){
if(iWParam==SC_MONITORPOWER){
return 0;
}
//break;
}else if(iMassage==WM_CLOSE){
//PostQuitMessage(0);
return 0;
}else if(iMassage==WM_KEYDOWN){
return 0;
}else if(iMassage==WM_KEYUP){
return 0;
}else if(iMassage==WM_SIZE){
return 0;
}
return DefWindowProc(iWindow,iMassage,iWParam,iLParam);
}
LRESULT WindowProcess2(HWND iWindow,UINT iMassage,WPARAM iWParam, LPARAM iLParam){
unsigned int i1,i2;
if(iMassage==WM_ACTIVATE){
if (!HIWORD(iWParam)){
Active2=1;
}else{
Active2=0;
}
return 0;
}else if(iMassage==WM_SYSCOMMAND){
if(iWParam==SC_MONITORPOWER){
return 0;
}
//break;
}else if(iMassage==WM_CLOSE){
PostQuitMessage(0);
return 0;
}else if(iMassage==WM_KEYDOWN){
return 0;
}else if(iMassage==WM_KEYUP){
return 0;
}else if(iMassage==WM_SIZE){
return 0;
}
return DefWindowProc(iWindow,iMassage,iWParam,iLParam);
}
void ThreadRender(void* pParams){
EnterCriticalSection( &cs );
CreateWindow1(800,600,L"Window1");
glViewport(0,0,800,600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while(true){
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if (msg.message==WM_QUIT){
break;
}else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
SwapBuffers(DC);
}
LeaveCriticalSection( &cs );
}
void ThreadRender2(void* pParams){
EnterCriticalSection( &cs );
CreateWindow2(800,600,L"Window2");
glViewport(0,0,800,600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while(true){
if (PeekMessage(&msg2,NULL,0,0,PM_REMOVE)){
if (msg2.message==WM_QUIT){
break;
}else{
TranslateMessage(&msg2);
DispatchMessage(&msg2);
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left]
glEnd();
SwapBuffers(DC2);
}
LeaveCriticalSection( &cs );
}
int WINAPI WinMain( HINSTANCE Instance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
InitializeCriticalSection( &cs );
_beginthread( ThreadRender, 0, NULL );
_beginthread( ThreadRender2, 0, NULL );
while(true){
}
return (msg.wParam);
return (msg2.wParam);
} |