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

  FORUM HardWare.fr
  Programmation
  C++

  Probleme affichage OpenGL avec MFC

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme affichage OpenGL avec MFC

n°789426
Ludobooz
Posté le 07-07-2004 à 17:53:59  profilanswer
 

Salut @ tous!
 
Voila je fais une appli où j'ai besoin d'avoir trois scenes OpenGl sur une même fenetre Windows gérée en MFC. Pour cela, j'ai créé 3 frames dans lesquelles je récupere le contexte graphique.
 
En fait j'ai une scene principale qui s'affiche sans aucuns problèmes et normalement un clic sur cette scene doit lancer l'affichage des 2 autres. ET LA C'est le drame ... RIEN! Pourtant je fais bien attention a changer le contexte courant pour que les affichages se fassent séquentiellement car ce ne sont pas des anums, mais rien y fait. J'ai même essayer de n'afficher que des carrés pour pas compliquer les choses mais bien sur ce la ne change rien :(...Si quelqu'un à une lumière sur mon problème je le remerci d'avance...
 
PS : lorsque je baisse l'accélération matérielle de ma machine, l'affichage est de retour...mais ca rame donc ca ne me va pas!! Pour info la carte graphique est une ATI Radeon 9200.
 
PS2: en changeant de carte graphique pour une ATI 7000, ca marche!
 
 
Ludo :)

mood
Publicité
Posté le 07-07-2004 à 17:53:59  profilanswer
 

n°789653
skeye
Posté le 07-07-2004 à 22:37:20  profilanswer
 

pb de drivers de la carte graphique là non? :??:


---------------
Can't buy what I want because it's free -
n°791605
Ludobooz
Posté le 09-07-2004 à 14:56:08  profilanswer
 

skeye a écrit :

pb de drivers de la carte graphique là non? :??:


 
Suite à ton message j'ai telechargé les derniers drivers de Ati et ca ne marche toujours pas!! Je pense que c'est plutot un pb de programmation mais je ne sais pas quelle est mon erreur...
Enfin c'est vrai que c'est tres etonnant que ca fonctionne avec d'autres cartes graphiques... :??:  
 

n°791608
skeye
Posté le 09-07-2004 à 14:56:54  profilanswer
 

Tu peux poster un bout de code?


---------------
Can't buy what I want because it's free -
n°793894
Ludobooz
Posté le 12-07-2004 à 18:06:23  profilanswer
 

Code :
  1. /*******************************************************************************************************************************/
  2. /*                                               Classe 3D                                                                     */
  3. /*                                                                                                                             */
  4. /* Cette classe permet de visualiser le volume constitué par une pile d'image. Elle offre également la possibilité d'afficher  */
  5. /* les coupes X-Z et Y-Z à partir d'un point donné.                                                                            */
  6. /*                                                                                                                             */
  7. /*******************************************************************************************************************************/
  8. #include "stdafx.h"
  9. #include "Deblurring.h"
  10. #include "Anim3D.h"
  11. #include "AVIGenerator.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. #define PI 3.14159265358979
  18. #define INITIAL 0
  19. #define CURRENT 1
  20. #define TOP 0
  21. #define BOTTOM 1
  22. #define LEFT 2
  23. #define RIGHT 3
  24. BOOL Anim3D::OnInitDialog()
  25. {
  26. CDialog::OnInitDialog();
  27. SetIcon(m_hIcon, TRUE);
  28. SetIcon(m_hIcon, FALSE);
  29. /*Mise en place de la fenêtre*/
  30. dispositionScene();
  31. /*----Initialisation de la fenêtre OpenGl---*/
  32. m_init = TRUE;
  33. CWnd * cwnd = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
  34. m_hgldc = ::GetDC(cwnd->m_hWnd);
  35.     if(!SetPixelformat(m_hgldc))
  36.     {
  37.  ::MessageBox(::GetFocus(),"SetPixelformat Failed!","Error",MB_OK);
  38.  return -1;
  39.     }
  40.     m_hglRC = wglCreateContext(m_hgldc);
  41.     wglMakeCurrent(m_hgldc,m_hglRC);
  42. InitGL();
  43. CRect rect;
  44. cwnd->GetWindowRect(&rect);
  45. ReSizeGLScene(rect.Width(), rect.Height());
  46. /*------- Initialisation des variables ------*/
  47. m_stack.m_seuil = m_seuil;
  48. m_stack.m_fileStack = this->m_fileList;
  49. m_stack.m_nbFile = this->m_nbFile;
  50. m_stack.m_ir = this->m_ir;
  51. m_stack.m_Na = this->m_Na;
  52. m_stack.m_lambda = this->m_lambda;
  53. m_stack.m_progressBar = m_progressBar;
  54. m_stack.loadImages();
  55. m_stack.makeScene(0);
  56. m_stack.makeScene(1);
  57. m_imgWidth = m_stack.m_width;
  58. m_imgHeight = m_stack.m_height;
  59. initCamera();
  60. /*------- Gestion des boutons outils --------*/
  61. m_button_coupe.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_COUPE));
  62. m_button_camera.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_INIT_VUE));
  63. m_button_avi.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_CAMERA));
  64. CString s ;
  65. {
  66.  /* Create the ToolTip control.*/
  67.  m_tooltip.Create(this);
  68.  m_tooltip.Activate(TRUE);
  69.  m_button_coupe.GetWindowText(s);
  70.  m_tooltip.AddTool((CWnd *)&m_button_coupe, s);
  71.  m_button_camera.GetWindowText(s);
  72.  m_tooltip.AddTool((CWnd *)&m_button_camera, s);
  73.  m_button_avi.GetWindowText(s);
  74.  m_tooltip.AddTool((CWnd *)&m_button_avi, s);
  75. }
  76. return TRUE;
  77. }
  78. void Anim3D::OnDestroy()
  79. {
  80. CDialog::OnDestroy();
  81. wglMakeCurrent(NULL,NULL);
  82.     wglDeleteContext(m_hglRC);
  83. wglDeleteContext(m_hglRC_YZ);
  84. wglDeleteContext(m_hglRC_XZ);
  85. }
  86. void Anim3D::OnLButtonDown(UINT nFlags, CPoint point)
  87. {
  88. m_oldX = point.x;
  89. m_oldY = point.y;
  90. if(IsDlgButtonChecked(IDC_CHECK_COUPE))
  91. {
  92.  CRect rect_frame;
  93.  CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
  94.  cwnd_frame->GetWindowRect(&rect_frame);
  95.  ScreenToClient(&rect_frame);
  96.  double proj[16],model[16];
  97.  int view[4];
  98.  double coordx, coordy, coordz;
  99.  glGetDoublev(GL_MODELVIEW_MATRIX,model);
  100.  glGetDoublev(GL_PROJECTION_MATRIX,proj);
  101.  glGetIntegerv(GL_VIEWPORT,view);
  102.  gluUnProject(point.x-rect_frame.left , point.y-rect_frame.top, 0.0, model, proj, view, &coordx, &coordy, &coordz);
  103.  drawCoupeYZ((int)coordx, (int)-coordy);
  104.  drawCoupeXZ((int)coordx, (int)-coordy);
  105.  wglMakeCurrent(m_hgldc,m_hglRC);
  106. }
  107. CDialog::OnLButtonDown(nFlags, point);
  108. }
  109. void Anim3D::OnMouseMove(UINT nFlags, CPoint point)
  110. {
  111. if(!IsDlgButtonChecked(IDC_CHECK_COUPE))
  112. {
  113.  if((nFlags == MK_LBUTTON)||(nFlags == MK_RBUTTON))
  114.  {
  115.   if( (nFlags == MK_LBUTTON) )
  116.   {
  117.    m_angleX = m_angleX + 0.5*(point.y - m_oldY);
  118.    m_angleY = m_angleY + 0.5*(point.x - m_oldX);
  119.   }
  120.   if(nFlags == MK_RBUTTON)
  121.   {
  122.    if(point.y<m_oldY)
  123.     m_tz+=20;
  124.    else
  125.     m_tz-=20;
  126.   }
  127.   m_oldX = point.x;
  128.   m_oldY = point.y;
  129.   PosEye(m_rx,m_ry,m_tz);
  130.   DrawGLScenePerspective();
  131.  }
  132. }
  133. else
  134. {
  135.  drawAxesCoupe(point);
  136. }
  137. }
  138. BOOL Anim3D::SetPixelformat(HDC hdc)
  139. {
  140.     PIXELFORMATDESCRIPTOR *ppfd;
  141.     int pixelformat;
  142.     PIXELFORMATDESCRIPTOR pfd =
  143. {
  144.  sizeof(PIXELFORMATDESCRIPTOR),  //  size of this pfd  
  145.  1,                     // version number  
  146.  PFD_DRAW_TO_WINDOW |   // support window  
  147.  PFD_SUPPORT_OPENGL |   // support OpenGL  
  148.  PFD_GENERIC_FORMAT |
  149.  PFD_DOUBLEBUFFER,      // double buffered  
  150.  PFD_TYPE_RGBA,         // RGBA type  
  151.  32,                    // 24-bit color depth  
  152.  0, 0, 0, 0, 0, 0,      // color bits ignored  
  153.  8,                     // no alpha buffer  
  154.  0,                     // shift bit ignored  
  155.  8,                     // no accumulation buffer  
  156.  0, 0, 0, 0,            // accum bits ignored  
  157.  64,                    // 32-bit z-buffer  
  158.  8,                     // no stencil buffer  
  159.  8,                     // no auxiliary buffer  
  160.     PFD_MAIN_PLANE,        // main layer  
  161.  0,                     // reserved  
  162.  0, 0, 0                // layer masks ignored  
  163.     };
  164.  
  165.     ppfd = &pfd;
  166.     if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
  167.     {
  168.         ::MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
  169.         return FALSE;
  170.     }
  171.     if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
  172.     {
  173.         ::MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
  174.         return FALSE;
  175.     }
  176.     return TRUE;
  177. }
  178. GLvoid Anim3D::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
  179. {
  180. glViewport(0,0,width,height);      // Reset The Current Viewport
  181. }
  182. int Anim3D::InitGL(GLvoid)
  183. {
  184. glShadeModel(GL_SMOOTH);       // Enable Smooth Shading
  185. glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
  186. glClearDepth(1.0f);         // Depth Buffer Setup
  187. glEnable(GL_DEPTH_TEST);       // Enables Depth Testing
  188. return TRUE;          // Initialization Went OK
  189. }
  190. void Anim3D::initCamera()
  191. {
  192. m_rx = -90;
  193. m_ry = 90;
  194. m_tz = 1700;
  195. PosEye(m_rx,m_ry,m_tz);
  196. m_angleX = m_angleY = m_angleZ = 0;
  197. }
  198. void Anim3D::PosEye(double teta,double phi,double T)
  199. {
  200. m_xe = T*sin(phi*PI/180)*cos(-teta*PI/180);
  201. m_ye = T*cos(phi*PI/180);
  202. m_ze = T*sin(phi*PI/180)*sin(-teta*PI/180);
  203. }
  204. int Anim3D::DrawGLScenePerspective(GLvoid)
  205. {
  206. CRect rect_frame;
  207. CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
  208. cwnd_frame->GetClientRect(&rect_frame);
  209. glMatrixMode(GL_PROJECTION);
  210. glLoadIdentity();
  211. gluPerspective( 45.0, /*rect_frame.Width()/rect_frame.Height()*/ m_imgWidth/m_imgHeight, 1, 10000.0);
  212. glMatrixMode(GL_MODELVIEW);
  213. glLoadIdentity();
  214. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  215. gluLookAt(m_xe,m_ye,m_ze,
  216.        0.0,0.0,0.0,
  217.     0.0,1.0,0.0);
  218. glRotatef(m_angleX,1,0,0);
  219. glRotatef(m_angleY,0,1,0);
  220. glRotatef(m_angleZ,0,0,1);
  221. m_stack.sceneDisplay(0);
  222. SwapBuffers(m_hgldc);
  223. return TRUE;
  224. }
  225. int Anim3D::DrawGLSceneOrtho(GLvoid)
  226. {
  227. glMatrixMode(GL_PROJECTION);
  228. glLoadIdentity();
  229. glOrtho(-m_imgWidth/2 - 5, m_imgWidth/2 + 5, -m_imgHeight/2 - 5, m_imgHeight/2 + 5, -m_nbFile/2 - 5, m_nbFile/2 + 5);
  230. glMatrixMode(GL_MODELVIEW);
  231. glLoadIdentity();
  232. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  233. glRotatef(m_angleX,1,0,0);
  234. glRotatef(m_angleY,0,1,0);
  235. glRotatef(m_angleZ,0,0,1);
  236. m_stack.sceneDisplay(1);
  237. SwapBuffers(m_hgldc);
  238. return TRUE;
  239. }
  240. /*Permet d'afficher les axes de coupes*/
  241. void Anim3D::drawAxesCoupe(CPoint point)
  242. {
  243. CRect rect_frame;
  244. CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
  245. cwnd_frame->GetWindowRect(&rect_frame);
  246. ScreenToClient(&rect_frame);
  247. double proj[16],model[16];
  248. int view[4];
  249. glGetDoublev(GL_MODELVIEW_MATRIX,model);
  250. glGetDoublev(GL_PROJECTION_MATRIX,proj);
  251. glGetIntegerv(GL_VIEWPORT,view);
  252. if( (point.x >= rect_frame.left) && (point.x <= rect_frame.right) && (point.y >= rect_frame.top) && (point.y <= rect_frame.bottom))
  253. {
  254.  double coordx, coordy, coordz;
  255.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  256.  gluUnProject(point.x-rect_frame.left , point.y-rect_frame.top, 0.0, model, proj, view, &coordx, &coordy, &coordz);
  257.  DrawGLSceneOrtho();
  258.  glColor3f(1.0,1.0,1.0);
  259.  glBegin(GL_LINES);
  260.   glVertex3f(coordx, -m_imgHeight/2, m_nbFile/2 + 5);
  261.   glVertex3f(coordx, m_imgHeight/2, m_nbFile/2 + 5);
  262.  glEnd();
  263.  glBegin(GL_LINES);
  264.   glVertex3f(-m_imgWidth/2, -coordy, m_nbFile/2 + 5);
  265.   glVertex3f(m_imgWidth/2, -coordy, m_nbFile/2 + 5);
  266.  glEnd();
  267.  glFlush();
  268.  SwapBuffers(m_hgldc);
  269. }
  270. }
  271. void Anim3D::initGLCoupes()
  272. {
  273. CWnd * coupeYZ = GetDlgItem(IDC_STATIC_COUPEYZ);
  274. CWnd * coupeXZ = GetDlgItem(IDC_STATIC_COUPEXZ);
  275. m_hdc_YZ = ::GetDC(coupeYZ->m_hWnd);
  276. m_hdc_XZ = ::GetDC(coupeXZ->m_hWnd);
  277. SetPixelformat(m_hdc_YZ);
  278. SetPixelformat(m_hdc_XZ);
  279.  
  280.     m_hglRC_YZ = wglCreateContext(m_hdc_YZ);
  281. m_hglRC_XZ = wglCreateContext(m_hdc_XZ);
  282. }
  283. void Anim3D::drawCoupeYZ(int x, int y)
  284. {
  285. CRect rect;
  286. CWnd * coupeYZ = GetDlgItem(IDC_STATIC_COUPEYZ);
  287. coupeYZ->GetClientRect(&rect);
  288. wglMakeCurrent(m_hdc_YZ,m_hglRC_YZ);
  289. InitGL();
  290. ReSizeGLScene(rect.Width(), rect.Height());
  291. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  292. glMatrixMode(GL_PROJECTION);
  293. glLoadIdentity();
  294. glOrtho(-30, 30, -m_imgHeight/2, m_imgHeight/2, -10, 10);
  295. glMatrixMode(GL_MODELVIEW);
  296. glLoadIdentity();
  297. m_stack.coupeYZDisplay(x, y);
  298. SwapBuffers(m_hdc_YZ);
  299. }
  300. void Anim3D::drawCoupeXZ(int x, int y)
  301. {
  302. CRect rect;
  303. CWnd * coupeXZ = GetDlgItem(IDC_STATIC_COUPEXZ);
  304. coupeXZ->GetClientRect(&rect);
  305. wglMakeCurrent(m_hdc_XZ,m_hglRC_XZ);
  306. InitGL();
  307. ReSizeGLScene(rect.Width(), rect.Height());
  308. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  309. glMatrixMode(GL_PROJECTION);
  310. glLoadIdentity();
  311. glOrtho(-m_imgWidth/2, m_imgWidth/2, -30, 30, -10, 10);
  312. glMatrixMode(GL_MODELVIEW);
  313. glLoadIdentity();
  314. m_stack.coupeXZDisplay(x, y);
  315. SwapBuffers(m_hdc_XZ);
  316. }


 
 
 
