Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2956 connectés 

 


Dernière réponse
Sujet : [opengl&& c++builder] initialisation de la fenetre
antp :heink:
ouais mais bon moi ça m'arrange pas spécialement non plus hein :p

Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
antp :heink:
ouais mais bon moi ça m'arrange pas spécialement non plus hein :p
farib ca marche
 
antp, je vais devenir payday rien ke pour toi :D
farib EXACTEMENT ?
antp         case WM_CREATE:  
-> onCreate
 
          case WM_CLOSE:
-> onClose
 
          case WM_SIZE:  
-> onResize
 
          case WM_PAINT:  
-> onPaint
 
:D
farib que ca affiche
 
 
sinon ca c le code api win32 sous devc++, qui marche et que j'ai essayé d'adapter sous builder
 

Code :
  1. #include <windows.h>
  2. #include <gl/gl.h>
  3. #include <gl/glu.h>
  4. WNDCLASS wc;   // ma classe de fenetre
  5. HWND hWnd;     // le handle de ma fenetre
  6. HDC DC;    //Device Context (DC)  
  7. HGLRC RC;  //Rendering Context (RC)  
  8. void RePaint ()
  9. {
  10. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // On efface le Z-buffer  
  11. glMatrixMode (GL_MODELVIEW);
  12. glLoadIdentity ();
  13. gluLookAt (7,7,-10,0,0,0,0,1,0);
  14. glBegin(GL_LINES);
  15. glColor3d (0,0,0);
  16. glVertex3i (-1,-1,1);
  17. glVertex3i (-1,1,1);
  18. glVertex3i (1,1,1);
  19. glVertex3i (1,-1,1);
  20. glVertex3i (-1,-1,-1);
  21. glVertex3i (-1,1,-1);
  22. glVertex3i (1,1,-1);
  23. glVertex3i (1,-1,-1);
  24. glVertex3i (-1,1,-1);
  25. glVertex3i (1,1,-1);
  26. glVertex3i (1,1,1);
  27. glVertex3i (-1,1,1);
  28. glVertex3i (-1,-1,-1);
  29. glVertex3i (1,-1,-1);
  30. glVertex3i (1,-1,1);
  31. glVertex3i (-1,-1,1);
  32. glVertex3i (-1,-1,-1);
  33. glVertex3i (-1,-1,1);
  34. glVertex3i (-1,1,1);
  35. glVertex3i (-1,1,-1);
  36. glVertex3i (1,-1,-1);
  37. glVertex3i (1,-1,1);
  38. glVertex3i (1,1,1);
  39. glVertex3i (1,1,-1);
  40. glEnd();
  41. glBegin (GL_QUADS);
  42. glColor3d (0,1,1);glVertex3i (-1,-1,1);
  43. glColor3d (1,0,0);glVertex3i (-1,1,1);
  44. glColor3d (0,1,0);glVertex3i (1,1,1);
  45. glColor3d (1,0,1);glVertex3i (1,-1,1);
  46. glColor3d (0,0,1);glVertex3i (-1,-1,-1);
  47. glColor3d (1,1,0);glVertex3i (-1,1,-1);
  48. glColor3d (1,1,1);glVertex3i (1,1,-1);
  49. glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);
  50. glColor3d (1,1,0);glVertex3i (-1,1,-1);
  51. glColor3d (1,1,1);glVertex3i (1,1,-1);
  52. glColor3d (0,1,0);glVertex3i (1,1,1);
  53. glColor3d (1,0,0);glVertex3i (-1,1,1);
  54. glColor3d (0,0,1);glVertex3i (-1,-1,-1);
  55. glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);
  56. glColor3d (1,0,1);glVertex3i (1,-1,1);
  57. glColor3d (0,1,1);glVertex3i (-1,-1,1);
  58. glColor3d (0,0,1);glVertex3i (-1,-1,-1);
  59. glColor3d (0,1,1);glVertex3i (-1,-1,1);
  60. glColor3d (1,0,0);glVertex3i (-1,1,1);
  61. glColor3d (1,1,0);glVertex3i (-1,1,-1);
  62. glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);
  63. glColor3d (1,0,1);glVertex3i (1,-1,1);
  64. glColor3d (0,1,0);glVertex3i (1,1,1);
  65. glColor3d (1,1,1);glVertex3i (1,1,-1);
  66. glEnd();
  67. SwapBuffers (DC);
  68. }
  69. void InitPixelFormat (HDC hDC)
  70. {
  71. PIXELFORMATDESCRIPTOR pfd =
  72. { sizeof (PIXELFORMATDESCRIPTOR), 1, PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
  73. 16,
  74. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  75. 16,
  76. 0, 0, 0, 0, 0, 0, 0
  77. };
  78. SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
  79. }
  80. LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  81. {
  82. switch (uMsg)
  83. {
  84.     case WM_CREATE:
  85.         DC=GetDC (hwnd);
  86.         InitPixelFormat (DC);
  87.         RC = wglCreateContext (DC);
  88.         wglMakeCurrent (DC, RC);
  89.         glEnable (GL_DEPTH_TEST);
  90.         glClearColor (0,0,1,0);
  91.         break;
  92.     case WM_CLOSE:
  93.         wglMakeCurrent (NULL, NULL);
  94.         wglDeleteContext (RC);
  95.         ReleaseDC (hwnd,DC); 
  96.        
  97.         PostQuitMessage (0);
  98.         break;
  99.     case WM_SIZE:
  100.         glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
  101.         glMatrixMode (GL_PROJECTION);
  102.         glLoadIdentity ();
  103.         gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD (lParam)),1,100);
  104.         break;
  105.     case WM_PAINT:
  106.         RePaint ();
  107.         break
  108.     default:
  109.         return DefWindowProc (hwnd,uMsg,wParam,lParam);
  110.         break;
  111. }
  112. return 0;
  113. }
  114. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
  115. {
  116.     wc.style = CS_OWNDC;
  117.     wc.lpfnWndProc = WindowProc;
  118.     wc.cbClsExtra = 0;
  119.     wc.cbWndExtra = 0;
  120.     wc.hInstance = hInstance;
  121.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  122.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  123.     wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  124.     wc.lpszMenuName = NULL;
  125.     wc.lpszClassName = "OGL";
  126.     RegisterClass(&wc);
  127.     hWnd = CreateWindow("OGL", "Fenetre OpenGL",WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,0, 0, 640, 480, NULL, NULL, hInstance, NULL );
  128. // on crée la fenetre
  129. MSG msg;
  130. while (GetMessage (&msg, NULL, 0, 0))
  131. {
  132.     TranslateMessage (&msg);
  133.     DispatchMessage (&msg);
  134. }
  135. return 0;
  136. }

