Thread: 2-D background bitmap behind a 3D wold using OpenGL

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    2-D background bitmap behind a 3D wold using OpenGL

    HI,
    can any one tell me that how can i apply 2-D bitmap behind a 3D Scene in OpenGL.
    Thanks!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What do you mean "behind a 3D scene" , do you mean you want a background to appear 2D? Just put a texture on a 2D plane. Position it with the appropriate Z coordinate and you should be set.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    What wizard said, wrap the background around a quad and
    put that faaaaar away in the z axis so it never melts with
    any oter rendered things

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    I have forget that code, once I was reading someone's code in which the OpenGL programmer Set his View Port to 2D He Pushed the Matrix and made a quad applied a .bmp texture to it and then Poped the matrix and then set the view port to 3D that was a nice trick really, i am looking for exactly same one.....

    ... thanks in advance

  5. #5
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    This would work with direct3d and probably openGl too. Before every render, just bitBlt an image to the screen, then when you render all the 3d image on top of it, your left with 2d bitmap, covered by 3d images.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  6. #6
    I hope you're not talking about GDI's bitblt. If you are, wouldn't that take a hit on the framerate?

  7. #7
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Traditionaly, yes it would be a performance hit.

    How ever, And im not sure if/how this would work, its just something that came to me:
    Perhaps using a sort of secondary back buffer. And as you would "flip" the backbuffer to the screen, you could draw your bitmap on the secondary backbuffer once, and every render "flip" it to the standard backbuffer. This shouldnt be much of a performance hit.

    Actually, now that im thinking about it. heres some rough psuedo code that might be a good lead. In my programming book for d3d, this is how you would go about plotting a pixel:
    PHP Code:
    // .. in render method
    LPDIRECT3DSURFACE8 pBackSurf 0;
    D3DLOCKED_RECT LockedREct;
    HRESULT r 0;
    g_pDevice->GetBackBuffer0D3DBACKBUFFER_TYPE_MONO, &pBackSurf );

    pBackSurf->LockRect( &LockedRectNULL);

    DWORD pData = (DWORD*)(LockedRect.pBits);
    // set pixel functions

    SetPixel32int Xint yDWORD Colorint PitchDWORDpData );

    //
    pBackSurf->UnlockRect():
    pData 0;
    pBackSurf->Release();
    // continue through render method... 
    // now this is what part of the setpixel method looks like
    PHP Code:
    pData[ (((Pitch/4)*y)+x)] = Color
    now your methods may be different but perhaps you see where im going.
    Create a global copy of the pData array on the first go around and name it BitmapBuffer or something (could be done in GameInit() function instead of render.
    Write your own bitmap loading procedure, that reads the color value of every pixel in the bitmap and changes the bitmapBuffer.

    Now that you have your bitmap stored in an array very easy to handle, in your render method you can use a memcpy() function to QUICKLY copy BitmapBuffer to the current backbuffer, then render over it with 3D.

    Im pretty sure that should work. I hope i didnt lose you. If you still have a question Ask, and I'll see if i can clarify.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  2. Load Bitmap as Window Background
    By Epo in forum Windows Programming
    Replies: 6
    Last Post: 07-19-2005, 09:37 AM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  5. Deep Exploration, OpenGL, and 3d models
    By DavidP in forum Game Programming
    Replies: 18
    Last Post: 04-06-2003, 01:12 PM