Voila le code ... j'ai enlevé des bouts qui ne servent pas à la comprehension et qui n'ont rien à voir avec mon problème.
Merci d'avance
 
@++


Message édité par Ludobooz le 13-07-2004 à 09:05:13
n°794040
Joel F
Real men use unique_ptr
Posté le 12-07-2004 à 22:31:50  profilanswer
 

utilise les balises [ code] stp >.< [:everything4free]

n°794214
gilou
Modérateur
Modzilla
Posté le 13-07-2004 à 09:06:18  profilanswer
 

Il avait oublié la balise fermante, que je viens de rajouter.
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°794215
Joel F
Real men use unique_ptr
Posté le 13-07-2004 à 09:07:39  profilanswer
 

c'est presque ca gilou ^^ :
 
void Anim3D:<img src="/images/biggrin.gif" alt=":D" title=":D" />rawCoupeYZ(int x, int y)
 
Sino n : j'ai comilé la chose, j'ai pas de pb.
Tu es sur de tes drivers ?

n°798475
yawen
Posté le 17-07-2004 à 13:43:52  profilanswer
 

si j'ai bien compris, tu utilise une carte ATI ? je voudrais pas faire de la mauvaise pub, mais les drivers d'ATI, c'est pas toujours ça... possible que ça vienne de là (j'avoue que j'ai jamais eu autre chose qu'une ATI, donc peut-être que les drivers ne sont pas mieux sur les autre marques...)

