hnirvana's picture

Line thickness

Hello All!

I'm new to OpenTK (OpenGL).
I have troubles in changing line width (line thickness).

I'm building XYZ space with pan, zoom and orbiting camera. For drawing XYZ axis i'm using following code:

drawing axes:

GL.Vertex3(0, 0, -5000); GL.Vertex3(0, 0, 5000);

GL.Vertex3(0, -5000, 0); GL.Vertex3(0, 5000, 0);

draws lines exactly of same thickness.

I tried add

without any success.

I need the lines will be fine thickness, right now they are very thick.

Any help will be very appreciated.

Thanx in advance


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
flopoloco's picture

Hi, does this code works for you? If it does not work then it might be something else wrong.

My notes on this is that I use OpenGL version 1 and also that the minimum for a line is 1 (less than one has no effect).

using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace GLLineWidth
	class MainClass
		public static void Main(string[] args)
			var window = new GameWindow();
			window.RenderFrame += (object sender, FrameEventArgs e) => 
				GL.Vertex2(-1, -1);
				GL.Vertex2(1, 1);
				GL.Vertex2(-1, 1);
				GL.Vertex2(1, -1);

Also for adding line smoothing is somehow a bit tricky, I grabbed one conversation from stack overflow.

There is no guarantee the GL_LINE_SMOOTH will do anything. Although they
look like core functionality my experience is that lots of hardware doesn't
implement these - the ones that do don't implement it consistently, and if
they do implement it the performance hit can be considerable.

In another response:

enabling antialiasing helps - how to enable this depends on your context creation, but this info will hopefully be of use for GLFW users.
If using GLFW 2: glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
If using GLFW 3: glfwWindowHint(GLFW_SAMPLES, 4);
...or whatever number of antialiasing samples you prefer. The above hints need to be set before opening the GLFW window.

This means that OpenTK might provide support for antializing that is based on the context window of the operating systeam rather than OpenGL itself. I don't know exactly if OpenTK has support for this, if some one else knows might answer us.

Although adding this code to the example you will see a significant improvement I but you might get a penalty as well.

			window.Load += (object sender, EventArgs e) => 
				GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
				GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.SrcAlpha);
hnirvana's picture

Thanx flopoloco,

I think i found the problem.
I changed the line thickness between GL.Begin() and GL.End().
After taking out the : GL.LineWidth();
It works nice.

As for the delegate you proposed, unfortunately i got a big penalty :(
something in : GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.SrcAlpha);
After googlling for the BlenfFunc.....still don't understand the difference between different blending techniques.


flopoloco's picture

Neither do I know the techniques, since I started learning OpenGL version 3 already was available so I never got in depth, I went straight to vertex buffer objects instead.

Edit: I found it something but I don't know how it can work.


In order to enable multisample antialiasing, simply pass a positive integer to the samples parameter.
Typical values are 2, 4, 6, 8 and 16, but the exact list depends on the capabilities of your video card.

I change this code in the example but I see no effect.

var samples = 8;
var mode = new OpenTK.Graphics.GraphicsMode(
		OpenTK.Graphics.ColorFormat.Empty, 32, 0, samples);
var window = new GameWindow(800, 600, mode);