Skip to main content
GameDev.net gamedev.net
🔒 Locked

Plotting Pixels...

Started by Tooko Jan 3, 2003 at 3:11 AM 0 replies 300+ views
Original Post
Tooko
Tooko
How can I place a single pixel onto a DirectDraw surface not using GDI SetPixel()? If you can answer that question, maybe you could become really nice and help a little more by giving a way of getting the colour of a pixel? Through either GDI or... any other ways avaliable. That would be a great help. Thanx The past was unknown, the future was predicted.
the future is just like the past, just later. - TANSTAAFL
KabOm
KabOm
Hey, check out some of the directx articles here on gamedev.net. pretty sure there are plenty of em with pixeldrawing.

Anyway, I'll try to give you a short version...

First you have to lock your surface, before editing the surface by changing pixels.

Then you have to retrieve the pixelbuffer from the DD object.

Then you just change the color value of the pixelBuffer.

And then you unlock the surface again.

Here comes an example for 16bitcolor

          
DDSURFACEDESC2 ddsd;
INIT_DX(ddsd); // a macro to zeoro memory of the dd object


//lock the surface

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

//now get the pixelbuffer

SHORT* pixelBuffer = (SHORT*)ddsd.lpSurface;
//now get the pitch... since lpSurface isn't an array of SCREEN_WIDTH*SCREEN_HEIGHT, but a straight array with each pixel following. And the size of each pixel depends on what color mode you use, for 16bit each pixel takes 2 bytes and for 32bit 4 bytes. So each pixel is stored with a 2 resp 4 byte space between. Thats why we use USHORT = 2byte for 16bit and UINT = 4byte for 32bit. SO the nPitch retrieves how many USHORT's there are on each y row :)

SHORT nPitch = ddsd.lPitch >> 1; // 2^1 = 2


//now change the pixel value

pixelBuffer[Y*nPitch + x] = COLOR_16_BIT_565(0,0,0); //macro for 16 bit color


//Unlock the surface

lpddsPrimary->Unlock(NULL);



this was a short and maybe vauge description... but it actually is really basic stuff, so I would recommend reading some of the articles around here on gamede.net

GL!

[edited by - KabOm on January 3, 2003 7:33:57 AM]

[edited by - KabOm on January 3, 2003 7:34:17 AM]

[edited by - KabOm on January 3, 2003 7:35:41 AM]

[edited by - KabOm on January 3, 2003 7:37:00 AM]
KaBooOM!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.