PDA

View Full Version : hollow tube with wall thickness



mael15
09-27-2016, 06:48 AM
hi,
i am very new to open gl programming and need to create a straight tube with a certain wall thickness. from 3dsmax i would think to create two cylinders with different radii and boolean subtract the narrow one from the wide one. i also read about creating a circle und extruding it along a path.
what would be the best way and can someone give me a code example? i will have to create hundreds of tubes on one canvas, so efficiency is quite important.
thank you!

john_connor
09-27-2016, 09:35 AM
hi,
i am very new to open gl programming and need to create a straight tube with a certain wall thickness. from 3dsmax i would think to create two cylinders with different radii and boolean subtract the narrow one from the wide one.

sure, but openGL is a graphics API, not a modelling software
what you have to do is to provide the vertices of the tube yourself, for example you model a tube (in blender, 3dsmax or whatever) and export it into a file format from which you are able to load the vertices (for example .obj)
then put those vertices into a "buffer object", create a "vertex aray object" and a "program object" (shaders), then you can render the tube
"instanced rendering" is a way to render effciently the same model multiple times

mael15
09-28-2016, 05:36 AM
you model a tube (in blender, 3dsmax or whatever) and export it into a file format from which you are able to load the vertices (for example .obj)
thank you, i just mentioned 3dsmax as an example for how i know an object might be constructed. i do not plan to use any modelling software with opengl.
what i want to do is enable my program to visualize a bundle of hundreds of tubes. tubes of one bundle all have the same diameter, wall thickness and length, but another bundle might have different tubes. so i have to custom create the tubes for every bundle. additionally, every tube will get its individual texture.
so what is the best way?

Silence
09-28-2016, 05:48 AM
Just do that the same than with your modeler. Maths are not that complicated. It's just two disks, and you just join each vertex of the two disks. Then join the vertices of the inner and outter cylinders.

Here (https://www.opengl.org/discussion_boards/showthread.php/167115-Creating-cylinder) I found an old topic about this. It uses fixed-pipeline OpenGL but it will be easy to adapt it to use VBOs if needed.

mael15
09-28-2016, 06:08 AM
Then join the vertices of the inner and outter cylinders.

ok, thank you, and with "join" you mean put everything between glBegin(GL_TRIANGLE_STRIP) and glEnd()? sorry, but i am VERY new to this.

john_connor
09-28-2016, 07:42 AM
ok, thank you, and with "join" you mean put everything between glBegin(GL_TRIANGLE_STRIP) and glEnd()? sorry, but i am VERY new to this.

"join" means how you create "primitives" (like triangles of quads)
GL_QUADS gives you a quad for each 4 vertices
GL_TRIANGLE_STRIP gives you a triangle for the first 3 vertices, then for each addidional vertex

i would recommend you to first understand 2D rendering (simple triangle / quad / line / etc), then make a simple 3D task (cube with camera)
after you have understood these basic things, it is just a "math problem" to make a tube (a simple for-loop), you just have to calculate the "corner points" of the tube (inner and outer circle points), but them into a buffer an issue a drawcall

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/

GClements
09-28-2016, 10:28 AM
Find a tutorial (or book) on modern OpenGL (using shaders and VBOs) rather than legacy OpenGL (glBegin/glEnd).

If you're rendering many of these tubes, instanced rendering is likely to be useful, and you can't do that with the legacy approach.

Carmine
09-28-2016, 04:44 PM
thank you, i just mentioned 3dsmax as an example for how i know an object might be constructed. i do not plan to use any modelling software with opengl.
what i want to do is enable my program to visualize a bundle of hundreds of tubes. tubes of one bundle all have the same diameter, wall thickness and length, but another bundle might have different tubes. so i have to custom create the tubes for every bundle. additionally, every tube will get its individual texture.
so what is the best way?

So each individual tube is straight, not bent like a strand of hair?

If you have a starting program written in Legacy GL, post the code, and I'll help you.

This is not that hard.

Silence
09-28-2016, 10:53 PM
ok, thank you, and with "join" you mean put everything between glBegin(GL_TRIANGLE_STRIP) and glEnd()? sorry, but i am VERY new to this.

Exactly. You just swap from one cylinder vertex to the other cylinder vertex until you reach the first point again.

mael15
09-29-2016, 11:27 PM
thank you everyone! i think i am on my way now. my boss just changed the requirements from "hollow tube" to "plain cylinders" but it is good to know how a hollow tube with a specific wall thickness can be made :)


If you're rendering many of these tubes, instanced rendering is likely to be useful, and you can't do that with the legacy approach.
that sounds very helpful and i will look into that.


If you have a starting program written in Legacy GL, post the code, and I'll help you.
that is very kind, thank you. i think i can handle it :)