Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: drawing a 1 pixel thick line  (Read 3150 times)

0 Members and 1 Guest are viewing this topic.

smurf

  • Newbie
  • *
  • Posts: 27
    • View Profile
drawing a 1 pixel thick line
« on: February 01, 2021, 08:10:20 pm »
How can I draw a simple 1-pixel thick line?
I've tried the obvious but it draws a 2-pixel thick line thats the wrong color! (I'm trying to draw it white but it comes out grey instead).

BTW I'm using the C# bindings if that matters.


Vertex[] line = new Vertex[2];
line[0].Position.X = 10;
line[0].Position.Y = 10;
line[0].Color.R = col.R;
line[0].Color.G = col.G;
line[0].Color.B = col.B;
line[0].Color.A = col.A;

line[1].Position.X = 10;
line[1].Position.Y = 100;
line[1].Color.R = col.R;
line[1].Color.G = col.G;
line[1].Color.B = col.B;
line[1].Color.A = col.A;

currentRenderTarget.Draw(line,0, 2, PrimitiveType.Lines);

Ignatius_Z

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: drawing a 1 pixel thick line
« Reply #1 on: February 02, 2021, 12:21:06 am »
is anti-aliasing on it or something?

smurf

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: drawing a 1 pixel thick line
« Reply #2 on: February 02, 2021, 03:04:18 am »
I don't think so.
I don't see anywhere to set anti-aliasing in regards to these lines.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: drawing a 1 pixel thick line
« Reply #3 on: February 02, 2021, 07:51:24 am »
Try 10.5 and 100.5 for the points coordinates. I assume that you didn't change the view, nor resized the window.
Laurent Gomila - SFML developer

smurf

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: drawing a 1 pixel thick line
« Reply #4 on: February 02, 2021, 05:21:22 pm »
Very interesting, thank you that worked!

Now the obvious next question, is there a global setting to add (or subtract) 0.5 from all line coordinates or something like that?

I'm trying to build a pixel-perfect drawing that is composed of lines, and all of my inputs and math is using integers. It would be really nice to have a global solution rather than adding 0.5 to everything all over the place.

Interestingly, when I draw a RectangleShape it doesn't have this problem.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: drawing a 1 pixel thick line
« Reply #5 on: February 02, 2021, 06:07:36 pm »
This only applies to points and lines primitives.

A simple solution would be to offset the whole view by (0.5, 0.5). But then you'll probably have troubles with other shapes (sprites, rectangles, ...). So adding the offset manually, only for lines and points, is probably the best solution.
Laurent Gomila - SFML developer

smurf

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: drawing a 1 pixel thick line
« Reply #6 on: February 02, 2021, 06:25:58 pm »
Disappointing answer but I really appreciate your time (and your library) anyway!

Thanks,

 

anything