SFML community forums
Help => Graphics => Topic started by: MasterQ32 on July 14, 2013, 02:42:18 pm
-
Hey!
I'm new to SFML and just migrate my current project to it. I previously used SDL for drawing and event management but it has some flaws like missing keyboard input and other things.
My project is written in C# with SFML.Net, but i think this doesn't matter in my case. I compose a lot of graphics in my project from one source texture. With SDL it looked really good, but now i have the problem that seams appear in my GUI system:
(http://picshare.masterq32.de/img_14_07_2013_14_40_43.png)
That's the code i use to draw a texture on the screen:
public static void DrawTexture
( RenderTarget target,
Texture texture,
IntRect targetPos,
IntRect
? sourcePos,
bool tileTexture
){ texture
.Repeated = true; texture
.Smooth = false; using (Sprite sprite
= new Sprite
(texture
)) { if (sourcePos
!= null) sprite
.TextureRect = sourcePos
.Value; else sprite
.TextureRect = new IntRect
(0,
0,
(int)texture
.Size.X,
(int)texture
.Size.Y); sprite
.Position = new Vector2f
(targetPos
.Left + 0
.5f, targetPos
.Top + 0
.5f
); if (!tileTexture
) { sprite
.Scale = new SFML
.Window.Vector2f((float)targetPos
.Width / sprite
.TextureRect.Width,
(float)targetPos
.Height / sprite
.TextureRect.Height); sprite
.Draw(target, RenderStates
.Default); } else { sprite
.Scale = new Vector2f
(1,
1); while (sprite
.Position.X <= targetPos
.Left + targetPos
.Width - sprite
.TextureRect.Width) { sprite
.Draw(target, RenderStates
.Default); sprite
.Position = new Vector2f
(sprite
.Position.X + sprite
.TextureRect.Width, sprite
.Position.Y); } } }}
Is there any way to get SFML to create pixel perfect graphics?
Greetings
Felix Qu.
-
I wouldn't use repeating texture if you really want, what you do.
If you want to work with one textures you can use a RenderTexture to draw go, but you can also simply draw the snippet as man times as you want. ;)
-
Thanks for the fast answer!
I just looked into the features of a RenderTarget and found out that i can draw vertices. This would fit my needs perfectly and should be faster as well (way lesser draw calls).
I think i got it running now.
-
I previously used SDL for drawing and event management but it has some flaws like missing keyboard input and other things.
Off topic, but I'm curious: In what way does SDL not have keyboard input support?
-
I only found 2 C# wrappers for SDL and one was unusable and the other had no Text/Unicode input option so i would've built my own IME system.
-
Was one of them this one (https://github.com/flibitijibibo/SDL2-CS)? In any case, if you need full IME/composition support, I guess yeah, you're on your own with either SDL or SFML =/
-
no, it was cs-sdl.
But i got IME with SDL working, so my problem is solved