Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenLayer: LineStrip

This thread is locked; no one can reply to it. rss feed Print
OpenLayer: LineStrip
kdevil
Member #1,075
March 2001
avatar

Yes, I have another issue involving OpenLayer, this time involving LineStrip. I've attached a picture of the problem, and here's the code to make it happen:

1#include "OpenLayer.hpp"
2using namespace ol;
3 
4volatile int counter;
5 
6typedef struct _trail
7{
8 bool exists;
9 int time, striplen;
10 float x, y, xv, yv, xa, ya, dx, dy;
11 LineStrip strip;
12 Rgba start, end;
13} _trail;
14 
15void timer_handler()
16{
17 counter++;
18}
19END_OF_FUNCTION(timer_handler);
20 
21bool do_trail(_trail *t)
22{
23 if (t->exists)
24 {
25 t->time--;
26
27 t->x += t->xv;
28 t->y += t->yv;
29 t->xv += t->xa;
30 t->yv += t->ya;
31
32 t->strip.AddToBegin(Vec2D(t->x, t->y));
33 
34 if (t->strip.GetNumOfVertices() > t->striplen)
35 {
36 t->strip.DeleteLast();
37 }
38
39 if (t->time <= 0)
40 {
41 t->exists = false;
42 }
43 }
44 
45 if (t->exists) return false;
46 return true;
47}
48 
49int main()
50{
51 const float tconst = 10.0;
52 const float gravity = 1.0;
53 bool done = false;
54 
55 LOCK_VARIABLE(counter);
56 LOCK_FUNCTION(timer_handler);
57 
58 Setup::SetupProgram();
59 Setup::SetupScreen(800, 600, false);
60 Settings::SetOrthographicProjection(640, 480); // Commenting this out doesn't do anything related to the problem
61 install_int_ex(timer_handler, BPS_TO_TIMER(30));
62 
63 _trail b;
64 
65 float dx = 304, dy = 80;
66 float ox = 304, oy = 200;
67
68 b.x = ox;
69 b.y = oy;
70 b.xv = float(dx - ox) / (tconst * 2);
71 b.yv = (float(dy - oy) / (tconst * 2)) + (-gravity * tconst);
72 b.xa = 0;
73 b.ya = gravity;
74 b.striplen = 10;
75 b.time = int(tconst) * 4;
76 b.start = Rgba(1.0, 1.0, 1.0, 1.0);
77 b.end = Rgba(0.0, 0.0, 0.0, 0.0);
78 b.exists = true;
79 
80 glPointSize(2);
81 
82 readkey();
83 
84 counter = 0;
85 
86 while ((!done) && (!key[KEY_ESC]))
87 {
88 while (counter > 0)
89 {
90 done = do_trail(&b);
91 counter--;
92 }
93 Canvas::Fill(Rgba::BLACK);
94 b.strip.Draw(b.start, b.end);
95 Canvas::Refresh();
96 }
97 
98 exit(0);
99 return 0;
100}
101END_OF_MAIN()

Basically, at the height of the trail, I get a line going off the screen towards the bottom-right for no apparent reason.

???

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Birdeeoh
Member #6,862
February 2006
avatar

Eeeps!

What version are you using? Fladimir and I exposed alot of border-cases in the OpenLayer 2.0 LineStrip code that have since been fixed, but I'm sure there are more...

However, on that note, I tested your code with the latest Subversion and I get a crash once the 2nd vertex has been added... I'll spend a little time trying to track it down but Fladimir knows the code alot better than I.

[EDIT]
Nevermind, my build of the library was out of date with the headers. Your thingy works now but I see that artifact. Lemme take a look and see what I can find.

[url http://developer.berlios.de/projects/openlayer/]OpenLayer[/url is an OpenGL accelerated 2D library for fast and easy graphics development under Allegro

kdevil
Member #1,075
March 2001
avatar

I got it from svn recently. I'll update it and see if the problem is still there...

Edit: Yeah, latest svn version and the problem is still there.

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Birdeeoh
Member #6,862
February 2006
avatar

Okay, yah, there's still some cases where we don't catch when the linestrip goes back over itself which yours does. Basically, LineStrip takes two vertices and your line width, and creates a whole bunch of little rectangles. When you have repeat coordinates like your code produces, those little rectangles end up having a zero-dimension and this translates into weird opengl artifacts.

Lemme see if I can fix that ;) Gimme a little bit.

[EDIT]
An initial fix for the problem is done. Need to clean up one or two things then commit it, I'll let you know

[2nd EDIT]

Dammit... I can't commit right now because Fladimir left some file additions out of his last commit so the repository is currently not compilable. I've attached the two files you'll need to change to make yours work until we can get ahold of Fladimir to commit the missing files. Vec2d.hpp goes in /include/Openlayer and linestrip.cpp goes in /src

Good luck

[3rd EDIT]

God dammit, he did commit it, I just didn't update it somehow. sigh... making the commit now...

could you please reply to my post so I could start a new post instead of editting this one over and over? ;)

[4th and final? edit]

Okay. Checkout a copy of the HEAD - you should be at revision 35
Problem fixed.
Enjoy

[url http://developer.berlios.de/projects/openlayer/]OpenLayer[/url is an OpenGL accelerated 2D library for fast and easy graphics development under Allegro

kdevil
Member #1,075
March 2001
avatar

OK, just got the latest version and the problem no longer shows up.:)

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Go to: