DDraw Surfaces in system memory...
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?
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:
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
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
You absolutely rule. Thanks a thousand times over, and a few times after that. Problem solved!
-A very grateful Arek the Absolute
-A very grateful Arek the Absolute
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement