draw a skeleton OpenGL

Hello
I am newbie in opengl programming, I have a problem I want to draw a skeleton.

I wrote a program but uses Loop, so I draw closed shapes.

I want to have a form like this:
[ATTACH=CONFIG]636[/ATTACH]

It seems to me you’ve already identified the problem: using GL_LINE_LOOP as primitive type will produce a closed loop, try GL_LINES or GL_LINE_STRIP instead. Note that for GL_LINES you’ll have to repeat vertices that are both endpoint of a line and startpoint of the next one. Or perhaps I’m misunderstanding your question?

thank you

but that I use strip but I can draw without lifting the pen, and so I can not rlier members’ arms legs … "

Draw multiple GL_LINE_STRIPs: if you are using glBegin()/glEnd(), end the current strip with glEnd() and start a new one with glBegin(GL_LINE_STRIP), if you are using glDrawArrays or some similar draw call you need multiple of those [1], one for each STRIP. Alternatively you can draw individual GL_LINES.

[1] When using indices (glDrawElements and friends) you could also make use of glPrimitiveRestartIndex, but that is more of an advanced topic.

PS: As you can see from the various alternatives in my reply it would be helpful if you included more details about what you are doing in future questions, that makes it easier to give an answer to your specific problem, see also [thread=176139]Forum Posting Guidelines[/thread] for suggestions of what to include in questions.

[QUOTE=carsten neumann;1259475]
PS: As you can see from the various alternatives in my reply it would be helpful if you included more details about what you are doing in future questions, that makes it easier to give an answer to your specific problem, see also [thread=176139]Forum Posting Guidelines[/thread] for suggestions of what to include in questions.[/QUOTE]


	if (pointsSupprimer.size() >= 2)
	{
		glBegin(GL_LINE_LOOP);


		// glBegin(GL_POINTS);
		for (int unsigned i = 0; i<pointsSupprimer.size(); i++) {
			glColor3f(1.0, 0.0, 0.0);
			glVertex2i(pointsSupprimer[i].xval, pointsSupprimer[i].yval);

		}




		glEnd();

		glutSwapBuffers();

	}

Please use [noparse]


[/noparse] around source code snippets to preserve formatting, thanks!

Ok, so you are using glBegin()/glEnd(), but the code is still drawing one GL_LINE_LOOP, so all parts of the skeleton will be connected. As mentioned before, you’ll have to draw multiple GL_LINE_STRIPs, one for each part of the skeleton, something like this pseudo code:


for each skeleton_part in skeleton:
{
    glBegin(GL_LINE_STRIP);
    for each vertex in skeleton_part:
    {
        glVertex2(vertex.x, vertex.y);
    }
    glEnd();
}

[QUOTE=carsten neumann;1259478] GL_LINE_STRIPs, one for each part of the skeleton, something like this pseudo code:


for each skeleton_part in skeleton:
{
    glBegin(GL_LINE_STRIP);
    for each vertex in skeleton_part:
    {
        glVertex2(vertex.x, vertex.y);
    }
    glEnd();
}

[/QUOTE]
please every part of the skeleton will be stored in a table ?

I guess so, yes.
It really depends on what you want to do. If all you need is drawing the skeleton as lines and points representing a skeleton_part as an array (or std::vector) of vertices is sufficient; a skeleton would then be an array (or std::vector) of skeleton_parts. If on the other hand you want to eventually use the skeleton to animate a mesh it may be better to represent each joint as a distinct object.

[QUOTE=carsten neumann;1259482]I guess so, yes.
It really depends on what you want to do. If all you need is drawing the skeleton as lines and points representing a skeleton_part as an array (or std::vector) of vertices is sufficient; a skeleton would then be an array (or std::vector) of skeleton_parts. If on the other hand you want to eventually use the skeleton to animate a mesh it may be better to represent each joint as a distinct object.[/QUOTE]
oui je veux animer le squelette comme ça , c’est notre propre simulateur :
https://www.youtube.com/watch?v=XGjTt5H5Qt0

I did not understand "each joint as a distinct object "is what I have to define structures

thanks

Yes, I meant making a joint a struct or class, since in case you want to animate them you’ll likely want to store a bunch of information about each joint. So, perhaps something along these lines:


struct Joint
{
    vec3f offset_;
    quatf rotation_;

   Joint*                    parent_;
   std::vector<Joint*> children_; 
};

struct Skeleton
{
    std::vector<Joint*> roots_;
};

Where quatf stores a quaternion. Note that the above is merely for illustration, there are other ways to represent the joint hierarchies and lots of options of what information to store in the joints.