我正在尝试使用 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 章中的红皮书,
...如果有一个与启用边缘标志的 GLU_TESS_EDGE_FLAG 关联的回调,则仅使用 GL_TRIANGLES 调用 GLU_TESS_BEGIN 回调。
那么我相信我应该只使用GL_TRIANGLES
.
但是,我可以看到在我的自定义 tessellator 回调中调用的类型可以是或中GL_TRIANGLE_FAN
的任何一个。我只问是否有办法强制执行此操作,因为我太忙于创建一个可以处理除or之外的任何其他内容的 VBO 。GL_TRIANGLE_STRIP
GL_TRIANGLES
GL_QUADS
GL_TRIANGLES