Bonjour,

J'ai saisi le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <windows.h> 
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
 
HGLRC hRC=NULL;// Rendering Context
HDC hDC=NULL; //Device Context
HWND hWnd=NULL;
HINSTANCE hInstance;
bool active=TRUE;
bool fullscreen=TRUE;
 
char*   Msgc_Release_Of_DC_And_RC_Failed         = "Release Of DC And RC Failed.";
WCHAR   Msgw_[256 ];
LPCWSTR Msgu_Release_Of_DC_And_RC_Failed;
 
char*   Msgc_Shutdown_Error                      = "Shutdown Error";
LPCWSTR Msgu_Shutdown_Error;
 
char*   Msgc_Release_Device_Context_Failed       = "Release Device Context Failed.";
LPCWSTR Msgu_Release_Device_Context_Failed;
 
char*   Msgc_Release_Rendering_Context_Failed    = "Release Rendering Context Failed.";
LPCWSTR Msgu_Release_Rendering_Context_Failed;
 
char*   Msgc_Could_Not_Release_hWnd              = "Could Not Release hWnd.";
LPCWSTR Msgu_Could_Not_Release_hWnd;
 
char*   Msgc_OpenGL                              = "OpenGL";
LPCWSTR Msgu_OpenGL;
 
char*   Msgc_Could_Not_Unregister_Class          = "Could Not Unregister Class.";
LPCWSTR Msgu_Could_Not_Unregister_Class;
 
char*   Msgc_Failed_To_Register_The_Window_Class = "Failed To Register The Window Class.";
LPCWSTR Msgu_Failed_To_Register_The_Window_Class;
 
char*   Msgc_ERROR                               = "ERROR";
LPCWSTR Msgu_ERROR;
 
char*   Msgc_Fullscreen_Not_Supported            = "The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?";
LPCWSTR Msgu_Fullscreen_Not_Supported;
 
char*   Msgc_NeHe_GL                             = "NeHe GL";
LPCWSTR Msgu_NeHe_GL;
 
char*   Msgc_Program_Will_Now_Close              = "Program Will Now Close";
LPCWSTR Msgu_Program_Will_Now_Close;
 
char*   Msgc_Window_Creation_Error               = "Window Creation Error.";
LPCWSTR Msgu_Window_Creation_Error;
 
char*   Msgc_Cant_Create_GL_Device               = "Can't Create A GL Device Context.";
LPCWSTR Msgu_Cant_Create_GL_Device;
 
char*   Msgc_Cant_Find_PixelFormat               = "Can't Find A Suitable PixelFormat.";
LPCWSTR Msgu_Cant_Find_PixelFormat;
 
char*   Msgc_Cant_Set_PixelFormat                = "Can't Set The PixelFormat.";
LPCWSTR Msgu_Cant_Set_PixelFormat;
 
char*   Msgc_Cant_Create_GL_Rendering_Context    = "Can't Create A GL Rendering Context.";
LPCWSTR Msgu_Cant_Create_GL_Rendering_Context;
 
char*   Msgc_Cant_Activate_GL_Rendering_Context  = "Can't Activate The GL Rendering Context.";
LPCWSTR Msgu_Cant_Activate_GL_Rendering_Context;
 
char*   Msgc_Initialization_Failed               = "Initialization Failed.";
LPCWSTR Msgu_Initialization_Failed;
 
char*   Msgc_Run_FullScreenMode	     		     = "Would You Like To Run In Fullscreen Mode?";
LPCWSTR Msgu_Run_FullScreenMode;
 
char*   Msgc_StartFullScreen					 = "Start FullScreen?";
LPCWSTR Msgu_StartFullScreen;
 
char*   Msgc_Lesson1							 = "Start FullScreen?";
LPCWSTR Msgu_Lesson1;
 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
 
void Conversion_MsgsChaineUnicode()
{
MultiByteToWideChar
(CP_ACP, 0,
 Msgc_Release_Of_DC_And_RC_Failed,
 strlen(Msgc_Release_Of_DC_And_RC_Failed)+1,
 Msgw_,
 sizeof(Msgw_)/sizeof(Msgw_[0])
 );
Msgu_Release_Of_DC_And_RC_Failed=Msgw_;
}
 
