Archived

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

CTRL_ALT_DELETE

plotting a pixel

Recommended Posts

I am trying to directly manipulate a surface to plot a pixel. Right now i am calling a function that says something like: bool particles::Draw(LPDIRECTDRAWSURFACE s, int r, int g, int b) { BYTE* dest =NULL; //destination DDSURFACEDESC ddsd; //create a descriptor //init descriptor memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); //LOCK THE SURFACE if(FAILED(s->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL))) return FALSE; //Huston, there is a problem. //find out where we are going dest = static_cast(ddsd.lpSurface) //write the data /*gives me errors here*/ *(dest+m_xpos+m_ypos*SCREEN_WIDTH) = (r<<16)|(g<<8)|b; s->Unlock(NULL); return TRUE; I checked out the gamedev resources on plotting pixels, but they were dealing with methoeds a little bit more advanced than I want to deal with. I am still learning. Thanks. Edited by - CTRL_ALT_DELETE on December 18, 2001 5:54:02 PM

Share this post


Link to post
Share on other sites
a person    118
first off read the docs on lock() and be enlightened.

secondly the only things i see wrong are that you should be using the pitch of the surface not the screen_wdith. secondly you better not be reading form a vram surface or wave good nye to your frame rate. finnally dont lock() the surface for every pixel you plot. thats just plain stupid (and massivly slow). how are they more advanced then you want to deal with? plotting pixels is modifying memory. it cant get more simple then that. also explain what you errors are. unless you mean it crashes there.

Share this post


Link to post
Share on other sites
I fave read the docs, a person, but they aren't helping me with my problem; that's why I am asking you.

I realize that this is slow, and eventually I will write on routine that will plot all of my pixels with one lock and unlock call, but I want it to work first.

I was able to get my function to work, where I am having problems is getting it to disblay the rigt color.. right now I am using the expression r<<16|g<<8|b
bu I think this is for 32 bit color, and I am working in 8 bit color. How do i get my rgb values into a UCHAR (I think).

Thanks,
CTRL_ALT_DELETE

Edited by - CTRL_ALT_DELETE on December 18, 2001 10:20:36 PM

Share this post


Link to post
Share on other sites
EbonySeraph    122
a person sort of gave you the answer. Im not sure if you saw it though. He said that you should use the pitch of the monitor instead of the screen width to advance to the next row correctly.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
a person    118
if you are using 8bit, then you are using a palette mode. this means that you will have a pallete of 256 entries (make sure to use the ALLOW_256 flag (check the docs for the exact flag)). eah entry in the pallete table will be a 24bit color. on the surface however you will plot the index into that pallete so the correct color displays.

example:
a small 4 color pallete
0 red (0xFF0000)
1 blue (0x0000FF)
2 green (0x00FF00)
3 cyan (0x00FFFF)

now to plot green you would use 2 instead of 0x00FF00 (which is the green in hex usng 24bit color). you will have to read up on how to read and write to the pallete, so you can set the colors you need up. you probally will only want to write a pallate out at the start of your program. you can modify the pallete at any time (as long as no surface is locked).

example:
by doing this you could plot index 2 at the bottom of the screen and index 1 at the top. so the bottom looks like grass and the top portion like the sky. its getting dark, instead of actually changing the surface, you merely change the pallete. maybe you change index 1 to be a darker blue or black and make index 2 a darker green. after updating the pallate with your new colors. ALL the positions on the surface with the number 2 stored will be the darker green and the places with the number 1 will be the darker blue. this allows efficent color cycling which was used a lot in old school games for the pc and consoles.

you may want to jump to 32bit color which is a bit easier to grasp since all the colors are literal instead of having to deal with the limited pallete (which can be quite fun since many effects can only be done using a pallete otherwise they are slow).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
you seem to be targetting 24-bit color mode which shows up by the way you wrote (r<<16 + g<<8 + b), but duh!! you casted the surface as BYTE* !! which is typical to 8-bit color mode. You are mixing up the whole thing i guess.

First of all make up your mind which color mode you will be using and then cast you surface likewise.

for 8-bit cast it as BYTE*
for 16-bit cast it as WORD*
for 24-bit u have to do some tricks
for 32-bit cast is as DWORD*

for 8-bit color mode u have to set a palette.
i hope this will solve your problem.

Share this post


Link to post
Share on other sites