Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » primitives glitches

Credits go to Elias and SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
primitives glitches
Matthew Leverton
Supreme Loser
January 1999
avatar

Expected results: a red filled triangle on top right half of screen.

Random result:

{"name":"601585","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/5\/155b9fb0831d5b795a262bd2c4dafbf6.png","w":648,"h":507,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/5\/155b9fb0831d5b795a262bd2c4dafbf6"}601585

Usually nothing is drawn. Sometimes partially. Sometimes all of it.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_primitives.h> 3#include <allegro5/allegro_opengl.h> 4 5int main() 6{ 7 al_init(); 8 al_init_primitives_addon(); 9 10 al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL); 11 ALLEGRO_DISPLAY *display = al_create_display(640, 480); 12 13 ALLEGRO_COLOR red = al_map_rgb_f(1,0,0); 14 15 ALLEGRO_VERTEX triangle[3]; 16 17 triangle[0].color = red; 18 triangle[0].x = 0; 19 triangle[0].y = 0; 20 21 triangle[1].color = red; 22 triangle[1].x = 639; 23 triangle[1].y = 0; 24 25 triangle[2].color = red; 26 triangle[2].x = 639; 27 triangle[2].y = 479; 28 29 al_draw_prim(triangle, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_FAN); 30 31 al_flip_display(); 32 33 al_rest(2); 34 35 return 0; 36}

Edit:

Ubuntu with NVIDIA drivers.

  • Do I need to set z? If so, to what? [edit2: setting to 0, seems to fix]


  • Any other member variables to worry about?


  • Does order matter (e.g., clockwise) when doing lists or fans?

james_lohr
Member #1,947
February 2002

Does order matter

If it's using OpenGL as the backend, then almost certainly: yes.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I thought clockwise/counterclockwise only mattered for backface culling ???. IIRC backface culling isn't enabled by default.

They all watch too much MSNBC... they get ideas.

Dario ff
Member #10,065
August 2008
avatar

AFAIK, setting the z on the vertexes to 0 have fixed most of my problems when switching to .9.20.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Elias
Member #358
May 2000

I think we should make the members of ALLEGRO_VERTEX non-public (like ALLEGRO_COLOR) and instead have a function like this:

ALLEGRO_VERTEX triangle[3];
al_set_vertex(triangle + 0, x, y, z, u, v, color);
al_set_vertex(triangle + 1, x, y, z, u, v, color);
al_set_vertex(triangle + 2, x, y, z, u, v, color);
al_draw_prim(triangle, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_FAN);

It would mean there can never be uninitialized values and we could always fix things later (inside the al_set_vertex function) without breaking compatibility.

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

Trent Gamblin
Member #261
April 2000
avatar

Elias' idea sounds good to me. It doesn't incur much overhead and gives a lot more flexibility and foolproofing.

james_lohr
Member #1,947
February 2002

On a different topic: I'm really struggling to see the point of Allegro 5. The one thing that Allegro has going for it is that it's great for retro games. If you're using OpenGL as a backend, you lose this and you may as well use one of the other vastly better libraries or even just an OpenGL wrapper.

Mokkan
Member #4,355
February 2004
avatar

Have you ever used A5? It's a lot more than just a graphics wrapper...

Trent Gamblin
Member #261
April 2000
avatar

What does using OpenGL have to do with not being able to make retro games? Also, I'd really like to know what these vastly superior libraries are.

james_lohr
Member #1,947
February 2002

From my experience, OpenGL is not suited to low-res "pixel-art" style games. No, I haven't used Allegro 5, so my comments are unjustified; you're welcome to correct my misconceptions. :)

As to other libraries, well let us not forget that OpenGL is a library, and if you're going to use the "not beginner-friendly" argument, then I would argue for another language altogether: Java or C#.

Elias
Member #358
May 2000

You can use pixel-art with OpenGL. You just get no direct framebuffer access. Nothing ever stops you from doing your whole game graphics in a memory bitmap though then just updating that 60 times a second - it simply means it will all run on the CPU and not use the GPU. Should not be a big issue for retro games...

As for OpenGL, it's only a graphics API... you can't do anything with it. I mainly use Allegro 5 just to get a window in which I can use OpenGL. So I don't use the A5 drawing functions but OpenGL, but the drawing functions are only a small part of the library.

Oh, and Allegro 5 uses DirectX under Windows by default, so OpenGL might not be an alternative at all under Windows.

[edit:]
About the original issue of the thread - I'm fairly certain that's just un-initialized z values and has nothing to do with OpenGL.

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

Dario ff
Member #10,065
August 2008
avatar

From my experience, OpenGL is not suited to low-res "pixel-art" style games.

I don't see what's the problem here. If you want it to look as ugly and software-ish as the last Allegro, you just use the Point filtering instead of linear for rotation and scaling. And Allegro 5 provides a layer above both Direct3D(under Windows) and OpenGL. Some configurations under a Windows OS work only with Direct3D sometimes... what's better than such compatibility between different drivers?

A4's restrictions are more suited to retro-style games, because they're forced. It's still possible with modern hardware, what would you say regarding the Megaman's sequels on WiiWare? They look retro enough to me.

Not to mention you also have platform compatibility with the iPhone, so you can port your PC games easily.

EDIT: I'm really slow today.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Trent Gamblin
Member #261
April 2000
avatar

From my experience, OpenGL is not suited to low-res "pixel-art" style games.

That just doesn't make sense... you can put pixels on the screen just like allegro 4... if you want an example of a low res pixel are game made with allegro5, look here.

GullRaDriel
Member #3,861
September 2003
avatar

I remember that:
2D using OpenGl

That was a thing without value for me.

Plus that with just plain A4 and AllegroGL, all your already coded game could easily be ported to OpenGL with a few allegro_gl_set_allegro_mode(); allegro_gl_unset_allegro_mode();

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Trent Gamblin
Member #261
April 2000
avatar

