Results 1 to 6 of 6

Thread: Help!!! OpenGl and CreateDIBSection

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    3

    Help!!! OpenGl and CreateDIBSection

    what's wrong with the code:


    hdc = GetDC(hWnd); // creating bitmaps in memory with size of client area

    // GlPlane
    GlPlane.hdcMem = CreateCompatibleDC(hdc);

    BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    BitmapInfo.bmiHeader.biWidth = cxClient;
    BitmapInfo.bmiHeader.biHeight = cyClient;
    BitmapInfo.bmiHeader.biPlanes = 1;
    BitmapInfo.bmiHeader.biBitCount = 24;
    BitmapInfo.bmiHeader.biCompression = BI_RGB;
    BitmapInfo.bmiHeader.biSizeImage = 0;
    BitmapInfo.bmiHeader.biClrUsed = 0;
    BitmapInfo.bmiHeader.biClrImportant = 0;
    BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
    BitmapInfo.bmiHeader.biYPelsPerMeter = 0;


    GlPlane.hBitmap = CreateDIBSection(hdc,&BitmapInfo,DIB_RGB_COLORS,&p Bits,NULL,0);
    SelectObject(GlPlane.hdcMem,GlPlane.hBitmap);

    memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR)) ;
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iPixelFormat = ChoosePixelFormat(GlPlane.hdcMem,&pfd);
    SetPixelFormat(GlPlane.hdcMem,iPixelFormat,&pfd);

    hrc = wglCreateContext(GlPlane.hdcMem);
    wglMakeCurrent(GlPlane.hdcMem,hrc);


    glViewport(0, 0, cxClient, cyClient);
    glLoadIdentity();
    glOrtho(0.0f, cxClient, 0.0f, cyClient, 1.0f, -1.0f);

    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0f, 0.0f, 0.0f);
    glRectf(100.0f, 100.0f, 200.0f, 200.0f);
    glFlush();
    GdiFlush();
    BitBlt(hdc,0,0,cxClient,cyClient,GlPlane.hdcMem,0, 0,SRCCOPY);

    ReleaseDC(hWnd,hdc);


    i got rendering context but it doesn't want to draw on the bitmap
    or maybe the bitmap has size of 0????
    help needed urgently

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    London, UK (but from France)
    Posts
    125

    Re: Help!!! OpenGl and CreateDIBSection

    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    try pfd.cColorBits = 32;

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    6

    Re: Help!!! OpenGl and CreateDIBSection

    This is a guess, but is it possible that there's some 24/32bit incompatability happening? try making a 32bit color bitmap

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    3

    Re: Help!!! OpenGl and CreateDIBSection

    i tried it and nothing

    i think it's something its bitmap problem because GDI FillRect function doesn't work also

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2001
    Posts
    15

    Re: Help!!! OpenGl and CreateDIBSection

    Hi,
    I do the following and it works

    GlMemDC = CreateCompatibleDc(NULL);
    memBitmap = CreateDIBSection(0,BitmapInfo,DIB_RGB_COLORS,&pBit s,NULL,0);
    OldmemBitmap = SelectObject(GlMemDc, memBitmap);

    DPS

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Loveland, CO, USA
    Posts
    2

    Re: Help!!! OpenGl and CreateDIBSection

    try adding a glMatrixMode( GL_PROJECTION) after glViewport and before glLoadIdentity.

    Also, if I understand correctly, the values in glOrtho should be the user data (which you specify when drawing), not the Window client coordinates, unless you want them to be the same. For example, glViewport should have the dimensions of the window client area (in client coordinates), and the glOrtho should have the dimensions of the object to draw in user coordinates (e.g. 10000, 20000, -20000, ...)

    I hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean