I’m playing with the example in Writing Code To Modify Scenes And Transformations. I 'm trying to create a scene from code using an old OpenGL 1.1 program I wrote time ago.
The problem is that I was using GL_TRIANGLES
while Castle Engine seems to use GL_TRIANGLE_STRIP
so when rendering the vertices seems in the correct places but the mesh is a mess (pun not intended) with all triangles overlapping. Am I right?
So is there a way to tell CGE to use GL_TRIANGLES
?
Later I’ll dig in the sources and see if it’s possible to write my very own TCastleScene
class. Maybe somebody can guide me in that travel…
Replace TIndexedFaceSetNode
(which is basically the equivalent of GL_QUADS
) in the example with either TTriangleSetNode or TIndexedTriangleSetNode should work. Both use GL_TRIANGLES
underneath.
3 Likes
Thankyou kagamma. It works. 
I’ll look for more “SetNode” classes. I didn’t realize that it should be more.
Adding to @kagamma answer:
-
While I also recommend to use TTriangleSetNode
or TIndexedTriangleSetNode
if you have only triangles, as it will be most straightforward…
-
…note that TIndexedFaceSetNode
shown in Writing code to modify scenes and transformations | Manual | Castle Game Engine is also possible to use. TIndexedFaceSetNode
renders a set of polygons, each polygon separated by -1 in the indexes. Polygons can be triangles, quads, or larger n-gons. They can be convex or concave (when TIndexedFaceSet.Convex = true
, they must be convex; when it’s = false, they can be any kind). The example shows TIndexedFaceSetNode
exactly because it allows to cover so many cases 
I would not say that TIndexedFaceSetNode
is like GL_QUADS
or GL_TRIANGLE_STRIP
(which were mentioned in this thread), and it actually never does use these primitive types.
What it does:
- Determine the polygons, looking at -1 separators in the indexes.
- For each polygon, render it using a number of
GL_TRIANGLES
.
- If
Convex = true
, each polygon is triangulated in a simple fast way, a bit like “triangles fan” (but not actually using GL_TRIANGLES_FAN
, as it would prevent from having multiple fans in one draw call, unless one would do dirty tricks with degenerate polygons).
- If
Convex = false
, each polygon is triangulated using ear clipping algorithm.
E.g. modify IndexedFaceSet.SetCoordIndex
from Writing code to modify scenes and transformations | Manual | Castle Game Engine like this to have 3 triangles:
IndexedFaceSet.SetCoordIndex([
0, 1, 2, -1, // 1st triangle
3, 4, 5, -1, // 2nd triangle
6, 7, 8, -1, // 3rd triangle (note: ending -1 is allowed but optional, doesn't really matter)
]);
See docs, in this case X3D spec for IndexedFaceSet
node is helpful,
1 Like