Probleme openGl niveau debutant

cs_AmK Messages postés 368 Date d'inscription jeudi 13 mars 2003 Statut Membre Dernière intervention 27 janvier 2010 - 16 avril 2003 à 13:22
cs_payen Messages postés 252 Date d'inscription mercredi 25 octobre 2000 Statut Membre Dernière intervention 1 mai 2005 - 16 avril 2003 à 14:11
salut je debute en openGL et j'ai du mal a creer une fenetre le compilateur me mets 2 erreurs :

PS: les erreurs du compilateur(vc++ 6.0)sont plus bas !

// debut du code

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

HWND hWnd;
WNDCLASS wc;
MSG msg;
HDC DC;
HGLRC RC;

void RePaint ()
{
glClear (GL_COLOR_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

SwapBuffers (DC);
}

void InitPixelFormat (HDC hDC)
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
16,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16,
0, 0, 0, 0, 0, 0, 0
};

SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
}

LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
RC=wglCreateContext(DC);

wgMakeCurrent(DC,RC);

switch(uMsg)
{
case WM_CREATE:
DC=GetDC(hWnd);
InitPixelFormat(HDC);

break;

case WM_SIZE:
glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD (lParam)),1,100);
break;

case WM_PAINT :
RePaint();
break;

case WM_CLOSE :
wglMakeCurrent(NULL,NULL);
wglDeleteContext(RC);
ReleaseDC(hWnd,DC);
PostQuitMessage(0);

break;

default :
return DefWindowProc(hWnd,uMsg,wParam,lParam);
break;
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int CmdShow)

{

wc.style = CS_OWNDC;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "OGL";

RegisterClass(&wc);

hWnd=CreateWindow("OGL","Fenetre OpenGl",WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,0,0,640,480,NULL,NULL,hInstance,NULL);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;

}

// fin du code

--------------------Configuration: sdf - Win32 Debug--------------------
Compiling...
sdf.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\jesis\sdf.cpp(46) : error C2065: 'wgMakeCurrent' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\jesis\sdf.cpp(51) : error C2275: 'HDC' : illegal use of this type as an expression
c:\program files\microsoft visual studio\vc98\include\windef.h(239) : see declaration of 'HDC'
Error executing cl.exe.

sdf.exe - 2 error(s), 0 warning(s)

merci de me dire ou sont les erreurs ! :)

1 réponse

cs_payen Messages postés 252 Date d'inscription mercredi 25 octobre 2000 Statut Membre Dernière intervention 1 mai 2005
16 avril 2003 à 14:11
si c'est juste une fenetre que tu veux creer, tu te compliques mechamment la vie! Code pris sur http://www.linuxgraphic.org/section3d/openGL/didact.html

#include <GL/glut.h>

void affichage();
void clavier(unsigned char touche,int x,int y);

int main(int argc,char **argv)
{

/* initialisation de glut et creation
de la fenetre */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowPosition(200,200);
glutInitWindowSize(250,250);
glutCreateWindow("ogl1");

/* Initialisation d'OpenGL */
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glPointSize(2.0);
/* enregistrement des fonctions de rappel */
glutDisplayFunc(affichage);
glutKeyboardFunc(clavier);

/* Entree dans la boucle principale glut */
glutMainLoop();
return 0;
}

void affichage()
{
/* effacement de l'image avec la couleur de fond */
glClear(GL_COLOR_BUFFER_BIT);

/* Dessin du polygone */
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.5,-0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.5,-0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.5,0.5);
glColor3f(1.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();

/* on force l'affichage du resultat */
glFlush();
}

void clavier(unsigned char touche,int x,int y)
{
switch (touche)
{
case 'p': /* affichage du carre plein */
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glutPostRedisplay();
break;
case 'f': /* affichage en mode fil de fer */
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutPostRedisplay();
break;
case 's' : /* Affichage en mode sommets seuls */
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay();
break;
case 'q' : /*la touche 'q' permet de quitter le programme */
exit(0);
}
}

ca me semble plus simple a comprendre que tn premier code ...
0
Rejoignez-nous