HI,
can any one tell me that how can i apply 2-D bitmap behind a 3D Scene in OpenGL.
Thanks!
Printable View
HI,
can any one tell me that how can i apply 2-D bitmap behind a 3D Scene in OpenGL.
Thanks!
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.
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
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
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.
I hope you're not talking about GDI's bitblt. If you are, wouldn't that take a hit on the framerate?
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:
// now this is what part of the setpixel method looks likePHP Code:
// .. in render method
LPDIRECT3DSURFACE8 pBackSurf = 0;
D3DLOCKED_RECT LockedREct;
HRESULT r = 0;
r = g_pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackSurf );
r = pBackSurf->LockRect( &LockedRect, NULL, 0 );
DWORD * pData = (DWORD*)(LockedRect.pBits);
// set pixel functions
SetPixel32( int X, int y, DWORD Color, int Pitch, DWORD* pData );
//
pBackSurf->UnlockRect():
pData = 0;
pBackSurf->Release();
// continue through render method...
now your methods may be different but perhaps you see where im going.PHP Code:
pData[ (((Pitch/4)*y)+x)] = Color;
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.