Archived

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

Arek the Absolute

DDraw Surfaces in system memory...

Recommended Posts

If I lock a buffer that is in system memory, it just seems to lock. I''m probably giving it the wrong parameters, but I can''t find what I SHOULD be giving it anywhere. Also, once I have the surface locked, how would I go about reading / writing it? Previously I''d just do something like this: locksurface->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); unsigned short *surface = (unsigned short *)ddsd.lpSurface; int color = surface[location]; locksurface->Unlock(NULL); Granted, that is a very generic example, but it gets the point across. What would I have to change to do the same thing with a surface in system memory?

Share this post


Link to post
Share on other sites
I assume that your are in 16bit color, since you cast the surface memory as a unsigned short.

The first problem I see is that you are taking mixing data types.

Your color variable is an int which is 32bits, and you are requesting data from a location that is only 16bits.

Second, your not requesting a proper location in surface memory.

You would need to do this:

  
void GetColor( unsigned short &usColor, LPDIRECTDRAWSURFACE pSurface, int nPosX, int nPosY )
{
// Fil up your surface desc.

DDSURFACEDESC ddsd;

ZeroMemory( &ddsd, sizeof( DDSURFACEDESC ) );
ddsd.dwSize = sizeof( DDSURFACEDESC );

// Lock the surface

pSurface->Lock( NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR , NULL );

// Grab the surface memory

usigned short * pusSurfaceMem = (unsigned short*)ddsd.lpSurface;

// Grab the surface pitch - divide by 2

unsigned int uiSurfacePitch = ddsd.lPitch / 2;

// Now grab the color

usColor = pusSurfaceMem[ nPosX + nPosY * uiSurfacePitch ];

// unlock the surface

pSurface->Unlock( NULL );
}



That should work for ya... but I''m at school so that''s off the top of my head. :D



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites
No prob man. Email me or contact me on ICQ or AIM is your have anymore questions. I''d be happy to help.

Email: rem@ziremsoftware.net
ICQ: 40309514
AIM: Remnex1



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites