Hi, I'm trying to use the gluTesselator in CsGL but I'm somewhat confused
how to use it.
I am using the following code to tessellate (in my case a font glyph)
protected void GenerateText()
{
CsGL.OpenGL.GLUtesselator tess = GL.gluNewTess();
GL.gluTessCallback(tess, GL.GLU_TESS_BEGIN, new
GLUtessBeginProc(OnTessBegin));
GL.gluTessCallback(tess, GL.GLU_TESS_VERTEX, new
GLUtessVertexProc(OnTessVertex));
GL.gluTessCallback(tess, GL.GLU_TESS_END, new
GLUtessEndProc(OnTessEnd));
GL.gluBeginPolygon(tess);
GL.gluTessBeginContour(tess);
foreach (CFreeTypeGlyph glyph in glyphs)
{
double ratio = Math.Max(glyph.maxX, glyph.maxY);
for (int i=0; i<glyph.numPoints; i++)
{
int ix = glyph.points[i * 2];
int iy = glyph.points[(i * 2) + 1];
byte tag = glyph.tags[i];
double x = ix / ratio;
double y = iy / ratio;
double[] xy = { x, y };
GL.gluTessVertex(tess, xy, (IntPtr) 0);
}
}
GL.gluTessEndContour(tess);
GL.gluEndPolygon(tess);
GL.gluDeleteTess(tess);
}
Where my callbacks look like this...
public void OnTessBegin(uint type)
{
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
GL.glBegin(GL.GL_POLYGON);
GL.glEnable(GL.GL_TEXTURE_2D); // this one is added
GL.glNormal3d(0, 0, 1);
GL.glColor4d(1.0,1.0,1.0,1);
}
public void OnTessVertex(IntPtr data)
{
// PROBLEM - DATA IS NULL!!!!!!
// THIS CODE WILL THROW
double[] vertex = new double[3];
System.Runtime.InteropServices.Marshal.Copy(data, vertex, 0, 3);
GL.glTexCoord2d(vertex[0], vertex[1]);
GL.glVertex2d(vertex[0], vertex[1]);
}
protected void OnTessEnd()
{
GL.glEnd();
}
When the tesselator calls my OnTessVertex function though the "data" param
is null. I guess I'm just using the whole thing wrong but I don't know if
it's my lack of understanding of OpenGL or lack of understanding of C# or
maybe both (which I would not be surprised).
Any thoughts on what is wrong with my code please?
Thanks,
-chris
PS. CsGL Rocks!
|