int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return TRUE;
}
 
 
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
return TRUE;
}
 
 
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
 
 
 
 
GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if (hRC)
{
if (!wglMakeCurrent(NULL,NULL))
{
 
MessageBox(NULL,Msgu_Release_Of_DC_And_RC_Failed,Msgu_Shutdown_Error,MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC))
{
MessageBox(NULL,Msgu_Release_Rendering_Context_Failed,Msgu_Shutdown_Error,MB_OK | MB_ICONINFORMATION);
}
hRC=NULL;
}
if (hDC && !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,Msgu_Release_Device_Context_Failed,Msgu_Shutdown_Error,MB_OK | MB_ICONINFORMATION);
hDC=NULL;
}
if (hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL,Msgu_Could_Not_Release_hWnd,Msgu_Shutdown_Error,MB_OK | MB_ICONINFORMATION);
hWnd=NULL;
}
if (!UnregisterClass(Msgu_OpenGL,hInstance))
{
MessageBox(NULL,Msgu_Could_Not_Unregister_Class,Msgu_Shutdown_Error,MB_OK | MB_ICONINFORMATION);
hInstance=NULL;
}
}
 
 
BOOL CreateGLWindow(/*char* title*/LPCWSTR title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
fullscreen=fullscreenflag;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = Msgu_OpenGL;
if (!RegisterClass(&wc))
{
MessageBox(NULL,Msgu_Failed_To_Register_The_Window_Class,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL,Msgu_Fullscreen_Not_Supported,Msgu_NeHe_GL,MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE;
}
else
{
MessageBox(NULL,Msgu_Program_Will_Now_Close,Msgu_ERROR,MB_OK|MB_ICONSTOP);
return FALSE;
}
}
}
if (fullscreen)
{
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
ShowCursor(FALSE);
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
if (!(hWnd=CreateWindowEx( dwExStyle,
Msgu_OpenGL,
title,
dwStyle |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN,
0, 0,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL,
NULL,
hInstance,
NULL)))
{
KillGLWindow();
MessageBox(NULL,Msgu_Window_Creation_Error,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
 
static PIXELFORMATDESCRIPTOR pfd=
{
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
bits, // 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 (!(hDC=GetDC(hWnd))) // getting Device Context
{
KillGLWindow();
MessageBox(NULL,Msgu_Cant_Create_GL_Device,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) //find a pixel format
{
KillGLWindow();
MessageBox(NULL,Msgu_Cant_Find_PixelFormat,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) //setting the pixel format
{
KillGLWindow();
MessageBox(NULL,Msgu_Cant_Set_PixelFormat,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if (!(hRC=wglCreateContext(hDC))) //get a Rendering Context.
{
KillGLWindow();
MessageBox(NULL,Msgu_Cant_Create_GL_Rendering_Context,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
if(!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,Msgu_Cant_Activate_GL_Rendering_Context,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
 
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
ReSizeGLScene(width, height);
 
if (!InitGL())
{
KillGLWindow();
MessageBox(NULL,Msgu_Initialization_Failed,Msgu_ERROR,MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
return TRUE;
}
// end of the function
 
 
 
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL done=FALSE;
Conversion_MsgsChaineUnicode();
if (MessageBox(NULL,Msgu_Run_FullScreenMode,Msgu_StartFullScreen,MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
	fullscreen=FALSE;
	}
if (!CreateGLWindow(Msgu_Lesson1,640,480,16,fullscreen))
	{
	return 0;
	}
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if (active)
{
DrawGLScene();
SwapBuffers(hDC);
}
}
}
KillGLWindow();
return (msg.wParam);
}

A l'édition de lien, j'ai une erreur LNK 2019 qui me dit :

1>main.obj : error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function "int __cdecl CreateGLWindow(wchar_t const *,int,int,int,bool)" (?CreateGLWindow@@YAHPB_WHHH_N@Z)
1>D:\Programmation Sous Windows\C++\Projets C++\Test_SDL\Debug\Test_SDL.exe : fatal error LNK1120: 1 unresolved externals
Je pense qu'il manque une librairie. Laquelle ?
Si vous pouviez m'éclairer ...

Merci à tous