Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL 3.2 Core Profile glLineWidth

I'm setting up a OpenGL 3.2 Core context on Mac OS X. I want to be able to draw some thick black likes on the screen. In pervious version of OpenGL, I could just set

glLineWidth(10.0f);

and I will get a line 10 pixels wide. However when I check the line width ranges in 3.2 Core

GLint range[2];
glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range);
glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, range);

I get the values of 1 for Aliased Lines and 0-1 for Smooth lines. How can I make a line that is 10.0 pixels wide in screen space? Is there a simple way to draw this other than making each line segment a rectangle?

like image 559
user1139069 Avatar asked Jan 09 '12 16:01

user1139069


2 Answers

Using OpenGL 3.2 core profile, calling glLineWidth with a value greater than 1.0 give an INVALID_VALUE error (call glGetError to prove it).

Surely you can get the wanted result by determining the quad required for drawing the line.

I think you should be able to generate quads from from line points: hey, a larger line is a quad! Maybe you could use techinques like this to get your wanted result.

The key is: instead of rely on LineWidth, you give a unit quad as input (4 vertices using triangle strip), then transform incoming vertices inside a shader passing to it appropriate uniforms.

Maybe another approach would be rendering using a geometry shader: generate a quad from a point. However, I'm not sure about this point. I don't know if a geometry shader (only if it feasible, of course) would be the best approach: the cost of drawing a line strip using a single quad would be the shader uniform setup for each line composing the strip.

like image 173
Luca Avatar answered Nov 01 '22 15:11

Luca


This could be depending on the type of projection you set up. Are you using orthographic or perspective projection matrix?

I think that if you are not using the orthographic projection, the final rasterisation of the primitive will be subject to the distance of the object (model matrix) from the camera (view matrix).

Cheers

like image 27
Maurizio Benedetti Avatar answered Nov 01 '22 15:11

Maurizio Benedetti