🎉 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!

Pixel color array

Started by
3 comments, last by David20321 24 years ago
I''m pretty sure there''s an easy way to get a 2-d array with the colors of all the pixels on the screen in C but I''ve only been using c for 2 weeks. Can anyone help me with this?
Advertisement
You mean a pointer to video mem? If so, there are many ways to get access to this ''array'' (a pointer isn''t really and array, but it holds all the values like an array), if you''re using good old DOS, you can just use: char *vidmem=''whatever vid mem address is'' (I haven''t used DOS in quite a while). If you''re using WIndows you can use Direct and lock surfaces to get pointers to video memory, etc. That''s getting a bit advanced, there are a bunch of tutorials (all over GameDev.net) on how to access video memory, etc. Hope this helps! Cheers!
Thanks but I''m using a mac. No dos or windows. I''m trying to get the colors of every pixel on the screen so I can add some number to all of them and get a tinted screen and things like that so it would also help a lot if anybody knows how to change the color of all the pixels on the screen to conform with an array variable video memory pointer thing.
Well, I''m a Mac programmer, so hopefully I can help. Are you using GLUT for your projects or AGL? You''ll have to be using AGL to do all that stuff. Just in case you don''t know how to use AGL I wrote a tutorial on it (http://www.sover.net/~jams/Morgan/) and there''s one at http://www.xgdl.org/macgl.html.

What you need to do is take your CGrafPtr, access it''s pixmap and draw into that. The pixmap is not an array, it''s like a whole chunk of memory, so you have to access it by offsetting a pointer to a specific are, to do this you need to know the bit depth of the CGrafPort and the Rect.

CGrafPtr myWindow;

Say we take myWindow, then to access the pixmap you use myWindow->portBits. To get the starting memmory address of the pixmap''s memory area you do myWindow->portBits.baseAddr, then you need to know how many bytes per row, that is stored in myWindow->portBits.rowBytes. The rectangle of the pixMap is stored in myWindow->portBits.bounds (it''s a rectangle). And to know the bitdepth the window is set at you can use myWindow->portBits.pixelSize.

I know this isn''t too clear right now, just doing off the top of my head, so if you need more help, just ask and I''ll write up some example code if you need it.

Morgan
Damn, didn''t take my uname & pword.

Morgan

This topic is closed to new replies.

Advertisement