Solved

OpenGL & Bitblt

Posted on 2004-04-06
4
1,506 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create string splitting user defined function in C++ 23 317
C Language combined operators 28 114
VS2015 Redefinition errors 4 68
Outlook 13 41
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 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