• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1586
  • Last Modified:

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.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.
  • 2
  • 2
1 Solution
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.
rossryanAuthor Commented:
                        Rectangle rectangle = new Rectangle(0, 0, bitmap.Width,
                        BitmapData bitmapData = bitmap.LockBits(rectangle,
                              ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                        Gl.glGenTextures(1, out this._texture);
                        Gl.glBindTexture(Gl.GL_TEXTURE_2D, this._texture);
                              Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                              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,
rossryanAuthor Commented:
Perhaps replacing bitmapData.Scan0 with hBitmap?
No, your code seems to be OK. Scan0 is the address of the first scan line. bitmap.LockBits behaves like GetDIBits.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now