Link to home
Start Free TrialLog in
Avatar of rossryan
rossryan

asked on

OpenGL & Bitblt

Question: is it possible to toss OpenGL a pointer to some data from a BitBlt operation, in hopes that it can make a texture out of it?


Here the current code (C#, don't ask):

this._hdcSrc = User32.GetWindowDC(HWnd.ToInt32());
this._hdcDest = GDI32.CreateCompatibleDC(HdcSrc);
this._hBitmap = GDI32.CreateCompatibleBitmap(HdcSrc,
GDI32.GetDeviceCaps(HdcSrc,8),GDI32.GetDeviceCaps(HdcSrc,10));       
GDI32.SelectObject(HdcDest,HBitmap);
GDI32.BitBlt(HdcDest,0,0,GDI32.GetDeviceCaps(HdcSrc,8), GDI32.GetDeviceCaps(HdcSrc,10),      HdcSrc,0,0,0x00CC0020);

Can I toss HdcDest or HBitmap to an OpenGL function for textures? Creating a Bitmap from the HBitmap pointer, creating a mimap from that Bitmap, loading, unloading, etc. is very slow.

I'm half tempted to say I'd like to stream video from a pointer to a window (hWnd), but that might be going a bit far.
Avatar of joghurt
joghurt

Why don't you use GetDIBits instead of copying the bitmap or creating a new bitmap? I don't know which gl function do you prefer for creating a texture, but you may also be able to use this._hBitmap directly.
Avatar of rossryan

ASKER

bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        
                        Rectangle rectangle = new Rectangle(0, 0, bitmap.Width,
                              bitmap.Height);
                        BitmapData bitmapData = bitmap.LockBits(rectangle,
                              ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                              
                        Gl.glGenTextures(1, out this._texture);
                        Gl.glBindTexture(Gl.GL_TEXTURE_2D, this._texture);
                        Gl.glTexParameteri(Gl.GL_TEXTURE_2D,
                              Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                        Gl.glTexParameteri(Gl.GL_TEXTURE_2D,
                              Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
                        Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, 3,
                              bitmapData.Width, bitmapData.Height,
                              Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE,
                              bitmapData.Scan0);
                        bitmap.UnlockBits(bitmapData);
Perhaps replacing bitmapData.Scan0 with hBitmap?
ASKER CERTIFIED SOLUTION
Avatar of joghurt
joghurt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial