Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Can someone explain this to me?

This thread is locked; no one can reply to it. rss feed Print
Can someone explain this to me?
Kevin Eperjesi
Member #16,900
September 2018

I'm currently enrolled into a gaming class for my college and we just started learning graphics using allegro. We were creating a polygon and we were using different x and y's to make the polygon. but im having trouble understanding. can someone explain to me how all these letters make the polygon?

void chevron (int x, int y, int d, int color)
{
int vertices[12] = {x,y,x+2*d,y,x+3*d,y+d,x+2*d,x,y+2*d,x+d,y+d};
polygon (screen, 6, vertices, color);
return;
}

DanielH
Member #934
January 2001
avatar

The polygon is created using those six points as vertices.

Line 1 is drawn from x0y0 to x1y1
Line 2 is drawn from x1y1 to x2y2
...
Line 5 is drawn from x4y5 to x5y5
Line 6 is drawn from x5y5 to x0y0

Well, you say you are passing in six points (12 numbers). But on further look, I see only 11.

int vertices[12] = {x,y,x+2*d,y,x+3*d,y+d,x+2*d/*,(missing y component here)*/,x,y+2*d,x+d,y+d};

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Would you kindly notify your professor that Allegro 4 is deprecated and that Allegro 5 is the modern replacement, with hardware acceleration and event based input as well as much more. If you insist on using Allegro 4, and you need DOS, use Allegro 4.2.X. If you don't need DOS, use Allegro 4.4.3. If you don't need software drawing, and know the limitations of polling for input, then you choose Allegro 5. No one develops Allegro 4 anymore. 5 is the recommended version unless you absolutely know what you're doing.

can someone explain to me how all these letters make the polygon?

Those are alternating x and y positions. There are six pairs, hence twelve arguments. If you're referring to the 'letters' when you mean variables, x and y are of type 'int', and they are integers. The expressions make the x and y passed to the function inside the array different so that they draw your chevron.

roger levy
Member #2,513
July 2002

Well, it could be argued Allegro 4 is easier and therefore better suited to a class ...

Sometimes I miss it... :D

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jmasterx
Member #11,410
October 2009

As soon as I started reading the thread I knew a professor would be using A4 not A5. I don't know why, just a hunch.

But yeah understanding event loops and how modern hardware acceleration works obviously adds a lot more value if you're starting from scratch anyways.

But that's way over most professors' heads sadly. I had several University professors #include .cpp files :-X

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Audric
Member #907
January 2001

The bottom left point gets drawn at the x and y coordinate. d works as a "zoom" level : if d=100, the entire shape takes 300 pixels in its biggest width, and 200 pixels in the tallest height.
In mathematical representation, the polygon looks like this :
{"name":"2prxw6r.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/d\/fd8dc668ca26cb6021e3534360800b78.png","w":346,"h":356,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/d\/fd8dc668ca26cb6021e3534360800b78"}2prxw6r.png

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Chris Katko
Member #1,881
January 2002
avatar

New GIMP actually gets rid of that stupid "everything is floating window" thing that wrecks COMPLETE HAVOK with virtual desktops. (GIMP loads as you switch, some windows are on the first virtual desktop, some on the other.) Now it uses docked bays kind of like Visual Studio and other IDEs.

GIMP still has some other stupidity. Like the fact you have to google how to simply "select a rectangle and move the pixels" because no matter what you INTUITIVELY do, you just move the damn selection itself. That's (early?) Blender levels of open-source stupidity.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Audric
Member #907
January 2001

That was Excel :)

ZoriaRPG
Member #16,714
July 2017
avatar

Some of us fossils actually hate OOP.

Further, learning how things used to work can be incredibly useful.

I've often argued that Universities should instruct ASM and C/Pascal before C++/Java/nonsense. They teach backwards-like, instructing in highly-abstracted OOP nonsense, giving no fundamental comprehension on how anything <I>actually works</I>.

I have junior developers on projects who had never used C, and didn't comprehend how anything worked at all, that have found learning how these things function to be quite beneficial. They were taught only modern OOP languages and had no clue how to do anything low-level; or clean.

Most of the time, you honestly <I>do not need</I> all of the baggage that comes with OOP.

If he's teaching them how to use DOS, Allegro 4, C, and probably ASM, then in the long-term, they are getting a far better education.

Anyway, Polygon() is sort of a bitch to use unless you plot all of your points in advance. I hate doing 3D stuff, so I tend to avoid it; but it can be useful for mapping bitmaps onto surfaces for pseudo-3D effects, on occasion.

Allegro 4 is certainly not designed for creating 3D gaming environments.

void chevron (int x, int y, int d, int color)
{
int vertices[12] = {x,y,x+2*d,y,x+3*d,y+d,x+2*d,x,y+2*d,x+d,y+d};
polygon (screen, 6, vertices, color);
return;
}

Why the extraneous return instruction? You only need that in a (void) type if you want to exit the function early. As that's at the end of its scope, it does the same thing as not having the return instruction.

Likewise, I also only see eleven elements in your array. That'll cause issues because you passed 6 points, but your last point isn't defined properly. The array should always be points*2 in size.

IDK what C-spec you're using, but your last value here is either 0, or undefined.

jmasterx
Member #11,410
October 2009

Using A5 doesn't mean you have to employ OOP or anything like that; it's still super low level. Event loops are probably just more relevant than thinking you can just poll everything.

ZoriaRPG
Member #16,714
July 2017
avatar

I understand that. I just see that a professor--probably younger than me, in fact--using ag4 to teach C code being useful long-term.

The people learning can always move on to greener pastures, but learning how stuff <I>used to work</I> can't hurt.

I might still be stuck in 1995 though.

jmasterx
Member #11,410
October 2009

I could argue that learning electrical engineering and how logic gates work, 2's compliment, voltages, transistors, resistors, etc will not be very helpful to me when my boss asks me to design and implement a distributed system that scales.

For that it's more about understanding concurrency, load balancing, memory management.

For the same reason, knowing the instruction set for ARM probably will not help me make better iPhone apps.

You should probably have a good understanding of concepts like memory allocation, stack vs heap, etc. So that you don't do dumb things like a for loop that rereads a 1gb file into memory each iteration. And understand virtual memory. But for the most part, the emphasis these days is on:
Concurrency, scalability, cloud deployment, maintainable designs, automated testing, automation. And frankly those were not the needs that C and older languages were designed to meet. C was created long before we had multithreading and well, even filesystems, as a given. It's a systems programming language that was fast and had relatively easy to understand syntax so it got really popular for general purpose.

Chris Katko
Member #1,881
January 2002
avatar

[nvm]

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: