我正在尝试使用GLUtesselator在OpenGL中生成3D拉伸文本。以下是相关代码:
private boolean createText(final String displayText)
{
final Font font = new Font("Times New Roman", Font.TRUETYPE_FONT, 3);
final float depth = 1000f;
final float flatness = 0.0001f;
final GlyphVector glyphVector = font.createGlyphVector(
new FontRenderContext(new AffineTransform(), true, true), new StringCharacterIterator(displayText));
final GeneralPath generalPath = (GeneralPath) glyphVector.getOutline();
final PathIterator pathIterator = generalPath.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0),
flatness);
tesselateFace(pathIterator, false, 0.0f);
return false;
}
private void tesselateFace(final PathIterator pathIterator, final boolean justBoundary, final double tessZ)
{
final GLUtessellatorCallback callback = new TessellatorCallback();
final GLUtessellator tessellator = glu.gluNewTess();
glu.gluTessCallback(tessellator, GLU.GLU_TESS_BEGIN, callback);
glu.gluTessCallback(tessellator, GLU.GLU_TESS_END, callback);
glu.gluTessCallback(tessellator, GLU.GLU_TESS_ERROR, callback);
glu.gluTessCallback(tessellator, GLU.GLU_TESS_VERTEX, callback);
glu.gluTessCallback(tessellator, GLU.GLU_TESS_COMBINE, callback);
if (pathIterator.getWindingRule() == PathIterator.WIND_EVEN_ODD)
glu.gluTessProperty(tessellator, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
else
glu.gluTessProperty(tessellator, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
if (justBoundary)
glu.gluTessProperty(tessellator, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_TRUE);
else
glu.gluTessProperty(tessellator, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_FALSE);
glu.gluTessProperty(tessellator, GLU.GLU_TESS_EDGE_FLAG, GL.GL_TRUE);
glu.gluTessBeginPolygon(tessellator, (double[]) null);
while (!pathIterator.isDone())
{
final double[] coords = new double[3];
coords[2] = tessZ;
switch (pathIterator.currentSegment(coords))
{
case PathIterator.SEG_MOVETO:
glu.gluTessBeginContour(tessellator);
break;
case PathIterator.SEG_LINETO:
glu.gluTessVertex(tessellator, coords, 0, coords);
break;
case PathIterator.SEG_CLOSE:
glu.gluTessEndContour(tessellator);
break;
}
pathIterator.next();
}
glu.gluTessEndPolygon(tessellator);
glu.gluDeleteTess(tessellator);
}
如果我相信第11章中的RedBook,
...如果存在与启用边缘标志的GLU_TESS_EDGE_FLAG关联的回调,则仅使用GL_TRIANGLES调用GLU_TESS_BEGIN回调。
那么我认为我应该只使用
GL_TRIANGLES
进行绘图。但是,我可以看到在我的自定义镶嵌细分回调中调用的类型可以是
GL_TRIANGLE_FAN
,GL_TRIANGLE_STRIP
或GL_TRIANGLES
中的任何一种。我只问是否有一种方法可以强制执行此操作,因为我太忙于创建一个可以处理GL_QUADS
或GL_TRIANGLES
以外的其他任何事情的VBO。 最佳答案
我敢肯定,如果您只提供了边缘回调(即使您什么都不做),也只会得到三角形。
我过去肯定有同样的问题,并找到以下代码和注释:
// providing this callback should stop triangle fans / strips coming back
if not fBoundaryOnly then
gluTessCallback(tess, GLU_TESS_EDGE_FLAG_DATA, @tessEdgeData);
Nb,这是Delphi代码,但仍然有意义。 @tessEdgeData是指向不执行任何操作的回调例程的指针。