Solved

OpenGL & Bitblt

Posted on 2004-04-06
4
1,470 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:rossryan
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:joghurt
ID: 10764042
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.
0
 

Author Comment

by:rossryan
ID: 10764136
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);
0
 

Author Comment

by:rossryan
ID: 10764151
Perhaps replacing bitmapData.Scan0 with hBitmap?
0
 
LVL 6

Accepted Solution

by:
joghurt earned 500 total points
ID: 10764193
No, your code seems to be OK. Scan0 is the address of the first scan line. bitmap.LockBits behaves like GetDIBits.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now