n°799059
retrox
Posté le 18-07-2004 à 22:31:35  profilanswer
 

Methode SetPixelFormat
Je note que le bit PFD_GENERIC_FORMAT est mis. Ca me parait plus que bizarre. En mettant ce bit, on demande spécifiquement un format utilisant l'implémentation générique, c'est à dire l'implémentation software via GDI de Microsoft. Donc à mon avis, il vaut mieux l'enlever. Ne pas mettre non plus PFD_GENERIC_ACCELERATED qui correspond à un MCD, de toutes façons il n'y en a plus sur le marché. Un PixelFormat pris en charge par un ICD n'a ni PFD_GENERIC_FORMAT, ni PFD_GENERIC_ACCELERATED.
Je note aussi dans le pixelformat demandé :  
accumulation buffer de 8 bits -> est-ce vraiment utilisé?
un z-buffer de 64 bits -> ça n'existe nulle part à ma connaissance
8 aux buffers -> est-ce vraiment utilisé?
 
D'une façon générale, plus on est précis dans ce qu'on demande, plus on a de chances d'etre bien servi. ChoosePixelFormat va chercher le format le plus proche de la demande, ça ne veut pas dire que ce sera exactement ce qui était demandé. Une bonne habitude est de vérifier ce qu'on obtient en utilisant DescribePixelFormat.
 
Autre chose : je n'ai pas vu ou était appelée la méthode initGLCoupes(). A premiere vue elle devrait etre appelée lors de la création de la boite de dialogue non?(ie dans OnInitDialog, la ou est créée l'autre fenetre OpenGL)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  Probleme affichage OpenGL avec MFC

 

Sujets relatifs
[MFC] differente s couleurs dans une CTreeViewespace entre les lignes d'un tableau, problème avec mozilla [résolu]
probleme makefile c++Probleme avec explorer ou mozilla
Probleme d'acces Oracle Management ServerProbleme pour ecrie un algorithme
wxFileName problèmeProblème d'affichage ( Rien ne s'affiche )
Problème de taille de la barre de défilement sur iframe 
Plus de sujets relatifs à : Probleme affichage OpenGL avec MFC


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR