Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Is Open GL a good platform for drawing 3D lines?

  1. #1
    Newbie Newbie
    Join Date
    Feb 2016
    Posts
    3

    Is Open GL a good platform for drawing 3D lines?

    I'm responsible for an industrial application written for Windows in C# for WPF/.Net that controls a bank of industrial lasers. The app already exists and runs, and for its graphics output it uses the basic line-drawing and 3D transform API's in WPF.

    Graphics performance is terrible so I want to replace that part with a hardware-accelerated API such as OpenGL 3D or Direct3D.
    N.B. I only need to draw lines (fully 3D transformed, with perspective) and text, not lighted, shaded surfaces. Also N.B. this is not the same as wireframe - the lines do not necessarily represent surfaces and I do NOT want polygons tesselated into triangles. Just think of these as thousands of lines that can be rotated, scaled, translated and (if desired) viewed in perspective. The lines should be able to assume specific colors and the text is there to label details of what's being represented.

    Questions:

    1. Does OpenGL have a 3D line-drawing primitive?

    2. How easy is OpenGL to integrate with WPF? I want to run the OpenGL part in some sort of WPF control like a Panel or Canvas so it integrates well with the surrounding UI and so I can mouse over the graphics to draw rectangular regions of interest, etc.

    3. Where can I see some sample hello world code that shows how to integrate this with WPF (not Windows Forms)?

    Thanks in advance.
    Last edited by plnelson; 02-16-2016 at 10:43 AM. Reason: clarify question

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,829
    Quote Originally Posted by plnelson View Post
    1. Does OpenGL have a 3D line-drawing primitive?
    Yes.

    To get decent performance, you don't want to be making a function call for each line segment. You ideally need an array of vertex coordinates so that you can tell OpenGL to draw many line segments with a single call.

    Also, if the coordinates aren't changing continually, you want to avoid having to transfer all of the vertex coordinates from system memory to video memory every frame. This basically means explicitly managing the copying of data between system memory and video memory so that you only need to copy the portions which have changed.

    In short, you get better performance if you structure the data around what's convenient for the hardware than if you design the data structure in isolation then deal with rendering as an afterthought. Common OOP practices tend to work against you here.

    I have no experience with WPF so I can't answer the WPF-related aspects.

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    391
    Of course OpenGL can draw 3D lines. It draws points, lines, and polygons. And it does so very quickly. How many lines are you talking about? You don't even have to worry about hardware acceleration unless there are hundreds of thousands of lines. Try googling 'WPF OpenGL' to get some sample code. One link that looked promising to me was THIS.
    Last edited by Carmine; 02-16-2016 at 10:21 PM.

  4. #4
    Newbie Newbie
    Join Date
    Feb 2016
    Posts
    1
    If your going the OpenGL route, search for the nuget package 'OpenTK'.
    We used it as a base to build a editor for a application in the automotive segment, the application is written in C#, gui is WPF and we use MVVM as pattern,
    but we had to host the OpenTK Control in a winforms host.

    If you only have to draw a couple of thousands lines just go for the old OpenGL immediate mode and dont invest in modern OpenGL.
    code to draw one line:
    GL.Begin(PrimitiveType.Lines);
    GL.Color4(color.R, color.G, color.B, color.A);
    GL.Vertex3(start.X, start.Y, start.Z);
    GL.Vertex3(end.X, end.Y, end.Z);
    GL.End();

    Your other problem will be rendering text, there is no support for drawing texts in OpenGL.
    So you need to use a third party tool. At the moment we use a modified QuickFont implementation (search the nuget package), but we plan to replace it with a own font rendering engine in the (not so near) future.

  5. #5
    Newbie Newbie
    Join Date
    Feb 2016
    Posts
    3
    Quote Originally Posted by carlamengo View Post

    . . .
    but we had to host the OpenTK Control in a winforms host . . .
    . . .

    Your other problem will be rendering text, there is no support for drawing texts in OpenGL.
    So you need to use a third party tool. At the moment we use a modified QuickFont implementation (search the nuget package), but we plan to replace it with a own font rendering engine in the (not so near) future.
    Why the Winforms host? That just adds another layer of complexity to the problem. Is it really necessary for OpenGL?

    Also, If I can layer a WPF canvas over the window (/panel/canvas/whatever) that has the graphics I can make the overlay canvas transparent and put text in that using WPF, since I don't need the text to be 3D or rotatable.

    My other option that I'm exploring is Direct3D and it's going to come down to which can be more seamlessly integrated with WPF.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •