Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

KalvinB

Fast copy from HDC to Texture

This topic is 5644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Here''s the current source. It takes the 320x240 source image and copies it to a 256x256 texture.

This nets a whopping 3fps. I also need to be able to hide the source window but still be able to read the data from it. Moving it off screen or using SW_HIDE results in not being able to read the pixel information. Getting a fast copy is more important at this point though.

15fps or better would be optimal.

data is defined as BYTE size 262144.


  
GLvoid oglClass::CreateVideoTexture(HWND hWndV)
{
hVDC = GetDC(hWndV);

//copy data to texture

int cur=0;
DWORD color;

for (int l=0;l<256;l++)
for (int c=0;c<256;c++)
{
color=GetPixel(hVDC,c*1.25,l*0.93);
memcpy(&VidData[cur],&color,4);
cur=c*4+l*1024;
}

glGenTextures(1, &videoTexture); // Create 1 Texture

glBindTexture(GL_TEXTURE_2D,videoTexture); // Bind To The Blur 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, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, VidData);

ReleaseDC(hWndV,hVDC);
}


Ben



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

Share this post


Link to post
Share on other sites
hmmmm, what would be the image you are trying to grab from video ram via get pixles?
I assume its one you''ve already made yourself?
if thats so then you could render it direct to a pbuffer, thus giving you the data in a texture form already to go.

Share this post


Link to post
Share on other sites
I could (if I ever figure out how to change the video format) but it'd probably die performance wise.

At this point I'm more concerned about making it fast. I'll make it pretty later.

click for larger image


The small picture is the original source and the larger is the copy on the texture.

Ben


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


[edited by - KalvinB on December 8, 2002 3:17:50 AM]

Share this post


Link to post
Share on other sites
well, believe it or not, 512x512 texture might end up being faster than your present code. i assume that your video input and gl renderer can agree on a data format.

create a temporary bitmap with dimensions 512x512, same format as the video dc''s bitmap, and get a compatible dc for it. if you kwow video dc at load time, create a dc compatible to that and create a bitmap compatible with compatible dc (as opposed to using CreateDIBSection()). select bitmap into compatible dc. all of this is done on load. also, keep a pointer to bitmap bits around.

every frame, call BitBlt() and transfer 320x240 image from your video dc to the temporary dc. don''t scale anything. call GdiFlush().

use glteximage2d for the entire 512x512 bitmap. in other words, upload entire 512x512 bitmap to opengl. you should only need one gl call for this.

then you''ll have to modify your texcoords to only reference 320x240 part of the 512x512 texture. i suppose you can do this?

Share this post


Link to post
Share on other sites

  
hVDC = GetDC(hWndV);

HDC hBDC=CreateCompatibleDC (NULL);
HBITMAP hBmp = CreateCompatibleBitmap( hBDC, 256,256);
which=BitBlt(hBDC,0,0,100,100,hVDC,0,0,NULL);
GdiFlush();
SelectObject( hBDC, hBmp );

BITMAP BM;
::GetObject (hBmp, sizeof (BM), &BM);


"which" is comming back true so BM.bmBits is being copied to the texture instead of the pixel by pixel copy. However nothing is showing up.

When I tried copying the hBDC pixel by pixel it was empty.

Ben


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!