trying to make my own 3D modeling tool


I want to start working right away on making a 3D modeling tool.
I want to give the user the freedom to pick, drag and modify each vertex of any basic shape for a start…say a sphere. Could anyone please tell me how I can achieve this ? Besides in the case of the glutsolidsphere() function I would not have access to all its vertices so do I have to write my own sphere function? Please help.

Hi optik,

I think you must start creating lines, polygons and later complex meshes such as a sphere.

Hi Exoide,

Thanks for the suggestion. That makes more sense.
I already have experience creating lines and polygons.
Where I face difficulty is to be able select and move individual vertices of any simple mesh.

Firstly lets just stick to the selection part. Should I store the vertex data in a kind of a structure that also has its corresponding screen co-ordinates so that I can select any particular vertex? But this way how can I differentiate vertices that fall on top of each other? I don’t think my method is good nor is it even fairly efficient.

In that case I think you should start selecting and moving lines and polygons then any other kind of spline or mesh.

Fortunately the OpenGL’s API has the functions needed to select objects and these functions are

  • glInitNames/glPushName/glPopName
  • glSelectBuffer/glRenderMode
  • glFeedbackBuffer/gluPickMatrix

It’s very easy and very fast to implement the selection with these functions.

So if you will use the OpenGL’s API you don’t have to store the vertices in the screen coordinates because it will return to you the vertices or objects (if any) selected by the user.

One more thing, with the API you don’t have to worry about what vertices or objects are forward or backward because in the “selection buffer” are stored the Z values.

This is very well explained in the book “OpenGL Superbible 4th edition. 2007”.

Once you have the vertices or objects selected you know how to carry on.

I hope this help you :wink:


Your application has to be able to store a mesh (and probably other types as well - but a mesh is generic enough to get you started), which will then be edited. There are a few options on what your mesh should have, with the most common approach being to store geometric information as a list of vertices and triangles.

Having the mesh in play, you can use OpenGL to render it. Tip: if you structure your code nicely, the scene graph part and the rendering/ui part of your application will be conveniently separated into different modules, so that you may re-use the scene handling classes in other applications, involving, say, a different rendering library.

To edit the model, the use case starts from the UI end: thisl will be done with opengl, and you’ll have to implement picking (there are a few tutorials on thins I think). Picking will return you a list of entities that are selected. These entities may be individual vertices, triangles, a whole mesh, etc, depending on how you implement it and what you want to do.

In your case, you want to pick vertices. As you suggest, you will come across the situation where you pick a vertex, and there are more vertices hidden behind it (a term describing this is occlusion: the vertices in the back are occluded by the vertex in the front). This is a ui decision you’ll have to make: you can just pikc the front vertex or give the user the opportunity to choose which vertex she wants, etc. IF you only pick the front vertex, the user will have to rotate the view slightly, and un-hide the vertices in the back, in order to pick them. Sometimes, this works well actually.

Following the picking, you’ll have to modify the vertex, so you’re looking at dragging it to a different location. The new coordinates of the vetrex will be stored in your mesh scene object in memory.

Two bits of functionality that you’ll have to think about straightaway are loading and saving the models. Loading because you’ll have to get real data into your app to work with. And saving because the user will have to preserve all the changes they made with your edit tool. Of course, as soon as you start talking loading and saving, you also have to think about what format you’ll be using. (Lots of tutorials on this too, another tip: there is no right or wrong, there are pros and cons with everything, and be prepared to code in support for more than one format, as this will simplify things a lot in the future, if you’re thinking any seriously about this.)

The glutsphere is a utility functionality to create some geometry to play with. If you want to edit that, you’ll have to find its vertices and triangles, create a mesh object and add it in your scene, and then edit it as any other scene entity in your app.

I hope this helps.


Thanks a lot that was more helpful than I expected!
Sorry I have been having tests to take in college, so i have to stay away from the net for a few more days… :frowning:

thanks again!

I am trying the same.Can some one point me to some latest papers on modeling and mesh editing(mainly polygonal models).

Hi again

Additional comment on selecting/picking vertices:

You have 2 main options:

  1. Use the OpenGL selection/picking functionality, in which case you’ll have to implement this via the usual way of enumerating (naming) and rendering the primitives in selection mode, and then processing the hit list. The primitives in this case will be GL_POINTS - note this may be different to what it is you’re drawing.

Also note I haven’t tried this myself, but according to the Red book, you can select/pick primitives, and points are primitives; so there is hope. (I’m sure if that’s not the case, quite a few fellow members of the forum will jump in this discussion and save the day, so worry not…)

  1. You can implement picking in your scene managing code. When the user clicks on the screen, you can get the coordinates, and generate a ray, starting from the camera position and through the (3d) position of the mouse click (with unproject, if I’m not mistaken…).

Then picking can be done via intersecting that ray with the entities in your scene. In your case, the vertices. This is a 3d operation, you need lots of code to do this, so not for the light hearted I suppose. One the other hand, you can split that code from your rendering code, and then it’s portable to other applications you may do. Also, ray/primitive intersection are generally good to have, and once you’ve got them, you’ll find many uises for them.

I hope this clarifies things a bit more.


thanks madmortigan,

I recently got this open source modeling tool called Wings 3D. They have an interesting way of selection. There are 4 buttons which give the user the choice of specifically selecting vertices, edges, faces or the object as a whole. Unfortunately Wings 3D is coded in Erlang which makes it difficult for C++ programmers like myself. But as I see it, it seems fairly easy to implement in OpenGL. I feel setting the priorities in picking primitives in the hit list according to the user’s choice is the key. Ill get back on this topic with any further queries. Thanks a lot for all the help!