Y
Y
Yura Imashev2015-01-16 21:03:01
iOS
Yura Imashev, 2015-01-16 21:03:01

Is it possible to smoothly change line thickness in OpenGL ES?

I have several lines and I need to smoothly change their thickness from the minimum (1 px) to some other (let's say 3 px). I know the coordinates of the ends of all lines, moreover, all lines are either vertical or horizontal. Can this be done using OpenGL ES?
The problem is that the standard function, glLineWidthtaking a fractional number, converts it to an integer, due to which the line thickness changes discretely.
If you can't do it with line drawing tools, then perhaps there is another way or trick, like drawing polygons? It's just hard to believe that such a simple task can't be done with such a powerful library as OpenGL.
My code:

- (void)setupGL
{
    [EAGLContext setCurrentContext:self.context];

    self.effect = [[GLKBaseEffect alloc] init];

    glEnable(GL_DEPTH_TEST);

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(thinLines), thinLines, GL_STATIC_DRAW);

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

    glBindVertexArrayOES(0);
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindVertexArrayOES(_vertexArray);

    self.effect.constantColor = GLKVector4Make(lineR, lineG, lineB, 1.0f);
    [self.effect prepareToDraw];

    glLineWidth(1 + scaleQ);
    glDrawArrays(GL_LINES, 0, thinLinesCount*2);   
}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
maaGames, 2015-01-17
@maaGames

Judging by the description, when using screen anti-aliasing, the thickness can be fractional, and when anti-aliasing is disabled, it is rounded to a smaller integer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question