Fast copy from HDC to Texture

Started by
22 comments, last by KalvinB 21 years, 4 months ago
try this.

      GLvoid oglClass::CreateVideoTexture(HWND hWndV){	HDC hDC,                  // Handle to the display device context 		hDCMem;               // Handle to the memory device context	HBITMAP hBitmap,          // Handle to the new bitmap		hOldBitmap;		      // Handle to the old bitmap	BITMAP bm;	int   iWidth, iHeight;      // Width and height of the bitmap	char str[256];	// this should be done on init	// do you have control over window? if yes, use CS_OWNDC class style and keep this code	// if no, we need something else	hDC = GetDC (hWndV);	hDCMem = CreateCompatibleDC (hDC);	hBitmap = CreateCompatibleBitmap (hDCMem, 512, 512);	iWidth=320;	iHeight=240;	int bytes=GetObject(hBitmap, sizeof(BITMAP), &bm);	HGDIOBJ OldBitmap = SelectObject (hDCMem, hBitmap);	// this should be done every frame	BitBlt (hDCMem, 0, 0, iWidth, iHeight, hDC,  0, 0, SRCCOPY);	GdiFlush();	glBindTexture(GL_TEXTURE_2D,videoTexture);			// Bind To The Video Texture	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering	glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, bm.bmBits);	// this should be done on cleanup	SelectObject(hDCMem, OldBitmap);	DeleteObject (hBitmap);	DeleteDC (hDCMem);	// don't delete hDC if you have CS_OWNDC}      



[edited by - niyaw on December 8, 2002 5:46:07 PM]
Advertisement
Nope. But that''s because the GetObject function don''t return byte information for bitmaps. Only the header type info.

The GetDIBits is the way to go I think.

Ben


IcarusIndie.com [ The Labyrinth | DevZone | The Wall | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]
The below works as intended but it''s only 5fps (an inprovement from 2-3 though). I just need to move everything out that doesn''t need to be done every frame.


  GLvoid oglClass::CreateVideoTexture(HWND hWndV){	hVDC=GetDC(hWndV);    // Prepare to create a bitmap    BYTE*      pBitmapBits;    BITMAPINFO bmi;    ZeroMemory( &bmi.bmiHeader,  sizeof(BITMAPINFOHEADER) );    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);    bmi.bmiHeader.biWidth       =  (int)512;    bmi.bmiHeader.biHeight      = -(int)512;    bmi.bmiHeader.biPlanes      = 1;    bmi.bmiHeader.biCompression = BI_RGB;    bmi.bmiHeader.biBitCount    = 32;    // Create and clear a DC and a bitmap for the font    HDC     hFDC       = CreateCompatibleDC( hVDC );    HBITMAP hbmBitmap = CreateDIBSection( hFDC, &bmi, DIB_RGB_COLORS,                                          (VOID**)&pBitmapBits, NULL, 0 );	SelectObject( hFDC, hbmBitmap );	SetMapMode(hFDC, GetMapMode(hVDC));	BitBlt(hFDC,0,0,320,240,hVDC,0,0,SRCCOPY);	glBindTexture(GL_TEXTURE_2D,videoTexture);			// Bind To The Video Texture	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering	glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pBitmapBits);  	ReleaseDC(hWndV,hVDC);    DeleteObject( hbmBitmap );	DeleteDC( hFDC );}  


Ben


IcarusIndie.com [ The Labyrinth | DevZone | The Wall | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]
The fps was intially low because I was using GetMessage instead of PeekMessage.

Click for larger image:


This, along with the serial port communication class and GPS decoder class will be released to public domain after a bit of clean up.

It''s basically everything you need to make a GPS title.

Ben


IcarusIndie.com [ The Labyrinth | DevZone | The Wall | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]

This topic is closed to new replies.

Advertisement