antp onCreate c'est au moment où il crée en mémoire la Form
puis y a OnShow qui arrive juste avant l'affichage
OnActivate au moment où la fenêtre devient active
OnIdle quand le programme n'a plus rien à faire
 
Mais je vois pas trop ce que tu veux en fait :D
Harkonnen Je vais pas bcp t'aider, mais j'ai eu ma période OpenGL sous Windows, et avec les IDE, je me suis toujours emmerdé pour faire afficher quoi que ce soi-.
 
Ce que je te conseille, c'est de passer par GLut pour l'affichage, à mon avis tu te casseras moins la tête qu'avec Win32.
 
:hello:
farib j'ai trouvé les exemples sur le tres bon www.glinfrench.fr.st  
et j'ai compilé avec dev c++  
 
 
j'ai essayé de passer sous builder, en regardant les deux examplse opengl fournis avec le soft, mais je comprend pas trop, je me demande si la gestion de la boucle via builder est différente que lorsqu'on programme directement l'api win32 et doit entrainer une modification au niveau opengl ???  
 
paske ca n'affiche rien....  
 
faut il que je considere un onidle, que je réactualise l'affichage, ou autre ?  
 
Code:  
 

Code :
  1. void InitPixelFormat (HDC hDC)
  2. {
  3. PIXELFORMATDESCRIPTOR pfd =
  4. { sizeof (PIXELFORMATDESCRIPTOR), 1, PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
  5. 16,
  6. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  7. 16,
  8. 0, 0, 0, 0, 0, 0, 0
  9. };
  10. SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
  11. }
  12. void __fastcall TForm1::FormCreate(TObject *Sender)
  13. {
  14.         DC=GetDC (Handle);
  15.         InitPixelFormat (DC);
  16.         RC = wglCreateContext (DC);
  17.         wglMakeCurrent (DC, RC);
  18.         glEnable (GL_DEPTH_TEST);
  19.         glClearColor (0,0,1,0);
  20.         glViewport (0,0,ClientWidth,ClientHeight);
  21.         glMatrixMode (GL_PROJECTION);
  22.         glLoadIdentity ();
  23.         gluPerspective (45,(float)(ClientWidth)/(float)(ClientHeight),1,100);
  24. //dsfdsfsdfsdfsdf  
  25. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // On efface le Z-buffer  
  26. glMatrixMode (GL_MODELVIEW);
  27. glLoadIdentity ();
  28. gluLookAt (7,7,-10,0,0,0,0,1,0);
  29. glBegin(GL_LINES);
  30. //[....] mes dessins (qui marchent)  
  31. glEnd();
  32. SwapBuffers (DC);
  33. }
  34. //---------------------------------------------------------------------------  
  35. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  36. {
  37.         wglMakeCurrent (NULL, NULL);
  38.         wglDeleteContext (RC);
  39.         ReleaseDC (Handle,DC);
  40. }


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)