Jump to content
  • Advertisement
cebugdev

OpenGL ES Custom line rendering using traingles, how to do joints

Recommended Posts

 

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!

Share this post


Link to post
Share on other sites
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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!