Problem with 2d Terrain Rendere

BlitzMax Forums/BlitzMax Programming/Problem with 2d Terrain Rendere

klepto2(Posted 2005) [#1]
I have a small problem with a 2d terrain Creator I'm currently writing.

Here is a pic of the problem :



And here is a small exe to play with:

http://www.blitz-pasting.net/index.php?content=bp_showupload&id=559

Any ideas how to get rid of the wrong coloerd areas?

I have tried to get rid of this by check every Pixel and their Neibours if their is the right Color but that doesn't work and currently I'm out of ideas what i could try.

Thx.


Ferminho(Posted 2005) [#2]
That's very little information to try to help, but well, why don't you try to draw the borders, then fill in the space?


ImaginaryHuman(Posted 2005) [#3]
I am guessing that you are using a `scanline` fill system where you fill one column at a time from left to right? I only say that because it looks like the kind of error that you get when you try to draw a filled polygon with a scanline technique, usually horizontally, where the polygon has an `edge` where the defining pixels will start, continue, and then stop, without having any gap inbetween to be filled. Your routine will think that as soon as it gets into an open gap area, that is what has to be filled, rather than realizing that this is a `special case` and has to be handled differently.

It's also apparently related to the presence of the green parts because the error is occuring only where there is some green to be drawn but no yellow, for that column.

You see, you probably have an algorithm which says that you search for the edge of a piece of land starting at the top of the screen, when you find some land, draw a few pixels of green, then start drawing yellow pixels until you hit another edge of landscape, draw some more green, then draw empty until you find more landscape.

The problem is happening only on those parts of the landscape where the green is followed by an empty area but it's an area that shouldn't be filled.

I am guessing therefore that you first of all draw the edges of the landscape with your curve drawing, and THEN you try to fill it. That will make it harder for you and produce this kind of result - you should Google for scanline fill algorithms or look on these forums, it's been discussed before.

Otherwise, a better solution is if you can be calculating where the edges of the landscape are at the same time as filling it, so that you have the extra `information` on hand to know when you are at one of those special cases, where exactly things should be drawn and when an area has gaps in it.

You just need to solve the case where you have pixels defining the edge of the landscape, but they're on such an angle that they aren't followed by yellow space before the land ends again. ... so you've got a run of several edge pixels but no gap in the middle. It's just confusing your rendering algorithm.


klepto2(Posted 2005) [#4]
Thank you very much, AngelDaniel.

I have tried it from Up and Down, so I know why these Columns comes, but I hadn't an Idea on how to solve it. Many thanks to show me the right way.

I'm triing out now.


ImaginaryHuman(Posted 2005) [#5]
Certainly.

If you wanted to have things simplified, or to make sure that the thickness of the green line is consistent at all angles ... instead of drawing several vertical pixels, draw a small circle. You could perhaps draw and fill the yellow landscape in its entirity, first, then go back on a second `pass` and draw circles whenever you encounter an edge.


klepto2(Posted 2005) [#6]
Solved, I have now used a non - recursive Flood-Fill Function, that does the job very well. I will post it in the Codearchives as soon as possible.

Thx again .

[edit]
So here is the Flood Fill Function:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1509


Ferminho(Posted 2005) [#7]
Good you solved it, thanks for sharing the floodfill!


ImaginaryHuman(Posted 2005) [#8]
Also instead of doing a floodfill you could just create your own polygons which OpenGL or whatever will automatically fill for you - which could also be textured.