You don't have to go through any of that to draw using allegro 5. It has image loading, sprite blitting, primitives, etc all built in and easy to use.

james_lohr
Member #1,947
February 2002

You're missing my point.

Generally speaking, OpenGL is desgined to abstract away from the pixel level. The retro style that I find charming involves a loving respect for each and every pixel, and involves clever little tricks like palette effects, dithering and so forth. It most certainly does not involve resolution independence, anti-aliased texture mapping and vector-based geometry.

It's about making the most of the tools you have available. Give a man a piece of wood and a knife, and he might carve you a delightful little doll. Give him a modern industrial complex with state-of-the-art lathes, saws, planers, drills etc. and expect him to attempt some overly ambitious monstrosity that makes your average Ikea flat-pack look like the height of elegance and artistry.

LennyLen
Member #5,313
December 2004
avatar

You're missing my point.

And you're missing everybody else's point.

Quote:

Generally speaking, OpenGL is desgined to abstract away from the pixel level. The retro style that I find charming involves a loving respect for each and every pixel, and involves clever little tricks like palette effects, dithering and so forth. It most certainly does not involve resolution independence, anti-aliased texture mapping and vector-based geometry.

It's about making the most of the tools you have available. Give a man a piece of wood and a knife, and he might carve you a delightful little doll. Give him a modern industrial complex with state-of-the-art lathes, saws, planers, drills etc. and expect him to attempt some overly amitious monstrosity that makes your average Ikea flat-pack look like the height of elegance and artistry.

You can still use your knife if you want to.

james_lohr
Member #1,947
February 2002

LennyLen said:

You can still use your knife if you want to.

Actually I use OpenTK, and what a pleasure it is.

I'm not saying that I prefer the old to the new, I'm simply saying that there is a distinction, and failing to respect this can make things look very very cheap.

It's a bit like visiting a Bushmen (or native American or whatever) village where life is yet to be changed by modern amenities, and then discovering that they are using plastic Tescos bags for their roofing because it provides better water-proofing than any of the naturally available materials. Suddenly the charming facade vanishes and one is confronted by naked poverty.

GullRaDriel
Member #3,861
September 2003
avatar

Except that when you use OpenGL for doing 2D things, you have the benefit of Hardware Acceleration.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Dario ff
Member #10,065
August 2008
avatar

Allegro has been always known as a library which provides everything[1] needed for a programmer to make a game on a short time. It's also known to be newbie-friendly to C learners and quite easy to learn for an experienced programmer.

But, in some years, Allegro would lose that reputation. Why? Because fixed resolutions might not be an option anymore(because resolutions could go up to really huge values, making something like a 640x480 Window impossible), neither not being able to blit alpha-blended sprites with ease of use, and it's very likely they decide to scrap all 2D Drivers in the future in favour of 3D acceleration. I wouldn't be surprised if 8-bit screenmodes are thrown away forever.

Allegro must keep up with the latest trends. Starting programmers won't like to find themselves with an outdated library that's able to recreate games from several decades before, and won't even run on their hardware. They want to create something up to par with the latest 2D games. And yes, 2D games will remain IMO regardless of the trends.

If you're actually wondering about having all Allegro 4's feautures into A5, well that's another story. I'm sure it could be done adding some specific modes, but the work in porting, renaming everything to the new convention, and taking several things out of the global namespace will need a great deal of work. Which is not really worth it, to me at least.

References

  1. Though we can admit that without add-ons, it's a bit annoying

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Mark Oates
Member #1,146
March 2001
avatar

James, you're right in that A5 isn't suited for low-res pixel type games. Using A5, it's certainly easy to create a game that has the same graphical style as a game from 1985, but the thought process you have to use and programming methods are different.

The important point is that A5 is not A4-that-has-been-enhanced. A5 is a completely different library, one which is intended to provide functionality at a level which A4 was not designed. A5 was designed with a different methodology and even has a different API. As a result, you will not write games in the same way that you did 35 years ago.

If you still want to write using an older programming mindset, you can use A4. Or BASIC, or Assembly. They're all solid and stable.

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

SiegeLord
Member #7,827
October 2006
avatar

A5 can do everything A4 could do, only with a slightly different API. And yes, that includes palette effects and dithering (via shaders). There is only one reason to continue using A4 after the bugs have been ironed out from A5: you're targeting a system with cruddy OpenGL drivers.

Do I need to set z? If so, to what? [edit2: setting to 0, seems to fix]

0 is what you should set it to.

Quote:

Any other member variables to worry about?

The only ones that are optional are u and v members. If you're not using a texture, they can be ignored.

Quote:

Does order matter (e.g., clockwise) when doing lists or fans?

I'm pretty sure this is unspecified, but I think it should not matter. As someone said, this is an option that can be enabled/disabled and I think we disable it.

Elias said:

I think we should make the members of ALLEGRO_VERTEX non-public (like ALLEGRO_COLOR) and instead have a function like this:

This is difficult to extend to custom vertices.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Matthew Leverton
Supreme Loser
January 1999
avatar

What about the coordinates? If you want to draw a 10x10 box from (0,0)-(9,9), what should you use?

Thomas Fjellstrom
Member #476
June 2000
avatar

SiegeLord said:

This is difficult to extend to custom vertices.

Can't the custom verts use their own functions for setting? Or maybe the GFX driver provides a set of vert get/set'ers in its vtable?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

What about the coordinates? If you want to draw a 10x10 box from (0,0)-(9,9), what should you use?

Same as Allegro 4 except you add 0.5, since in Allegro 5 0.5 represents the center of a pixel. So (0.5, 0.5, 9.5, 9.5).

 1   2   3 


Go to: