PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

render pixel

hi!
how can i easily render my pixels?
i want to draw values with "SetPixel" that are
between pixels. but with the SetPixel-function
i can only use "long"-values.

thanks
ITT
nicholsr · 19 Sep 2003, 15:56 UTC — render pixel
Anonymous wrote:
hi!
how can i easily render my pixels?
i want to draw values with "SetPixel" that are
between pixels. but with the SetPixel-function
i can only use "long"-values.

thanks
ITT


I don't understand "between pixels"...

Could you give a little more detail?

Thanks
Richard
hi!
i want to draw "double-values",for example want to draw a point at 3.55 in x direction and 3.67 in y direction, but with SetPixel my point would be set
at 3,3 because SetPixel use long values.

thanks
Pejo Software - Per · 25 Sep 2003, 10:52 UTC
This really doesn't make any sense to me!
Isn't pixels by nature integer values? On a Pocket PC there are 240x320 pixels!

Are you trying to do some kind of antialiasing?
SetPixel will always render on integer pixel boundaries. If you wanted to work with floating point values you would need to multiply each coordinate by a fixed factor then cast the result. For example:

x = 3.55
y = 3.67

_x = (DWORD)(x * 100);
_y = (DWORD)(y * 100);

This would now make x = 355 and y = 367. You would then need to somehow scale these values to fit the display size of the device, or simply not draw any values outside of the display size (eg they are considered offscreen points).

Hope this is what you were looking for.
Or use float variables and cast them to int before drawing. There may be a performance hit. This will truncate not round (e.g. 3.9 will become 3 not 4).

Using ints as above is just another way of doing fixed point. It's faster but requires a little more bookkeeping.
So in your game, your sprite might be moving from 2.9 to 3.2, 3.5, 3.8, 4.1, 4.4, 4.7, and 5.

But onscreen, it will be at pixels 3, 3, 4, 4, 4, 4, 5, and 5.
And if you want to make it appear less discrete, check out Wu Particles at http://freespace.virgin.net/hugo.elias/graphics/x_wupixl.htm

Pam
I wouldn't worry about 1 pixel on the screen. If your sprite is moving less than 1 pixel per frame, it is going fairly slow, and at 30 frames per second it will take more than 8s to cross the screen. If your sprite is moving more than 1 pixel per frame, it will still be moving many frames per second, and you won't notice the quantization. For non-changing text it is different and sub-pixel rendering technologies make a difference; for moving game objects, it generally won't.
Pejo Software - Per · 25 Sep 2003, 20:04 UTC
mlepage wrote:
It's faster but requires a little more bookkeeping.


Not necessarily, you could create a fixed point class like this one:
http://memberpages.pejosoftware.com/FixedPoint16_16.h

Anyone can feel free to use it.
You may have to add some more operators, this was what I needed. This implementation will add some overhead in some cases. If you are going to use it I also reccomend that you understand what it is doing.
Yes a good fixed point class should be transparent. I tried to find a good one earlier this week, that had a license I could use. One was lacking operators. Another had bugs.

I eventually got my app working under either floating or fixed point via a simple flag. It is a testament to my encapsulation that it really only required one code change, plus a change to my file loading (to not sscanf into a fixed point directly), and adding a few typecasts here and there.

However, it completely broke my equation-based collision detection, so I disabled it until I could find time to fix it up. Strangely, and sadly, it didn't seem too much faster in my app.
Pejo Software - Per · 25 Sep 2003, 21:11 UTC
Pejo Software - Per wrote:
You may have to add some more operators, this was what I needed.

The sentence above perhaps wasn't completly clear. What I meant was:
If someone other than me is going to use my class they might need to add some extra operators. I only implemented thos that I needed.