Allegro.cc - Online Community

Allegro.cc Forums » The Depot » New Wiki Article - Drawing Primitives in Grid Coordinates

This thread is locked; no one can reply to it. rss feed Print
New Wiki Article - Drawing Primitives in Grid Coordinates
Mark Oates
Member #1,146
March 2001
avatar

Since it is common for people to be confused with pixel coordinates and Allegro 5's primitive drawing (eg this latest thread), I have created a new article on the Wiki, Drawing Primitives in Grid Coordinates, to add to the mythos.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Matthew Leverton
Supreme Loser
January 1999
avatar

It's a good idea for an article, but it doesn't seem to say much despite all of the pictures. At least, I know if I were an Allegro line drawing n00b it wouldn't help me out much, but maybe I just prefer different method of teaching than most. So there's not much more to point out other than I'd write it completely differently. ;)

Although, I would probably not use something like al_color_html("ffd200") in an unrelated tutorial when you can just al_map_rgb(0xff, 0xd2, 0x00) and save the dependency on the color addon.

Mark Oates
Member #1,146
March 2001
avatar

At least, I know if I were an Allegro line drawing n00b it wouldn't help me out much

I wouldn't classify anybody who's run into this specific problem as a "line drawing n00b". Those threads usually have titles like "line drawing bug?" in-so-much that the poster has plenty of experience and confidence in his ability to draw a line.

The problem occurs in the distinction between plotting to pixels and plotting on grids. People who are still struggling need to get to know how coordinates aren't pixels. That's what the article's about. Perhaps I could find a more fitting title that doesn't imply "Now Let's Draw Primitives! :D Yay!"

Quote:

So there's not much more to point out other than I'd write it completely differently. ;)

::)

Quote:

Although, I would probably not use something like al_color_html("ffd200") in an unrelated tutorial when you can just al_map_rgb(0xff, 0xd2, 0x00) and save the dependency on the color addon.

I kept the html and color names in because I find them incredibly useful, e.g. I want other people to know they're available. Plus, the article is about how shapes plot differently in grid and pixel coordinates. If they get stuck on how to map a color, then they are a noob and in the wrong tutorial.

That being said, I do need to create a little adjunct article about turning on and off sub-pixel rendering.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Billybob
Member #3,136
January 2003

Thank you for improving the Wiki even more, Mark! Great work!

Evert
Member #794
November 2000
avatar

First of all: good effort, with nice pictures that should hopefully clarify things for a lot of people.

Now for two points of criticism (yes, I know it's a wiki and I should go and edit it myself, but it's easier to say how to improve something than it is to do it, especially since it'd take a fair bit of my time). The first is that the article is titled "Drawing Primitives in Grid Coordinates", which in itself is fine, but it then goes off and discusses the situation in Allegro 4 in preparation of discussing the situation in Allegro 5. That in itself is also fine if what I'm looking for is a guide on how Allegro 5 is different from Allegro 4, but the title of the article doesn't make it clear that that's what it's going to discuss. I think the article should stand on its own and explain how primitive drawing works in Allegro 5, without referencing how it's done in Allegro 4. Afterall, if I'm looking to learn how it's done in A5 but I don't know A4, I don't want to learn A4 first just so I can learn A5 afterwards.
It might make sense though to have two sections in the article: one discussing Allegro 4, one discussing Allegro 5. Then the current content can become sub-sections under the Allegro 5 heading.
The second point of criticism is that the article assumes we understand what "switch on sub-pixel rendering" means. That could do with a brief introduction of a sentence or two, below this figure
{"name":"A5line2.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/7\/f76ae2b7d7e0887de93741b27abab1fe.png","w":475,"h":247,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/7\/f76ae2b7d7e0887de93741b27abab1fe"}A5line2.png

I kept the html and color names in because I find them incredibly useful, e.g. I want other people to know they're available. Plus, the article is about how shapes plot differently in grid and pixel coordinates. If they get stuck on how to map a color, then they are a noob and in the wrong tutorial.

I'm with Matthew on this one: make the examples as to-the-point and clear as you can. That means getting rid of the HTML and colour names. In fact, I'd just use an (implicit) ALLEGRO_COLOR variable called blue or red or yellow in preference of a function call.
Keep the code clean, focussed and as simple as possible.

Matthew Leverton
Supreme Loser
January 1999
avatar

That's what the article's about.

I'm still not sure exactly what it's about...

In reference to a line drawing n00b, I mean somebody who wants to draw a horizontal line by doing this:

al_draw_line(0,0, 5,0, black, 1.0);

They will notice quite quickly that it doesn't draw where they want it to. You don't need to be a guru to realize something is off by one.

Now if your article isn't intended to help them, then carry on with whatever it is you are talking about.

kazzmir
Member #1,786
December 2001
avatar

Could you explain what sub-pixel rendering is (on the wiki)? Its unclear to me if thats an actual mode you can set or just something to make understand how rendering works easier.

Mark Oates
Member #1,146
March 2001
avatar

al_draw_line(0,0, 5,0, black, 1.0);
They will notice quite quickly that it doesn't draw where they want it to. You don't need to be a guru to realize something is off by one.

What do you think is causing them to make that mistake?

Evert said:

That in itself is also fine if what I'm looking for is a guide on how Allegro 5 is different from Allegro 4, but the title of the article doesn't make it clear that that's what it's going to discuss.

In this case, I'm using the Allegro 4 function to illustrate the difference between what they expect the function is doing, and what it actually is actually doing. I think I'll revise it to exclude Allegro 4, and instead reference some kind of generic function that plots to pixel coordinates.

Quote:

The second point of criticism is that the article assumes we understand what "switch on sub-pixel rendering" means.

kazzmir said:

Could you explain what sub-pixel rendering is (on the wiki)?

The strategy is to link the words "sub-pixel rendering" to a little article on how to turn it on and off. I'll put that in.

And... I'll go ahead and change the color functions.

[edit]
OK, I've changed the title to "Grid Coordinates vs. Pixel Coordinates", modified the first two paragraphs to remove references to Allegro 4, linked to a (to be created) article on sub-pixel rendering, and changed the colors.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Matthew Leverton
Supreme Loser
January 1999
avatar

What do you think is causing them to make that mistake?

Allegro's primitives are not intuitive to someone who only thinks in terms of a 2D library. The article will (may) get them to realize there's something else going on under the hood, but they'll still come out with a very similar question:

"So how do I draw the horizontal line from (0,0) to (x,0)?

"I tried adding 0.5 like the article said al_draw_line(0.5,0.5, x + 0.5, 0.5, red, 1.0), but it still doesn't always work."

I think you give the average Allegro n00b too much credit if you think they will read your article and actually apply the theory into a working application. But again, if the article isn't written with them in mind, it doesn't really matter.

Mark Oates
Member #1,146
March 2001
avatar

Allegro's primitives are not intuitive to someone who only thinks in terms of a 2D library.

It makes no difference if it's 2D or 3D, plotting is the same. Take Photoshop or Illustrator for example, both are very much 2D. If I want to draw a line in Photoshop, the line tool doesn't care about whether or not you're interested in pixels, it's only concerned about coordinates and widths. Same with Illustrator, both are just like Allegro.

Now on the other hand, Photoshop does have the pencil - a special tool for drawing pixels (normally you would use the brush tool.) However, the pencil only draws pixels at a time, and there is no tool for plotting pixel-based shapes or lines. It's similar to the difference between al_draw_pixel() (in coordinate space) and al_put_pixel() (in pixel locations). I think al_draw_pixel() is a bit strange for this reason, it's more like al_draw_1px_width_filled_square() than anything else.

I might support a proposal for separate functions that draw pixel-specific-plots and are not modified by transformations, sort of like an expanded feature-set of al_put_pixel(). But to me, the Allegro (and Photoshop/Illustrator) method is very much intuitive and correct.

I would also support a proposal to have sub-pixel on by default, as having it off is one of the things that can throw people. I would also argue that it's more "correct" for it to be on than off.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Evert
Member #794
November 2000
avatar

I think the new version is better.
So, some more comments then: the terms "pixel coordinates" and "grid coordinates" are not clearly defined. I can understand what they mean without looking at the pictures, but I'm not the target audience for this article. It's easy to work out by scrolling down to the images and comparing the one that says "in pixel coordinates" and the one that says "in grid coordinates", but without doing that the introduction is still confusing.
I would rewrite the first section to explain and introduce those concepts, then explain how you'd draw a line in pixel coordinates as an illustration. I would not introduce a fictional function that would draw such a line because it doesn't actually make things clearer: you're still introducing a code example that doesn't do what you're trying to explain so that you can later explain the code that you want to explain by pointing out the difference.
I would also leave out the ALLEGRO_COLOR definitions, in a sense they're just bloat that detracts from the main point. In fact, looking at it now I would probably just replace the argument in all of them with a generic variable colour. On its first introduction you can explain that it's an ALLEGRO_COLOR variable and leave it at that. The colours really aren't an essential part of what you're trying to explain here and it's better to be to the point.

Elias
Member #358
May 2000

I had written something to the talk page - but guess that's hard to notice :) Basically I removed the picture below and just wrote a short warning about never doing it instead:

{"name":"A5-rect-no-subpixel.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/4\/94c75a9bc1136af669098ec3a4e218ef.png","w":532,"h":504,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/4\/94c75a9bc1136af669098ec3a4e218ef"}A5-rect-no-subpixel.png

In more detail, the rule for when a pixel is lit without super-sampling is that if the center of the pixel lies within the mathematical shape, the pixel is lit. There is nothing said about when the shape hits the exact center of a pixel - but that's what you are showing there. So your result is only one possible way - but not all GPUs will actually draw it like that (mine certainly does not). So if someone reads this and tries it they will be confused why it looks different and think Allegro is broken.

At least in OpenGl the only rule is that if the shape hits the 0.5/0.5 position of a pixel, then if another shape hits the same position and is filled in the other direction, only one of them must light that one pixel. So what it means is that usually there must be a rule saying that the left pixels are drawn and right pixels are skipped or something. But that's an implementation detail. A conforming implementation might just as well make it depend on even/odd pixel numbers or whatever else.

Explaining all of that (and maybe showing multiple possible outcomes, like how it's drawn on some specific GPUs...) would probably only confuse readers so best to just not show a wrong example I think.

--
"Either help out or stop whining" - Evert

Neil Roy
Member #2,229
April 2002
avatar

I can hear the questions now... how do I set the colour? No, I think it's best to leave in an ALLEGRO_COLOR variable. It only takes a brief explanation to make it clear that is how you set colours. They can learn about other functions to do with colour on their own later. But you want to give new programmers some place to start rather than just leaving a vague reference to colour. It is relevant to the topic as you're not plotting a line without it. ;)

---
“I love you too.” - last words of Wanda Roy

Evert
Member #794
November 2000
avatar

Neil Roy said:

No, I think it's best to leave in an ALLEGRO_COLOR variable. It only takes a brief explanation to make it clear that is how you set colours.

Yeah, but you do it once and near the top.

Go to: