SFML community forums
Bindings - other languages => DotNet => Topic started by: sofakng on January 28, 2009, 05:14:52 pm
-
Here's what I'm doing:
1) Drawing a line from (0, 0) to (11, 10).
2) Drawing a 1x1 sprite at (11, 10).
However, the sprite is drawn AFTER the end of the line. In other words, the line is not ending at (11, 10).
What's going on here?
Here is my code:
' Define points
Dim p1 As Vector2 = New Vector2(0, 0)
Dim p2 As Vector2 = New Vector2(11, 10)
' Create and draw the line
Dim line As SFML.Graphics.Shape = SFML.Graphics.Shape.Line(p1, p2, 1, White)
m_renderWindow.Draw(line)
' Create and draw the sprite
Dim sprite As Sprite = New Sprite(New Image("tiles\1x1.bmp"))
sprite.Position = p2
m_renderWindow.Draw(sprite)
-
Can you show a screenshot?
-
Thanks for the quick response.
Upon further testing, drawing a line directly through OpenGL produces yet another different result but this one seems to be correct.
Here are screenshots:
Line drawn with SFML:
(http://f.imagehost.org/0858/line_only.png)
Line drawn with SFML plus sprite (notice the sprite is after the line):
(http://f.imagehost.org/0562/line_withdot.png)
Line drawn with OpenGL (red) on top of SFML line (white):
(http://f.imagehost.org/0379/line_opengl.png)
-
Oh, so you're talking about a 1 pixel difference. Remember that you manipulate coordinates with float components, and that all this stuff gets converted to integer for displaying into the window.
Moreover, there are a few tricks involving half-pixels adjustments for sprites in SFML.
So, you shouldn't rely on pixel perfect mapping in this context.
-
Darn floats. They always cause problems! :)
The reason I found this bug was because I'm trying to draw isometric tiles using the SFML drawing functions but the sides of the tile do not line-up correctly. I guess it's a little confusing because OpenGL and Flash both seem to render the lines "correctly" (but I suppose correct is a relative term).
I might be able to use pre-generated sprites so my lines are always correct but I was hoping to use the drawing functions for other purposes as well.
-
Darn floats. They always cause problems! :)
The reason I found this bug was because I'm trying to draw isometric tiles using the SFML drawing functions but the sides of the tile do not line-up correctly. I guess it's a little confusing because OpenGL and Flash both seem to render the lines "correctly" (but I suppose correct is a relative term).
I might be able to use pre-generated sprites so my lines are always correct but I was hoping to use the drawing functions for other purposes as well.
You should always be allowing a pixel or so of overlap in your displays to prevent these "texture seams." Remember OpenGL or any 3D API correctly uses floats, so you have to expect and prepare for rounding variance.
You can possibly ignore this if everything you draw is axis-aligned and you always force it to the int value you want (with checks to make sure it rounds the correct way), but this will never be the case with "isometric" tiles. Either way, just having all your terrain textures (or any textures that are supposed to touch and match up) overlap by 1 pixel will fix all these issues.