Archived

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

quick question : getPixel in DD as you would GDI

This topic is 5748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello Can anyone tell me what the equivalent is, in direct draw, of the GDI GetPixel and SetPixel functions? I want to scan a DD surface and if a pixel is black fill it with one colour, and if it is any other colour, fill it with another. I was looking into GetPixelFormat(), but this is to do with the whole surface, not an individual pixel, right? An easy work around for me would be to somehow retrieve the direct draw surface in the form of a bitmap, manipulate this bitmap with GDI functions that I am used to, and then stick it back in the DD surface, if this is in fact the easiest way to go about this, how is it done? 'Though, to be honest, since I am working with a DD surface, I'd rather use DD functions, but I have looked through DD documentation and can't see anything there that seems useful. edit: Thinking about it, maybe FlipToGDISurface is what I need (I want to freeze everything and apply colour effects to all the whole surface.) What do you reckon? I'll try it in the morning at any event... thanks Edited by - graeme on March 18, 2002 8:34:57 PM

Share this post


Link to post
Share on other sites
I found this artcle here on gamedev: http://www.gamedev.net/reference/articles/article538.asp
so I am halfway there. This shows me how to plot a pixel of a specific colour onto a dd surface. But how to retrieve the colour value of a pixel on a surface in the first place?

Any ideas?

Share this post


Link to post
Share on other sites
Okay, so you have plotted the pixel, getting the pixel is more or less, the direct opposite process.

int get_pixel(int x, int y)
{
return video_buffer[offset];
}

Hmm, only thing I don''t know is what exactly to put in the offset of the video buffer, I''m looking off other source code. It is designed for a 320x200x256 resolution, and uses binary shifting, which I don''t yet understand

y<<8 + y<<6 - what would that be?

Oh well, I''ve pointed you in the right direction, I''ll try finding out more about binary shifting.

Share this post


Link to post
Share on other sites
Ah! I''ve found it.

It should be:

int get_pixel(int x, int y)
{
return video_buffer[y * pitch + x];
}

Try that

Remember to replace the video_buffer pointer with your actual video buffer you are using, and replace the pitch variable with whatever graphics API you are using! I use SDL myself, so the code would differ a little bit. Peace

Share this post


Link to post
Share on other sites
Thanks alot, I will have it working in no time I hope!

One more thing!

I followed this up, and found out that the surface has to be locked first...

this is the code that I saw in a couple of places:
UCHAR *video_buffer=ddsd.lpSurface;

Which made VC++ say, on compiling:

C:\Windows\Desktop\mm\main.cpp(624) : error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Windows\Desktop\mm\main.cpp(627) : error C2374: 'video_buffer' : redefinition; multiple initialization
C:\Windows\Desktop\mm\main.cpp(624) : see declaration of 'video_buffer'



this, however, works fine:
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;

What is the big difference between the two methods, and why does the first fail and the second work? I have a vague understanding of what's going on, but it's one thing to know what to use to get a job done, and another to know what goes on under the surface and why it works. What's going on here?


[edited by - graeme on March 19, 2002 4:00:51 PM]

Share this post


Link to post
Share on other sites