Some problems encountered when using tessellator in OSG

Source: Internet
Author: User

Previously, when polygon is used to draw a polygon, the following problems may occur when the point to be added is not clockwise or counterclockwise!

You can use tessellator to solve the problem, but it has never been effective! It took a long time to find out that it was originally a problem with vertex array settings!

If the vertex is set to OSG: vec3darray tessellator, it does not work! It is valid only when OSG: vec3array is set!

Why? I am not very clear now?

The implementation code is as follows:

OSG: geometry * userselector: createpolygon () {OSG: geometry * Geom = new OSG: geometry; OSG: stateset * stateset = new OSG: stateset; // enable Alpha hybrid stateset-> setmode (gl_blend, OSG: stateattribute: On); stateset-> setmode (gl_depth_test, OSG: stateattribute: Off ); stateset-> setmode (gl_lighting, OSG: stateattribute: Off | OSG: stateattribute: protected); // set the rendering priority stateset-> setrenderbindetails (101, "renderbin"); OSG: cullface * cf = new OSG: cullface; stateset-> setattributeandmodes (CF, OSG: stateattribute: Off ); geom-> setstateset (stateset); OSG: vec3array * vertexs = new OSG: vec3array; Geom-> setvertexarray (vertexs); OSG: vec4array * Colors = new OSG :: vec4array; OSG: vec4 color (0.5, 1,); Geom-> setcolorarray (colors); Geom-> setcolorbinding (OSG: geometry: bind_per_primitive_set ); colors-> push_back (color); OSG: ref_ptr <OSG: vec3array> normals = new OSG: vec3array; Geom-> setnormalarray (normals. get (); Geom-> setnormalbinding (OSG: geometry: bind_per_primitive_set); OSG: vec3 normal = OSG: z_axis; Normals-> push_back (normal ); // custom excavation vertexs-> insert (vertexs-> end (), m_vecpts.begin (), m_vecpts.end (); Geom-> addprimitiveset (New OSG: drawarrays (OSG :: drawarrays: polygon, 0, vertexs-> size (); // triangular, concave polygon OSG: ref_ptr <osgutil: tessellator> tes = new osgutil :: tessellator (); tes-> setboundaryonly (false); tes-> setwindingtype (osgutil: tessellator: container); tes-> settessellationtype (osgutil: tessellator: container ); tes-> retessellatepolygons (* Geom); Return Geom ;}

Effect:


If the color is set to OSG: vec4darray
Results will also appear! It is normal only when OSG: vec3array is set! The reason seems to be that the default vec3array of OSG is float in cmake during compilation!


The following code shows the image under the terrain.

OSG: geometry * statisticsselector: createregion () {OSG: geometry * Geom = new OSG: geometry; OSG: stateset * stateset = new OSG: stateset; // enable stateset-> setmode (gl_blend, OSG: stateattribute: On); stateset-> setmode (gl_depth_test, OSG: stateattribute: On); OSG :: cullface * cf = new OSG: cullface; stateset-> setattributeandmodes (CF, OSG: stateattribute: Off); // make these points always draw at the top of OSG :: ref_ptr <OSG: Depth> depth = new OSG: depth; depth-> setfunction (OSG: depth: Always); depth-> setrange (0.0, 0.0 ); stateset-> setattributeandmodes (depth. get (), OSG: stateattribute: On); Geom-> setstateset (stateset); OSG: ref_ptr <OSG: vec3array> vertexs = new OSG: vec3array; geom-> setvertexarray (vertexs. get (); OSG: ref_ptr <OSG: vec4array> colors = new OSG: vec4array; OSG: vec4d color (1.0, 1.0, 1.0, 0.0 ); geom-> setcolorarray (colors. get (); Geom-> setcolorbinding (OSG: geometry: bind_per_primitive_set); colors-> push_back (color); OSG: ref_ptr <OSG :: vec3array> normals = new OSG: vec3array; Geom-> setnormalarray (normals. get (); Geom-> setnormalbinding (OSG: geometry: bind_per_primitive_set); OSG: vec3 normal = OSG: z_axis; Normals-> push_back (normal ); vertexs-> insert (vertexs-> end (), m_vecpts.begin (), m_vecpts.end (); Geom-> addprimitiveset (New OSG: drawarrays (OSG: drawarrays: polygon, 0, vertexs-> size (); // triangular, concave polygon OSG: ref_ptr <osgutil: tessellator> tes = new osgutil: tessellator (); tes-> setboundaryonly (false); tes-> setwindingtype (osgutil: tessellator: Counter); tes-> settessellationtype (osgutil: tessellator: tess_type_geometry ); tes-> retessellatepolygons (* Geom); Return Geom ;}

Effect!

If the color is set to OSG: vec4darray
Results will also appear! It is normal only when OSG: vec3array is set! The reason seems to be that the default vec3array of OSG is float in cmake during compilation!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.