read pixel & write pixel

BlitzPlus Forums/BlitzPlus Beginners Area/read pixel & write pixel

Nivlac(Posted 2007) [#1]
New to programming - reading Game Programming for Teens 2nd Edition. Just wondering if someone can explain when and why these functions would be used in game programming, to help me understand these functions better.
Thanks


Abrexxes(Posted 2007) [#2]
A) You can read a picture pixel by pixel to get the color values
B1) You can create, manipulate save pictures
B2) You can replace colors in a picture
C) You can create, manipulate Colormaps (a normal map,but with color values)
D) You can copy every "range" of a picture (not only rects etc)
E) You can .....

There are a lot of things that you can do. ;)

cu


xlsior(Posted 2007) [#3]
Since blitzplus doesn't have built-in alpha transparancy, you can use readpixel/writepixel to mix pictures with their backgrounds, and fade them in/out.

(provided they aren't very large, since it' can be slow if you have a lot of pixels to cycle through)


sswift(Posted 2007) [#4]
Setting pixels to different colors is how all graphics in all games are produced.

In the old days you had to do that all manually in your program. That was called "software rendering". Nowadays many cards do the drawing for you. That's called "hardware rendering".

Also, nowadays you have APIs like DirectDraw, or Blitz itself, which allow you to just load an image, and either do the drawing themselves pixel by pixel, or tell the card to draw a whole image stored in video memory to the screen.

Why would you use the functions?

Well, today many games do the effects you can get with writepixel using 3D acceleration and pixel shaders and stuff like that. There's no need to write individual pixels manually. (Pixel shaders are small programs on the 3D card which tell it what to do with each pixel to create special effects you used to do with writepixel, like say, the frosted windows in Half Life 2.)

But BlitzPlus is older and designed for systems without 3D acceleration, so in that you could use pixel writing to do transparency, or fade the screen, or draw little dots for stars in a space shooter, or anything you can imagine that requires you to calculate a specific effect at runtime or which can use little dots to represent it instead of images, like a particle effect.