vedeveloper
asked on
OpenGL tesselation 2
Hi,
Please see my related question, I have another problem with that code.
Using the example, I am passing 4 vertices with gluTessVertex, however, in the callback function, I am getting four vertices.
I thought the whole purpose of these tesselation functions was to split the polygons into a series of triangles. I would therefore expect to get 6 vertices (for two triangles) in the callback function. My task was to use the OpenGL tesselation functions so I could get the list of triangles out for any given polygon (with holes, later).
Either I've misunderstood something or my code is incorrect.
Any help is greatly appreciate as before.
Regards
Please see my related question, I have another problem with that code.
Using the example, I am passing 4 vertices with gluTessVertex, however, in the callback function, I am getting four vertices.
I thought the whole purpose of these tesselation functions was to split the polygons into a series of triangles. I would therefore expect to get 6 vertices (for two triangles) in the callback function. My task was to use the OpenGL tesselation functions so I could get the list of triangles out for any given polygon (with holes, later).
Either I've misunderstood something or my code is incorrect.
Any help is greatly appreciate as before.
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. So how do I change my code so I can get the triangles?
ASKER
It's actually a triangle fan btw
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> My task was to use the OpenGL tesselation functions so I could get the list of triangles out for any given polygon (with holes, later).
That will work anyway, you just have to store the points and the trianglulation type for a set of points(GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_TRIANGLES), thats it :)
That will work anyway, you just have to store the points and the trianglulation type for a set of points(GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_TRIANGLES), thats it :)
ASKER
I just want to get the triangles out. Obviously, it's easy to do manually with quads but I will have polygons with any number of vertices / holes.
I've done a similar thing in the past with more detailed code and that worked ok, I'm just trying to do the same thing on a simple example.
I've done a similar thing in the past with more detailed code and that worked ok, I'm just trying to do the same thing on a simple example.
ASKER
I'm using the triangles to create a mesh in Ogre3D and am storing the points from the callback function as well as the triangulation type.
However, if I add a hole then there are two calls to the begin callback function. One is type 0 (triangle fan) and the other is type 1 (triangle strip).
How do I know which tessellation type to create the mesh with? Ogre has triangle list, strip and fan but how do I choose which one is correct to use? I'm talking about all possible cases.
Also, surely there are combinations of polygons and holes that cannot be represented by a triangle fan or strip? But a list of triangles will always work. Consider the case where the hole splits the polyogn into two pieces - that's why I always wanted to get a triangle list.
The other code seems to always produce triangle lists so I'm wondering if it is telling glu to always use triangle lists even though they may be less efficient?
However, if I add a hole then there are two calls to the begin callback function. One is type 0 (triangle fan) and the other is type 1 (triangle strip).
How do I know which tessellation type to create the mesh with? Ogre has triangle list, strip and fan but how do I choose which one is correct to use? I'm talking about all possible cases.
Also, surely there are combinations of polygons and holes that cannot be represented by a triangle fan or strip? But a list of triangles will always work. Consider the case where the hole splits the polyogn into two pieces - that's why I always wanted to get a triangle list.
The other code seems to always produce triangle lists so I'm wondering if it is telling glu to always use triangle lists even though they may be less efficient?
>> How do I know which tessellation type to create the mesh with?
Store it with the points, like you said here:
"and am storing the points from the callback function as well as the triangulation type."
Store it with the points, like you said here:
"and am storing the points from the callback function as well as the triangulation type."
ASKER
Yes, but there are two calls to the begin callback, one is a triangle strip and one is a triangle fan so which one do I know will be correct?
>> Also, surely there are combinations of polygons and holes that cannot be represented by a triangle fan or strip?
Right, you would have to use more than 1 lists for a mesh, but thats normal.
>> The other code seems to always produce triangle lists
What other code?
Right, you would have to use more than 1 lists for a mesh, but thats normal.
>> The other code seems to always produce triangle lists
What other code?
ASKER
The other code is a massive project, too large to post here. It was there that I first learned I could intercept the triangles during the tessellation process.
So does the begin callback function get called for every seperate list / strip / fan or once for every contour I put in?
If there's some way to just tell glu to use triangle lists then it would be so much easier.
So does the begin callback function get called for every seperate list / strip / fan or once for every contour I put in?
If there's some way to just tell glu to use triangle lists then it would be so much easier.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> So does the begin callback function get called for every seperate list / strip / fan or once for every contour I put in?
Yes.
>> If there's some way to just tell glu to use triangle lists then it would be so much easier.
No.
Yes.
>> If there's some way to just tell glu to use triangle lists then it would be so much easier.
No.
ASKER
Yes? Which one? Every seperate list / strip / fan or every contour?
Taking it one step back. It would be much easier, if you use any 3D-Modeling Tool (Blender, 3Ds Max, Maya) and export it in a format that can be read by Ogre, that'll safe you a lot of trouble.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm writing a modelling tool so exporting isn't an option unfortunately.
How do I know how many vertices are for the strip and how many for the fan?
How do I know how many vertices are for the strip and how many for the fan?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ahhhh, gotcha (I think)
I mean something like this:
#include <vector>
struct point
{
// convenience ctor
point(GLdouble _x, GLdouble _y, GLdouble _z) : x(_x), y(_y), z(_z) {}
GLdouble x, y, z;
};
// represents a vertex list and its geometry type
struct VertexList
{
// GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_TRIANGLES or GL_LINE_LOOP
GLenum geometryType;
// dynamic array of points
std::vector<point> points;
};
// array from vertex-lists
std::vector<VertexList> vertexLists;
void tcbBegin(GLenum which)
{
glBegin(which);
// add a new vertex list
vertexLists.resize(vertexLists.size() + 1);
// and set the geometry type of the new vertex list
int currentList = vertexLists.size() - 1;
vertexLists[currentList].geometryType = which;
}
void tcbEnd(void)
{
glEnd();
}
void tcbVertex(GLvoid *vertex)
{
const GLdouble *pointer;
pointer = (GLdouble *) vertex;
glVertex3dv(pointer);
int currentList = vertexLists.size() - 1;
// add this point to the current vertex list
vertexLists[currentList].points.push_back(point(pointer[0], pointer[1], pointer[2]));
}
ASKER
That's great, cheers
Do you need any more assistance here?
ASKER
Not sure, working on it at the moment...
ASKER
Ok that seems to be working, when accepting a solution does it affect your points if I just pick one of your replies? Really it's the whole discussion that's helped!
Great to hear it helped
Its best to choose the posts that helped you. it it was more than one post, pick them too. That will lead other readers searching the database to the solution, so its better for the community too.
Points are split between those answers, but since its all my answers, I get the points anyway.
Good luck for your project :)
ike
Its best to choose the posts that helped you. it it was more than one post, pick them too. That will lead other readers searching the database to the solution, so its better for the community too.
Points are split between those answers, but since its all my answers, I get the points anyway.
Good luck for your project :)
ike
ASKER
Thanks, this all seems to be working properly now.
ASKER
Ike is a legend
gluTessCallback(tess, GLU_TESS_BEGIN, ...
With the code from your last question, that would be:
Open in new window