Click to See Complete Forum and Search --> : Wince.net 4.2 directdraw question!


Daniel M
October 5th, 2004, 02:27 PM
--------------------------------------------------------------------------------

Iīm working on some directx functions and I need to have full control over the pixeldata pointer to a directdraw surface, It worked in Visual c++ but I get some funny stripe kind of pattern in wince, itīs supposed that the function should fill the surface with red color.

Here is the function:



void SetPixelDataPointer(win* p,IDirectDrawSurface* lpddsurf){
DDSURFACEDESC desc;
DWORD x,y;

ZeroMemory(&desc,sizeof(desc));
desc.dwSize=sizeof(desc);

if(!IDirectDrawSurface_Lock(lpddsurf,NULL,&desc,DDLOCK_SURFACEMEMORYPTR|
DDLOCK_WAIT|DDLOCK_WRITEONLY,0)){
// upload data
p->data = (DWORD*)desc.lpSurface;
p->pitch=desc.lPitch;
//detta ger endast en pekare till pixelarrayen du kan sätta
//hela arrayen mha:
desc.dwHeight=desc.dwHeight;
desc.dwWidth=desc.dwWidth;
for(y=0;y<desc.dwHeight;y++){
for(x=0;x<desc.dwWidth;x++)
#if defined(_WIN32_WCE)
p->data[x]=0xffff;
p->data+=desc.lPitch/2;
#else
p->data[x]=0x00ff0000; //fill whole array with red color
p->data+=desc.lPitch/sizeof(DWORD); //sizeof(DWORD) = 4
#endif

}
}

IDirectDrawSurface_Unlock(lpddsurf,desc.lpSurface);
}

I dont know why it is not working in wince, any ideas?

I hope someone knows something about this, thanks in advance Dani

TheCPUWizard
October 5th, 2004, 02:29 PM
What is the actual value of desc.lPitch

TheCPUWizard
October 5th, 2004, 02:35 PM
Also, please goto the definition of "win" and paste the complete declration of that structure here [I think I see it, but want to confirm before I "spout off"]

Daniel M
October 5th, 2004, 02:48 PM
Ok, thanks for your reply, sorry I forgot the implementation of the struct win!

Here is the struct:

typedef struct win
{
ULONG* data;
};

When I debug it (with Embedded VC) in WinCe the desc.pitch is 960

And when debugging it with (Developer Studio ) on my PC the desc.pitch is 1920

So the pitch is the double thatīs why I did the desc.lPitch/2; in the wince version.

I suppose wince uses 16 bits colors and win 32 bits colors, but I am not sure!

I hope you can help me some more, thanks Dani

TheCPUWizard
October 5th, 2004, 05:29 PM
Yup, but win->data is ALWAYS a pointer to a 32 bit quantity, do it wipes out half the data! [although in most cases the next access will overwrite the data that was overitten with the data that you want to overwrite.

A fairly simple rework of the code can correct this and should correct the effect.

Daniel M
October 5th, 2004, 07:17 PM
So, what is your suggestion, what should I change, it does seems to wipe out half of the data, but it gets a striped look!

I would like to post some picture of how it looks but donīt understand how!

I have an image of the stripes in C:/watch design/pixeldata.img

How should I post it so you can see it, using the insert image icon ?

Mick
October 5th, 2004, 07:31 PM
I would like to post some picture of how it looks but donīt understand how!

I have an image of the stripes in C:/watch design/pixeldata.img

How should I post it so you can see it, using the insert image icon ?

Post a reply or edit your post, and click the "manage attachments" button. If it is not a supported upload extension then zip it up or convert it to one that is and upload it.

Daniel M
October 5th, 2004, 07:36 PM
Thanks for the tip :) here is the picture of how the stripes look like!

Daniel M
October 5th, 2004, 08:47 PM
Thanks for all help the solution is :

in the struct i added:

#if defined(_WIN32_WCE)
UCHAR* data;
#else
DWORD* data;
#endif

and changed the function as following:

void SetPixelDataPointer(win* p,IDirectDrawSurface* lpddsurf){
DDSURFACEDESC desc;
DWORD x,y;

ZeroMemory(&desc,sizeof(desc));
desc.dwSize=sizeof(desc);

if(!IDirectDrawSurface_Lock(lpddsurf,NULL,&desc,DDLOCK_SURFACEMEMORYPTR|
DDLOCK_WAIT|DDLOCK_WRITEONLY,0)){
// upload data
#if defined(_WIN32_WCE)
p->data = (UCHAR*)desc.lpSurface;
#else
p->data = (DWORD*)desc.lpSurface;
#endif
//BUFFER=(DWORD*)desc.lpSurface;
p->pitch=desc.lPitch;
//detta ger endast en pekare till pixelarrayen du kan sätta
//hela arrayen mha:
desc.dwHeight=desc.dwHeight;
desc.dwWidth=desc.dwWidth;
for(y=0;y<desc.dwHeight;y++){
for(x=0;x<desc.dwWidth;x++)
#if defined(_WIN32_WCE)
//p->data[x]=0x00f0;
p->data[x]=0x0ff0;
p->data+=desc.lPitch/sizeof(UCHAR);
#else
p->data[x]=0x00ff0000; //fill whole array with red color
p->data+=desc.lPitch/sizeof(DWORD); //sizeof(DWORD) = 4
#endif

}
}

IDirectDrawSurface_Unlock(lpddsurf,desc.lpSurface);
}

I did get a turcose color not red, anyone knows how color components are managed in 16 bits colors?

Daniel M
October 7th, 2004, 10:38 PM
Actually it should be

p->data = (WORD*)desc.lpSurface;

and

p->data+=desc.lPitch/sizeof(WORD);

Cheers Dani, thanks for all help! :)