Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles


Chronological Thread 
  • From: "Ch'Gans" <>
  • To:
  • Subject: Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles
  • Date: Fri, 14 Apr 2017 15:47:02 +1200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:ADRRpRV13UxKbUJP5pHiTYA9AijV8LGtZVwlr6E/grcLSJyIuqrYYxyEt8tkgFKBZ4jH8fUM07OQ6PG8HzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjSwbLd9IRmssQndqtQdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KptVRTmijoINyQh/W7VhMx+jKxVrhG8qRJh34HZe52VOOZkc6/BYd8WWWhMU8BMXCJBGIO8aI4PAvIPMetGr4nxpFoAogG4BQm3Cu/k1zhFiWP23a01yeshFxrG0RcvH9IIqnvYttL1NL0dUe2syqTD0DvNb/RT2Tjn6YjIdAgsofeWUr1rasXRzVcgGxnZgVWXrIzpJzKV1uIXs2ia9eVsT+yvi3QhpgpsoTav3t8hhpfVio8R0FzJ9iV0zJwrKdGlSUN3e8OoHZpUuiycKoB4WNktQ3tytyY/0rAGuYC0fCwNyJk/wh7Qcf2Hc4yR7hL6SOadPS50hHx4dL++gxu+60egyur7Vsm71FZFsDBJncXLtnAIzxDT686HReVh/kq5xzqDywTe5vtHLE00j6bXNYMtz78qmpYOsEnOGjf6mEDsg6+XckUk9PKo6+PiYrj+upCcN4B0hRv4MqQ1gcG/DuE4PRIPX2if4+izyLrj/UjhTLVQkvI2irXZsIzdJckDuqG5DBVa0oI65xmiDjemy8gXnWQcLFJeYx+HlIjoO1TWIP/iF/u/glKskC1qx//cJLHhDI/NfTD+lqz8d+N991JE01h0istO4opdTLAHOvP6HEHr88fJCwcwdA2yzeGgA9p00sYSWHmEH7SCY5/V5FSH7+ZqL+iXb5IOox78LeIk7rjglywXg1gYKOOC3dQ4YXajVLwyKEWWaHz3qtgHGCENpAVoH7+is0GLTTMGPyX6ZKk7/DxuUI8=

On 14 April 2017 at 15:05, mikef
<>
wrote:
> I am using CGAL "make_surface_mesh" to create a mesh out of an ellipsoid
> function, then using OpenGL to draw it by plotting triangle by triangle. I
> have no clue what is going on...

Sounds like you have a problem with your normals and or your winding
direction.
What is likely happening is that your holes (grey) have the wrong
facing so they are not rendered, and the white have the wrong normals,
so their lighting is wrong.

OpenGL has x going right, y going up and z going towards you, CGAL has
x going right, y going toward the screen and z going up. With OpenGL
defaults, a front facing triangle is CCW and is rendered, a back
facing triangle is CW and is not rendered.

My 2 cents.
Chris

>
> *Problem:* the plotted surface is weird, some triangle has color, some not,
> some are like holes.
>
> *My codes for mesh generation:*
> Surface_3 surface(earth_function, // pointer to function
> Sphere_3(CGAL::ORIGIN, 7000*7000));
> // bounding sphere
> // Note that "2." above is the *squared* radius of the bounding
> sphere!
> // defining meshing criteria
> CGAL::Surface_mesh_default_criteria_3 criteria(30., // angular
> bound
> 500, // radius bound
> 50); // distance bound
> // meshing surface
> CGAL::make_surface_mesh(c2t3, surface, criteria ,
> CGAL::Manifold_tag());
>
> *My codes for mesh plotting: *
> glNewList(EARTH_S, GL_COMPILE);
>
> Point_3 pt0, pt1, pt2, pt3;
> for (auto it = c2t3.facets_begin(); it != c2t3.facets_end(); it++) {
>
> pt0 = it->first->vertex((it->second) & 3)->point();
> pt1 = it->first->vertex((it->second + 1) & 3)->point();
> pt2 = it->first->vertex((it->second + 2) & 3)->point();
> pt3 = it->first->vertex((it->second + 3) & 3)->point();
>
> auto vv = pt1 - pt0;
> auto n = CGAL::normal(pt1, pt2, pt3);
> if (CGAL::angle(n, vv) == CGAL::ACUTE) { n = -n; }
> //auto n = ((it->second % 2 ) == 1)?CGAL::normal(pt1, pt2,
> pt3): CGAL::normal(pt1, pt3, pt2);
>
> glBegin(GL_TRIANGLES);
> glColor3f(0.4, 0.5, 0.3);
> glNormal3f(n.x(), n.y(), n.z());
> glVertex3f(pt1.x(), pt1.y(), pt1.z());
> glVertex3f(pt2.x(), pt2.y(), pt2.z());
> glVertex3f(pt3.x(), pt3.y(), pt3.z());
> glEnd();
> }
>
> glEndList();
>
> *Resulting plot: *
> <http://cgal-discuss.949826.n4.nabble.com/file/n4662670/Capture.jpg>
>
>
>
> --
> View this message in context:
> http://cgal-discuss.949826.n4.nabble.com/CGAL-OpenGL-incorrectly-render-mesh-triangles-tp4662670.html
> Sent from the cgal-discuss mailing list archive at Nabble.com.
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
>
>



Archive powered by MHonArc 2.6.18.

Top of Page