我正在尝试使用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。
答案 0 :(得分:2)
我确定你是否只是提供了边缘回调(即使你没有做任何事情),你只会得到三角形。 我必须在过去遇到过相同的问题并找到此代码和评论:
// 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是一个指向回调例程的指针,它不执行任何操作。
答案 1 :(得分:2)
如果有人在c ++中需要它,代码如下:
void CALLBACK edgeCallback(void){return;}
gluTessCallback(Tobj, GLU_TESS_EDGE_FLAG_DATA,reinterpret_cast<_GLUfuncptr>(edgeCallback));