LANGAGE : C++/OpenGL-glut-glui
ENVIRONNEMENT : Cygwin
COMPILATEUR : G++
DEBUGGEUR : GDB

Hello tout le monde,

Je voudrais effectuer un rendu OpenGL directement dans une bitmap sans passer par le rendu sur l'écran car la résolution de cette bitmap doit être supérieure à celle de mon écran. D'après ce que j'ai lu sur
voir http://www.mesa3d.org/brianp/sig97/offscrn.htm
je dois utiliser la WGL. Hélas je ne connais rien du tout à la bibliothèque gdi32 : j'ai besoin de votre aide

J'ai essayé de me dépatouiller avec ce que j'ai pu trouver comme info sur le net, et j'ai développé le code suivant. Malheureusement, setPixelFormat renvoie FALSE et je récupère mon objet de type "mon_image" est une image 1000x1000 noire.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
  HGLRC * renderingContext=(HGLRC *)malloc(sizeof(HGLRC));
  HDC * deviceContext = (HDC *)malloc(sizeof(HDC));
  setGDI(*renderingContext, *deviceContext); 
  ... //rendu OpenGL
  mon_image im(1000,1000, COULEURS );
  readHBITMAP(*deviceContext,im );
  wglMakeCurrent(0,0);
  wglDeleteContext(*renderingContext);
  im.creer_image("visibilite.ppm");
mon_image est une classe que j'ai developper pour l'export et l'import d'images. Quant aux autres fonctions que vous ne connaissez pas, elles sont en dessous :

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
//-------------------------------------------------------------------------------
void setGDI(HGLRC& glMemRC, HDC& glMemDC){
  glMemDC=CreateCompatibleDC(NULL);
  UINT * ptPixels;
  HBITMAP memBitmap = createDeviceIndependantBitmap(glMemDC, ptPixels);
  if(memBitmap==0) {
    cerr<<"CreateDeviceIndependantBitmap error"<<endl; 
    return;&#125;
  setPixelFormat&#40;glMemDC&#41;;
  glMemRC=wglCreateContext&#40;glMemDC&#41;; 
  SelectObject&#40;glMemDC, memBitmap&#41;;
  wglMakeCurrent&#40;glMemDC,glMemRC&#41;; &#125;
//-------------------------------------------------------------------------------
HBITMAP createDeviceIndependantBitmap&#40;HDC& deviceContext, UINT * ptPixels&#41;&#123;
  BITMAPINFO RGB8BitsBITMAPINFO; 
  ZeroMemory&#40;&RGB8BitsBITMAPINFO,sizeof&#40;BITMAPINFO&#41;&#41;;
  RGB8BitsBITMAPINFO.bmiHeader.biSize=sizeof&#40;BITMAPINFOHEADER&#41;;
  RGB8BitsBITMAPINFO.bmiHeader.biWidth=1000;
  RGB8BitsBITMAPINFO.bmiHeader.biHeight=1000;
  RGB8BitsBITMAPINFO.bmiHeader.biPlanes=1;
  RGB8BitsBITMAPINFO.bmiHeader.biBitCount=8;
  HBITMAP  memBitmap = CreateDIBSection&#40;deviceContext, 
					&#40;BITMAPINFO *&#41;&RGB8BitsBITMAPINFO, 
					DIB_RGB_COLORS,
					&#40;void **&#41;&ptPixels, 
					NULL, 0&#41;;
  return memBitmap;&#125;
//-------------------------------------------------------------------------------
void setPixelFormat&#40;HDC& deviceContext&#41;&#123;
  PIXELFORMATDESCRIPTOR pfd = &#123; 
    sizeof&#40;PIXELFORMATDESCRIPTOR&#41;,   // size of this pfd 
    1,                     // version number 
    PFD_DRAW_TO_BITMAP |   // support window 
    PFD_SUPPORT_OPENGL |   // support OpenGL 
    PFD_SUPPORT_GDI,      // double buffered 
    PFD_TYPE_RGBA,         // RGBA type 
    8,                    // 24-bit 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,            // accum bits ignored 
    0,                    // 32-bit z-buffer 
    0,                     // no stencil buffer 
    0,                     // no auxiliary buffer 
    PFD_MAIN_PLANE,        // main layer 
    0,                     // reserved 
    0, 0, 0                // layer masks ignored 
  &#125;;
  int pixelFormatIndex = ChoosePixelFormat&#40;deviceContext, &pfd&#41;;
  if&#40;pixelFormatIndex==0&#41;
    cerr<<"ChoosePixelFormatt error"<<endl;
  bool r = SetPixelFormat&#40;deviceContext,pixelFormatIndex,&pfd&#41;;
  if&#40;r!=TRUE&#41; &#123;cerr<<"setPixelFormat error"<<endl;&#125;&#125;
//-------------------------------------------------------------------------------
void readHBITMAP&#40;HDC& deviceContext, mon_image& im&#41; &#123;
  RGBQUAD * pColors = &#40;RGBQUAD *&#41;malloc&#40;1000000*sizeof&#40;RGBQUAD *&#41;&#41;;
  int success = GetDIBColorTable&#40;deviceContext, 0,  1000000, pColors&#41;;
  if&#40;success ==0&#41;&#123;
    cerr << "readHBITMAP error"<<endl;&#125;
  else&#123;
  for&#40;int i=0; i<1000; i++&#41;
    for&#40;int j=0; j<1000; j++&#41;&#123;
      im.set_rouge&#40;i, j&#41; =  pColors&#91;i*1000+j&#93;.rgbRed;
      im.set_bleu&#40;i, j&#41; =  pColors&#91;i*1000+j&#93;.rgbBlue;
      im.set_vert&#40;i, j&#41; =  pColors&#91;i*1000+j&#93;.rgbGreen;&#125;&#125;&#125;
//-------------------------------------------------------------------------------
C'est tout... merci beaucoup par avance pour votre aide!