Search code examples
c#c++opengl3dopentk

Glu-less example of drawing a cube?


I'm trying to get back into OpenGL, but my knowledge and math are rusty now. I used to use C++, but I prefer C# now... trying out OpenTK. Apparently Glu has been deprecated since GL 3.1, so I'm trying to find a Glu-less example of drawing a cube on the screen in either C# or C++ (I can translate it).

The part I'm finding challenging is setting up the viewport/viewing angle/camera/perspective/initializing stuff. I'm okay with clearing the buffer, and laying down points in 3D space, but the other stuff I forget!

In particular, I need replacements for Glu.Perpsective and Glu.LookAt.


Solution

  • I suggest taking a look at the http://openglbook.com/ It says it's OpenGL 4, but everything described here (only the basics so far) directly applies to OpenGL 3 too. I think this is the best resource to get quickly started with recent OpenGL versions. Other very good resource is the Learning Modern 3D Graphics Programming, which goes a tad more in-depth.

    You must note that the OpenGL 3 and newer disregards the fixed pipeline. You can still use the fixed pipeline using a compatibility profile, but IMO it's better to learn the programmable pipeline. That means no more immediate mode (eg. glVertex3f and similar) and display lists. You have to submit your vertex data directly into to the graphics card prior drawing. This is done using buffer objects, which is nothing but an array of vertex data. Then you have to submit a GLSL program which will process these data, such as applying modelview and projection matrices (even when you don't need fancy shader stuff).

    Last but not least the current OpenGL versions doesn't implement matrix operations and lighting (again unless using compatibility profile). You need to create all the matrices on your own, but since it's a tedious work I suggest using an external library.

    This all may sound frightening and frankly, I found it more difficult to learn the programmable pipeline than the fixed pipeline. However it gives you much more flexibility.