🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Direct Draw - Setting Pixel Value

Started by
4 comments, last by B4 24 years, 7 months ago
Try this(I am assuming 8 bit color):

BYTE mycolor;
BYTE *sptr;

sptr = g_pDDSOne->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
sptr[x + (y*ddsd.lpitch)] = mycolor;
g_pDDOne->Unlock();

Advertisement
One thing I didn't see you do that is very important is initialize your ddsd!

ddsd.dwSize = sizeof(ddsd); (i think)

Otherwise direct draw doesnt know what to make of it.

Just because the church was wrong doesn't mean Galileo wasn't a heretic.It just means he was a heretic who was right.
You should be clearing your DDSURFACEDESC also:

memset(&ddsd, 0, sizeof(DDSURFACEDESC));

Good luck!

Starfall

On that note you should check the return value of the lock to make sure it worked.
(Just pointing out the obvious, which I'm sure you probably already did hehehe (but then again, maybe not))
-ns
-ns-
I am trying to set a pixel to a certain color using Direct Draw, but my method seems to make the computer crash. I first find the value of the pixel by doing the following:
DDSURFACEDESC2 ddsd;
int mycolor;
BYTE *sptr;
HRESULT hRet;

hRet = g_pDDSOne->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
sptr = (BYTE*) ddsd.lpSurface;
sptr++;
mycolor = *sptr; g_pDDSOne->Unlock(NULL);

I was having some problems with this code as well, when I tried printing the value of mycolor to a file, it crashed again. I tried
setting the pixel value by saying
*sptr = 255; but this did not work (I did this before Unlocking). Could someone help me out please?

Out of curiosity that surface wouln't be one pixel long, would it?
(I know this might sound stupid, but that surface does have a suspect name...)

This topic is closed to new replies.

Advertisement