Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:53:57+00:00 2026-05-23T08:53:57+00:00

I am using the gluTess* functions to draw non-convex polygons. To avoid redoing the

  • 0

I am using the gluTess* functions to draw non-convex polygons. To avoid redoing the tesselation at every step, I store the result in an array and use the vertex array capabilities of OpenGL to draw.

My problem is that, for some reason, the first time I use the gluTess* only part of the triangles are drawn. If I force to recreate the gluTess*, then everything is fine.

Note that, to recreate the gluTess*, I completely destroy the object containing the vertex array and recreate it (which forces the recalculation of the vertex array object).

Any idea on why that would be the case?

Some random ideas:

  • could it be because for the first OpenGL call the window is not yet at its full size?
  • do I need to set some OpenGL state, that would be done later, but not on the very first call?

Thanks.

Edit: As a test, I just created, destroyed, and recreated the vertex array. It solve the problem. Which means: without any change in the OpenGL state, the first call to gluTess* fails to tesselate the polygon correctly. But the second one succeed. Did anybody notice that before?

Edit (2): Here is the code:

VA va;
GLUtesselator *t = gluNewTess();
gluTessCallback(t, GLU_TESS_BEGIN_DATA, (GLvoid (*)())beginVA);
gluTessCallback(t, GLU_TESS_END_DATA, (GLvoid (*)())endVA);
gluTessCallback(t, GLU_TESS_VERTEX_DATA, (GLvoid (*)())vertexVA);
gluTessCallback(t, GLU_TESS_ERROR, (GLvoid (*)())&tessError);
gluTessCallback(t, GLU_TESS_COMBINE, (GLvoid (*)())&tessCombine);

gluTessProperty(t, GLU_TESS_BOUNDARY_ONLY, GL_FALSE);
gluTessProperty(t, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);

gluTessBeginPolygon(t, &va);
gluTessBeginContour(t);
foreach(Point3d& p, points)
  gluTessVertex(t, const_cast<GLdouble*>(p.c_data()), (void*)&p);
gluTessEndContour(t);
gluTessEndPolygon(t);
gluDeleteTess(t);

As the second call succeed, I suspect that beginVA, endVA and vertexVA work fine (as I said, the second call is made by destroying the data structure VA, which mostly hold the vertex array).

Edit (3): Here is the missing code:

struct VA
{
  std::vector<Point3d> positions; // Vertex array
  GLenum current_mode; // Drawing mode (GL_TRIANGLE, *_FAN or *_STRIP)
  Point3d v1, v2; // Two last vertices for _FAN or _STRIP
  bool has_v1, has_v2; // did we get the two last vertices?
  int n; // Index of the vertex, for *_STRIP
};


void beginVA(GLenum mode, VA *va)
{
  va->current_mode = mode; // Store the mode
  va->has_v1 = va->has_v2 = false; // We haven't had any vertex yet
  va->n = 0;
}

void endVA(VA *va)
{
  va->current_mode = 0; // Not really necessary, but cleaner
}

void vertexVA(Point3d *p, VA *va)
{
  ++va->n;
  if(va->current_mode == GL_TRIANGLES) // The simple case
    va->positions.push_back(*p);
  else if(!va->has_v1) {
    va->v1 = *p;
    va->has_v1 = true;
  } else if(!va->has_v2) {
    va->v2 = *p;
    va->has_v2 = true;
  } else if(va->current_mode == GL_TRIANGLE_STRIP) {
    if(va->n%2 == 1) {
      va->positions.push_back(va->v1);
      va->positions.push_back(va->v2);
      va->positions.push_back(*p);
    } else {
      va->positions.push_back(va->v2);
      va->positions.push_back(va->v1);
      va->positions.push_back(*p);
    }
    va->v1 = va->v2;
    va->v2 = *p;
  } else { // GL_TRIANGLE_FAN
    va->positions.push_back(va->v1);
    va->positions.push_back(va->v2);
    va->positions.push_back(*p);
    va->v2 = *p;
  }
}

Edit (4): In the end, the error was somewhere else. I must have been tired, I used a std::vector to store the result of the combine function. I don’t know why it worked later, but it was sure normal it didn’t work the first time! Sorry about that, I’ll now close this subject.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:53:58+00:00Added an answer on May 23, 2026 at 8:53 am

    OpenGL and GLU are independent from each other. They usually come together, but the GLU tesselation functions work independently from OpenGL.

    That you store the tesselated vertex data is a good thing, that’s how it should be done.

    EDIT: answered by first two question edits:

    Did you try to issue a redraw
    without recreation of the tesselated
    data?

    It would be much easier to give a good
    and sensible answer if you’d show the
    relevant code and its context.

    EDIT: answered by third question edit:

    Next question: What’s the signature
    of beginVA, endVA, vertexVA? And how
    does vertexVA insert the vertex into
    VA. How does VA look like? (class,
    structure definition, etc).

    May I offer a suggestion:

    struct VA
    {
      std::vector<Point3d> positions; // Vertex array
      std::vector<GLuint> triangle_face_indices;
      std::vector<GLuint> tristrip_face_indices;
      std::vector<GLuint> trifan_face_indices;
      GLenum current_mode; // Drawing mode (GL_TRIANGLE, *_FAN or *_STRIP)
    };
    
    void beginVA(GLenum mode, VA *va)
    {
      va->current_mode = mode; // Store the mode
    }
    
    void endVA(VA *va)
    {
      va->current_mode = 0; // Not really necessary, but cleaner
    }
    
    void vertexVA(void *p, VA *va)
    {
      GLuint idx = (GLuint)((intptr_t) p);
    
      switch(va->current_mode) {
      case      GL_TRIANGLES: va->triangle_face_indices.push_back(i); break;
      case GL_TRIANGLE_STRIP: va->tristrip_face_indices.push_back(i); break;
      case   GL_TRIANGLE_FAN: va->trifan_face_indices.push_back(i); break;
      }
    }
    

    used like this

    gluTessBeginPolygon(t, &va);
    gluTessBeginContour(t);
    for(GLuint i = 0; i < va.positions.size(); i++) {
      gluTessVertex(t, const_cast<GLdouble*>(va.positions[i].c_data()), (void*)((intptr_t)i));
    }
    gluTessEndContour(t);
    gluTessEndPolygon(t);
    gluDeleteTess(t);
    

    And draw using 3 consecutive calls to glDrawElements for either draw mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using select statement we can call functions inside the stored procedure, is there another
Using just python, is it possible to possible to use a USB flash drive
Using VB6 & Crystal Report 9. Need help with the VB6 code. When i
Using the pthread library in C, is it possible to send a SIGSTOP signal
Using XSLT 1.0, I'm trying to essentially create a small node set and then
Using the NuPack addin and installing the NInject MVC 3 package results in the
Using Java (1.6) is it better to call the clear() method on a List
Using Facebox with .NET (Web Forms) is painful--this primarily HTML site was designed by
Using Visual Studio, I have built an C++ application running in 32bit. It will
Using VB or C#, I am getting a string of variable length from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.