I am working on a project where I have to create a chain with 12 links in it. I want to create the chain out of two curved segments for the top and bottom of the link ad two cylinders for the straight segments, I intend to use a display list to create one link and then display it over and over after applying some rotation transformations. My question is how can I construct the curved sections?
One idea was to use gluPartialDisk(); swept thru 180 degrees to construct the top and bottom portions. is there a more efficient way of doing this?
PS: Forgot to mention that this was to be in 3D, I guess gluPartialDisk() will not work in this case. I want to use basic OpenGL shapes to create this rather than using 3D modeler, this way I will be able to learn more about OpenGL.
Assuming you want to use display lists, gluPartialDisk() is probably efficient enough (and it's not worth the effort to implement it yourself).
However, there are methods that are even faster than using display lists themselves. I would highly suggest using vertex arrays or vertex buffer objects.
Related
My PhD project revoles around simulating the paths of photons through objects of different optical properties. My code has classes which create ccd images etc, but it would be much more useful to be able to create a simple rendering of the 3D objects and the paths the photons take through them.
I've written an opengl system for viewing such a scene, but it would be much better if I could use something much more lightweight where I could simply specify the vertices of an object, and then a photon path as a list of connected vertices.
Exporting all the data and then visualising it in another program isn't ideal, as things like mesh transformations need to be taken into account, and I'd rather avoid exporting several new mesh objects just to import them all into another program.
What I essentially need is to be able to create the three dimensional equivalent of a svg image. Does such a '3D scene' file format with a simple visualiser exist?
I write in C++ on MacOS, though I'd prefer to avoid using a visualisation library. I appreciate that what I'm asking for is rather niece and picky, but that's why I'm asking the internet as someone might have come across a similar need for such a tool.
I need to draw some undirected graphs with different coloured vertices. Previously I have been doing this the tedious way, by drawing every vertex as a circle and every edge as a straight line. Is there a way that I can do this easily by using the Bezier curve function? I have tried to do this, but can't work out how to add vertices to my lines!
I'm guessing you want to create un-directed graphs with curved edges (since you mention Bezier curves).
I find that the easiest way to draw freestyle graphs is to lay down your vertices as circles (copy & paste for consistent size) and then use the "draw freehand lines" option (pencil icon) to connect the dots. Then you send the circles to the front layer, so the lines look like they start and end at the edges of your circles. If you really want to use Bezier curves instead of free hand, then the method applies just the same. Here's a sample I created using the first method.
Hope this helps.
So this answer uses an external tool as part of the process, but the end result is still a (good looking) graph inside of inkscape. So for anyone who wants relatively hassle free graphs inside inkscape (or other software) who stumbles across this question, hopefully this will be useful.
There is a (free) tool called the yEd Graph Editor which allows for simple creation of graphs, and after creating a graph you can copy them to the system clipboard (right-click menu) and paste them into inkscape. It requires installing an additional piece of software, but the process can be much faster than creating them manually in inkscape as yEd makes it easy to deal with things like layout, node style, edge style and similar.
This process works with other image software as well, both those that work in bitmap and vector graphics and yEd works with a wide range of graph types.
I want to model the (biological) cell division process. I have been able to create a 3D cell model and load the model (using glm library). However, I do not know how to make it divide and I don't know where to start.
Does any one know how to make the effect that things replicate in OpenGL? (It is great if I can use glut and glm for that). Maybe you could just show me how to make a sphere replicate.
I think what you're looking for is called meta-particles or meta-balls. I think that by adjusting thresold function you can get cell-divide effect, but this isn't guaranteed - metaballs normally look more like quicksilver and are used to create water out of particles.
They're hard to implement in 3d for a novice - you'll need to be able to make triangular mesh out of mathematically-defined surface (marching cubes algorithm), and result isn't guaranteed to be fully realistic.
I suggest to try something else or use some cheaper way - draw two seme-transparent spheres on top of each other then move them apart or something like that.
Of course, certain way to get desired result is to use modeling package (like blender) and skilled artist, but displaying modeled result in your application will be difficult, because object topology will be changing every frame, plus making satisfactory result will take time and skill.
I was wondering, I have an algorithm of mine that I want to test with a high poly-count model. (I'm using a hard coded cube and surface atm). I know you can draw objects with the GluSolid* commands.
But the problem is, for my alogrithm I need access to the coordinates of the triangles the object consists of. Is there an easy way to access these, or is that not possible?
I think there's not really an easy way to obtain these coordinates as they are just sent to the GL when calling these functions (you might use transform feedback, but that is definitely too cumbersome for your purpose). But these primitives are actually quite simple. You can quite easily generate a sphere or cylinder mesh yourself. Or write a small function for reading a common 3d model format (OBJ is quite common and easy to read), so you can search the web for models or create test models with your favourite modeling software.
I am working on a simple CAD program which uses OpenGL to handle on-screen rendering. Every shape drawn on the screen is constructed entirely out of simple line segments, so even a simple drawing ends up processing thousands of individual lines.
What is the best way to communicate changes in this collection of lines between my application and OpenGL? Is there a way to update only a certain subset of the lines in the OpenGL buffers?
I'm looking for a conceptual answer here. No need to get into the actual source code, just some recommendations on data structure and communication.
You can use a simple approach such as using a display list (glNewList/glEndList)
The other option, which is slightly more complicated, is to use Vertex Buffer Objects (VBOs - GL_ARB_vertex_buffer_object). They have the advantage that they can be changed dynamically whereas a display list can not.
These basically batch all your data/transformations up and them execute on the GPU (assuming you are using hardware acceleration) resulting in higher performance.
Vertex Buffer Objects are probably what you want. Once you load the original data set in, you can make modifications to existing chunks with glBufferSubData().
If you add extra line segments and overflow the size of your buffer, you'll of course have to make a new buffer, but this is no different than having to allocate a new, larger memory chunk in C when something grows.
EDIT: A couple of notes on display lists, and why not to use them:
In OpenGL 3.0, display lists are deprecated, so using them isn't forward-compatible past 3.0 (2.1 implementations will be around for a while, of course, so depending on your target audience this might not be a problem)
Whenever you change anything, you have to rebuild the entire display list, which defeats the entire purpose of display lists if things are changed often.
Not sure if you're already doing this, but it's worth mentioning you should try to use GL_LINE_STRIP instead of individual GL_LINES if possible to reduce the amount of vertex data being sent to the card.
My suggestion is to try using a scene graph, some kind of hierarchical data structure for the lines/curves. If you have huge models, performance will be affected if you have plain list of lines. With a graph/tree structure you can check easily which items are visible and which are not by using bounding volumes. Also with a scenegraph you can apply transformation easily and reuse geometries.