Hello Guest

Author Topic: Drawing a line to the screen.  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

Flascher

  • Member
  • Posts: 6
    • View Profile
Drawing a line to the screen.
« on: June 01, 2015, 09:25:53 PM »
Hey everyone, I've been messing around with trying to get a line to draw... I have 2 points, and just want to draw a line between them.

I've tried using

Code: [Select]
Otter.Draw.Line(point1.X, point1.Y, point2.X, point2.Y, Color.Cyan, 2);

I've also tried creating a new surface, adding it to the scene, and setting that surface as the draw target.

After my loop in which I try to draw all my lines, I call surface.Render(), but that didn't quite seem to do it either.

Here's a pastebin to the entire class (Sorry if this is terribly messy, I'm still learning to use Otter! :) )
http://pastebin.com/9AkcTLaz

Fruckert

  • Member
  • Posts: 60
  • Total Square
    • View Profile
Re: Drawing a line to the screen.
« Reply #1 on: June 01, 2015, 10:30:52 PM »
You'll want to stick that in the Render override method of the scene, or an entity. Otherwise, it'll render it for one frame and then the game will clear it's surfaces.

Flascher

  • Member
  • Posts: 6
    • View Profile
Re: Drawing a line to the screen.
« Reply #2 on: June 01, 2015, 11:24:07 PM »
Well, now I've got this:

Code: [Select]
public override void Render()
{
    base.Render();
    foreach (var edge in graph.GetEdges())
    {
        Draw.Line(point1.X, point1.Y, point2.X, point2.Y, Color.Cyan, 2);
    }
}

but that hasn't seemed to change anything. How would I go about shoving all those lines into an Entity?

Kyle

  • Administrator
  • Member
  • Posts: 259
    • View Profile
Re: Drawing a line to the screen.
« Reply #3 on: June 02, 2015, 08:35:57 PM »
Your code in the render function looks right.  Not sure where point1 and point2 are coming from though.  You might be rendering off camera, or below something else?  There is the "Verticies" graphic type which you can add verts to and render in various ways.  It's basically just a wrapper for SFML and OpenGL's basic primitive drawing stuff.

Flascher

  • Member
  • Posts: 6
    • View Profile
Re: Drawing a line to the screen.
« Reply #4 on: June 03, 2015, 05:56:41 AM »
The points are coming from my own Edge class to handle the graph. I tried the Vertices object, but I got a giant polygon :) I'm basically unfamiliar with OpenGL, I'm just aware its what SFML and thus Otter is built on top of.

I'll take another look at using the Vertices object if there's a way to change the rendering though! :) Thanks Kyle

TP

  • Member
  • Posts: 3
    • View Profile
Re: Drawing a line to the screen.
« Reply #5 on: June 19, 2015, 05:30:49 AM »
Hello Forums!
Sounds like you forgot to do:
yourVerticesObject.PrimitiveType = VertexPrimitiveType.Lines;
That should prevent it from turning into a polygon. Just give it pairs of points and it will draw lines between them.

Since I came from an OpenGL Background I went straight to the Vertices Class and everything works just fine.
Theres one Issue though: I can`t seem to find a method to change the Line Thickness. Is this implemented yet or would I have to directly call an OpenGL/SFML Method for that? I could also use rectangles to make thicker lines but that feels a little hacky...

Kyle

  • Administrator
  • Member
  • Posts: 259
    • View Profile
Re: Drawing a line to the screen.
« Reply #6 on: June 19, 2015, 06:02:13 PM »
Line thickness as far as I know isn't an openGL supported thing.  If you use the Draw.Line function though you can control the thickness (because it's actually drawing a quad)

TP

  • Member
  • Posts: 3
    • View Profile
Re: Drawing a line to the screen.
« Reply #7 on: June 20, 2015, 03:45:36 AM »
It is a thing ;)
https://www.opengl.org/sdk/docs/man/html/glLineWidth.xhtml

I´ll try Draw.Line but if its drawn using Immediate Mode I doubt it´ll provide the performance I need^^
Drawing a lot of dashed lines can be quite a task
I´ll probably just use vertices to draw quads in this case I think.
Mhh I could try prerendering them to a surface/texture as they don´t change too often.