pixartist's picture

GLU / GLUT ?

How can I use these libraries in openTK ?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

GLU has been deprecated by the ARB (it doesn't work with GL3+) and much of GLUT functionality already exists in OpenTK. What kind of functionality are you looking for? There may be better alternatives than GLU/GLUT.

While OpenTK does not support these libraries directly, you can find a GLU binding in OpenTK.Compatibility and GLUT binding in the Tao framework. Both should generally work, but neither is actively supported.

pixartist's picture

Well, how can I generate simple objects like cubes, spheres, etc. in opentk? There has to be a library for that....

the Fiddler's picture

There is example code for drawing geometric shapes in these forums (search for e.g. sphere). Simple geometric shapes tend to be quite simple to generate in code, to the point where setting up and using GLUT is not worth the effort. For instance, you can generate a sphere with this snippet:

List<Vector3> CreateSphere(float radius, int rings, int segments)
{
    var sphere = new List<Vector3>();
    for (double y = 0; y < rings; y++)
    {
        for (double x = 0; x < segments; x++)
        {
            double phi = (y / (rings - 1)) * Math.PI;
            double theta = (x / (segments - 1)) * 2 * Math.PI;
            sphere.Add(new Vector3
            {
                X = (float)(radius * Math.Sin(phi) * Math.Cos(theta)),
                Y = (float)(radius * Math.Cos(phi)),
                Z = (float)(radius * Math.Sin(phi) * Math.Sin(theta)),
            });
        }
    }
    return sphere;
}

GLUT abstracts this away but I generally don't find this abstraction to be worth the cost (carrying around a native dependency). Tao.FreeGlut works well with OpenTK if you find are searching for a ready-to-use solution and find the trade-off acceptable.

(Note that OpenTK is a low-level OpenGL binding, not a high-level 3d renderer. It allows you to access OpenGL from .Net in a sane manner and that's it, more or less. This is both a strength and a weakness).