
[Examples] Add forward-compatible OpenGL 3.0 example
Posted Sunday, 21 June, 2009 - 21:56 by the Fiddler| Project: | The Open Toolkit library |
| Version: | 0.9.9-1 |
| Component: | Documentation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
We should add a forward-compatible OpenGL 3.0 example to Examples.exe. This code should be of use.


Comments
#1
#2
Here goes a spinning cube example. Powered by OpenGL 3.0 forward compatible context!
The shaders are not ok (normals going wild:), and I don't know how to fix them yet. It has been too many new things for me so please be patient. This is my first experience with shaders as well. Tested against 0.9.8.1
Hopefully I'll get a GL3.1 + GLSL1.4 version of this up and running as soon as the drivers settle. Stay tuned.
Edit: I'm sure the winding is correct because it's the same cube from the other OpenTK examples. If anyone knows how to fix the shaders please post!
Edit2: It now occurred to me that I have to interpolate the normals through the primitive. Duh!
Edit3: Shaders separated into files now carry #version info. Minor code edits.
Edit4: Fixed
GL.UniformMatrix4parameters inconsistency.Edit5:
There's probably tons of google hits here. Until we have a proper GL3+ tutorial, I'll try to keep this page updated.
The code now follows its SVN counterpart more closely. Updated to OpenTK 0.9.9.0.
Using
Matrix4.Frustumfixed "normals" problem.Shaders back into code.
#3
Thanks!
GL3.0 has a steeper learning curve, since you have to use VBOs and shaders, but it is a lot cleaner in actual use. Reduced state management pays off: you no longer have to worry aboout the current matrix, or whether you forgot to enable/disable textures, lighting, etc. There's also something quite awesome in seeing your pixel shader produce the results you wanted (typically after a long fight with the equations).
#4
Setting up a GL3+ rendering environment wasn't *THAT* hard. Yes, it took me some crying and hair loss (empty black window symptoms:) but I can say I've seen worse. Also, pre-GL3 knowledge comes very handy, i.e. you still know what to do with matrices, vertices and all the rest. Which makes me curious about newcomers and their first steps into modern OpenGL.
Back to the matter, did you manage to get a 3.1 context, Fiddler?
#5
My Ati drivers don't seem to support 'pure' 3.1 at this point - specifying 3.1 gets me a 3.0 context plus extensions (exactly the same as specifying 3.0).
It seems that Nvidia's 190.xx drivers support 3.1, but I won't install leaked alpha-quality drivers just to test that rumour! :)
#6
GL.UniformMatrix4( ... , true/false, ... );
I think you should be more consistent with handling the matrices, either keep them all row- or all column-major. Ofcourse this is a convenient way to get the transpose modelview matrix for transforming the normal, but there's no // comment in your shader to keep track of this. You will not remember this hack next year without documenting it right now, and - as a side-bonus - documentation will also make sure you keep your hair 5 years longer! (at least.)
Problem: You are transforming the vertex position by a column-major projection matrix (it was transposed at GL.UniformMatrix4) and a row-major modelview matrix (no transpose).
Don't get this into the wrong throat, your work is very much appreciated. Thank you :)
#7
I think you should be more consistent with handling the matrices
I'm aware of the glitch and you're absolutely right. It's a leftover from a previous version of the example which was dependent on my own math module. Switching to OpenTK's I had to rewrite the equations because the two are not compatible.
Now the projection is transposed "at birth".
Nice shot Inertia, appreciate it.
PS: Even though I managed to write a scenegraph of sorts, I still find the sentences containing "OpenGL" and "matrix" stressful.
#8
Ok, I've committed the example with slight modifications. It is available here.
Modifications:
Matrix4and updated the example to use those.Frankly, I don't like the interface of the current math library. It's missing several important methods and it's not very intuitive. I'm slowly morphing it to follow the XNA API, which will provide several nice perks: extensive tutorials, easier ports, cleaner API.
I'll also try to see if it's possible to force the context to be constructed and current during the GameWindow constructor. This was not possible with the older architecture, but the GameWindow is more versatile in 0.9.9.
Once more, many thanks for the tutorial!
#9
Glad to hear it's been of use. Credits go also to manjian and his GLSL 1.30 example.
If I manage to fix the look of the cube I'll drop a line here. Won't happen for a week though. The exams are finally over and all I want to do is switch off somewhere in the wild.
#10
It seems that Nvidia's 190.xx drivers support 3.1, but I won't install leaked alpha-quality drivers just to test that rumour! :)
Nvidia finally released its OpenGL 3.1 capable drivers a couple of days ago. On this occasion I'll target GL 3.1 on the upcoming tutorial. The code is the same but I seriously dislike the name. "GL 3.0 forward context tutorial" is not cool(TM).
Objections?
PS: Will also mark the code here as deprecated.
Edit: I'll upgrade the shaders to version 1.4 so we can properly transform the normals with
inverse(mat4). Not available on 1.3.