Custom line rendering using traingles, how to do joints

Started by
5 comments, last by _WeirdCat_ 5 years, 8 months ago

 

originally, i just use GL_LINE_STRIP to render lines and it has been evident in different device the difference in width of the lines, plus i cannot texture it!

so i decided to use triangles to render my lines so i can have control on its width and add some textures,,

i can already convert a line segment based from two given points, or two lines using 3 points using textured quad, I want to do the joints of these quads next,

since the app needs to draw using the mobile touchscreen, so it is fitting to have a circular cap/joints instead of those pointy joints.

I saw some lessons and tutorials and they suggest as simple as adding a circle in the joint end, is that really how simple it is done?
Let me know if you guys have any tips and further suggestions, or link to a source/tutorial (OpenGL/OGL ES).

much appreciated!

Advertisement

The simplest solution may be as you describe: render the segments as quads, and render appropriately sized circles at the nodes. There may be some drawbacks to this method though, including (but not limited to) the fact that it probably won't work with non-unity alpha (because you'll be able to see the quads under the circles or vice versa).

If you want to do something more complicated, you can use procedurally generated meshes. This should eliminate issues such as the aforementioned overlapping. I've done this before with good results, although building the meshes can be non-trivial (especially if more than one segment can meet at a node).

There may be other ways to do it as well, and perhaps you'll get some other suggestions, but for what it's worth I've had good luck using meshes for this in the past.

 

If you have different line width on diffndevices either your drawing routine is wrong, or you might need to set glLineWidth, or you just simply see a difference on different screen sizes resolutions - but they always should be the same. And you can texture lines aswell.

Drawing lines is hard. That being said, drawing caps/miter joints in of themselves is a matter of some trigonometry, but properly texturing the line in 3D gets a bit nastier as you'll either have up to up the tessellation quite a bit in corners, resort to projection or perform some sort of fancy triplanar texturing to avoid distortion.

8 hours ago, _WeirdCat_ said:

If you have different line width on diffndevices either your drawing routine is wrong, or you might need to set glLineWidth, or you just simply see a difference on different screen sizes resolutions - but they always should be the same. And you can texture lines aswell.

Hi, ive been wondering how to texture a GL_LINES in OpenGL, the thing is im using OpenGL ES 2.0, so it may be possible for desktop OpenGL 3.3+ but im not sure if it is possible to texture a line in OpenGL ES 2.0

Its really possible, in fragment shader you just output the line color so either it can be a texture pixel or sqrt(e=mc^2) or cute little kittens there. You need to pass lets say a texturr coordinate, it really doesnt differs from drawing a textured triangle

This topic is closed to new replies.

Advertisement