我正在尝试使用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。
PathIterator.SEG_MOVETO
情况下,你没有调用GLU.gluTessVertex(tessellator, coords, 0, coords)
。 - Vincent Cantin