dletozeun
Messages postés
546
Date d'inscription
vendredi 13 février 2004
Statut
Membre
Dernière intervention
9 janvier 2008
1
31 juil. 2004 à 15:20
ok je la met en entier:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
HDC DC;
HGLRC RC;
void SetupPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), //taille du descripteur de format
1, //version
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, //Propriétés
PFD_TYPE_RGBA, //Mode de couleurs
16, //Bits de couleur
0, 0, 0, 0, 0, 0, //Paramètres des couleurs
0,0, //Paramètres alpha
0,0, 0, 0, 0, //Paramètres du buffer d'accumulation
32, //Bits de profondeur
0, //Bits du buffer stencil
0, //Nombre de buffers auxiliaires
0, //ignoré (obsolète)
0, //réservé
0, //ignoré (obsolète)
0, //Couleur de transparence
0 //Ignoré (obsolète)
};
int pixelFormat;
pixelFormat = ChoosePixelFormat(hDC, &pfd);
if (!pixelFormat)
{
MessageBox
(
WindowFromDC(hDC),
"Mode graphique non supporté.",
"Problème",
MB_ICONERROR | MB_OK
);
exit(1);
/*Vérifie si un PixelFormat du type demandé existe*/
}
if (!SetPixelFormat(hDC, pixelFormat, &pfd))
{
MessageBox
(
WindowFromDC(hDC),
"Mode graphique non supporté.",
"Problème",
MB_ICONERROR | MB_OK
);
exit(1);
/*Applique le PixelFormat. Arrête si erreur*/
}
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam )
{
switch(uMsg)
{
case WM_CLOSE:
wglMakeCurrent(NULL, NULL);
if (RC) wglDeleteContext(RC);
ReleaseDC(hwnd,DC);
PostQuitMessage(0);
break;
//Libère RC et DC et ferme le programme
case WM_CREATE:
DC=GetDC(hwnd);
SetupPixelFormat(DC);
RC = wglCreateContext(DC);
if (!RC) SendMessage(hwnd,WM_CLOSE,0,0);
wglMakeCurrent(DC, RC);
break;
//Récupère le DC et le RC
default:
return DefWindowProc(hwnd,
uMsg,
wParam,
lParam);
break;
//Sinon, fait le truc habituel
}
}
void Draw()
{
glMatrixMode(GL_MODELVIEW);
gluLookAt(0,2,3,0,0,0,0,1,0);
glBegin(GL_LINES);
glVertex2i(0,0);glVertex2i(0,1);
glVertex2i(0,0);glVertex2i(1,0);
glVertex2i(0,0);glVertex3i(0,0,1);
glEnd();
SwapBuffers(DC);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HINSTANCE HInst = hInstance; //HInst est un variable globale de type HINSTANCE
WNDCLASS WindowClass =
{ 0, //Style
WinProc, //Procédure pour la gestion des messages
0, //octets supplémentaires à allouer à la classe
0, //octets supplémentaires à allouer à la fenêtre
HInst, //Handle du programme
0, //Icône
0, //Curseur
0, //Couleur d'arrière-plan
NULL, //Pointeur sur le menu associé à la classe
"La classe!" //Nom de la classe fenêtre
};
if (!RegisterClass(&WindowClass)) exit(1);
HWND OpenGLWindow = CreateWindow
( "La classe!", //Classe de la fenêtre
"Fenêtre OpenGL", //Nom de la fenêtre
WS_VISIBLE | WS_BORDER, //Caractéristiques
0, //Position x
0, //Position y
800, //Largeur
600, //Hauteur
0, //Handle de la fenêtre mère
0, //Identifiant de la fenêtre fille
HInst, //HINSTANCE du programme
NULL /*Chaine de caractère envoyée
en paramètre lors de la création
de la fenêtre*/
);
MSG msg;
do
{
while (PeekMessage(&msg,OpenGLWindow,0,0,PM_NOREMOVE))
{
if(!GetMessage(&msg,OpenGLWindow,0,0)) exit(0);
DispatchMessage(&msg);
Draw();
}
}
while(1);
}
J'espere que vous pouvez m'aider....