Question

I'm drawing some objects to a view in my application using OpenGL with GLKit. I have been trying to add a stroke to one of the objects I'm drawing, but I can't figure out a good way to do that. I could probably add a stroke using a texture or by drawing lines over the object, but those don't sound like good/smart methods. What is the usual method to draw an object with a stroke?

This is the code I'm currently using (modelViewMatrix and vertices are defined elsewhere):

GLKBaseEffect *effect = [[GLKBaseEffect alloc] init];
effect.useConstantColor = YES;
effect.constantColor = kPlayerColor;
effect.transform.projectionMatrix = modelViewMatrix;
[effect prepareToDraw];

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

glDrawArrays(GL_TRIANGLE_STRIP, 0, sizeof(vertices) / sizeof(vertices[0]));
glDisableVertexAttribArray(GLKVertexAttribPosition);

In the following picture you can see what I currently draw (on the left) and what I would like to draw (on the right):

Images with (right) and without stroke (left)

So basically all I'd like to do is add a stroke (in this case black) to an object. Not all objects are as simple as this example.

Summarized my question is: how do draw an object with stroke using OpenGL?

Was it helpful?

Solution

Simplest way to do outline like that is to render model as wire frame with thick lines, then render it again normally above the lines.

Or you can render abit scaled up model with solid color and the again render normally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top