Jump to content
  • Advertisement
Sign in to follow this  
axv4745

OpenGL Direct3D port of OpenGL equivalent call issue

This topic is 4521 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

I've been trying to write Direct3D equivalent code to do the following code snippet that was originally written in OpenGL: //read data from frame buffer #define AMBIENT_RESOLUTION 16 float s[AMBIENT_RESOLUTION*AMBIENT_RESOLUTION*3]; glReadPixels(0, 0, AMBIENT_RESOLUTION, AMBIENT_RESOLUTION, GL_RGB, GL_FLOAT, s); Here is what I've written in Direct3D (which isn't working too well):
//read data from frame buffer (probably wrong)	
LPDIRECT3DSURFACE9 targSurf = NULL;
deviceHandle->GetRenderTarget(0,&targSurf); 
LPDIRECT3DSURFACE9 tmpSurface;
deviceHandle->CreateOffscreenPlainSurface(AMBIENT_RESOLUTION,
                                          AMBIENT_RESOLUTION,
                                          D3DFMT_A32B32G32R32F,
                                          D3DPOOL_SYSTEMMEM, 
                                          &tmpSurface, 
                                          NULL);
RECT r;
r.left = 0;
r.top = 0;
r.bottom = AMBIENT_RESOLUTION;
r.right = AMBIENT_RESOLUTION;
//should copy surface data from surface of screen buffer to our surface
//with conversion of data to floating point (I think)	
D3DXLoadSurfaceFromSurface(tmpSurface,
                           NULL,
                           NULL,
                           targSurf,
                           NULL,
                           &r,
                           D3DX_DEFAULT, 
                           0);
D3DLOCKED_RECT lrect;
tmpSurface->LockRect( &lrect, NULL, 0 );
void * pBits = lrect.pBits;
INT Pitch = lrect.Pitch;
//copy pixels from surface into float array (probably wrong)
unsigned char BytesPerPixel1 = 4;
unsigned char index = 0;
for(int Y = 0; Y < AMBIENT_RESOLUTION; Y++)
{
    for(int X = 0; X < AMBIENT_RESOLUTION; X++)
    {
	float* pPixelAddress1 = 
               ( (float*)pBits ) + (Y * Pitch) + (X *  BytesPerPixel1);		
	memcpy(&s[index],pPixelAddress1,sizeof(float)*3);
	index += 3;
    }
}	
tmpSurface->UnlockRect();
tmpSurface->Release();
targSurf->Release();



clearly glReadPixels() is a highly complex function and unless I'm doing something wrong, is a nightmare to port over to Direct3D (as there is so much to take into account such as bit ordering, byte ordering, type formats,etc... Can anyone perhaps provide me with a start as to what I'm doing wrong in my code? Thanks,

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!