Jablo's picture

Issues updating from to

Replacing the OpenTK dlls for my application from to, results in two issues.

1. issue (minor but ugly)

I get following warning for all functions needed for tesselation (eg. OpenTK.Graphics.Glu.TessNormal, OpenTK.Graphics.Glu.NextContour):
'OpenTK.Graphics.Glu' is obsolete: 'Use OpenTK math functions instead.'
But this functions only exists in namespace OpenTK.Graphics.Glu. Obsolete message can't be suppressed.

2. issue (wrong output)

There is also a warning 'OpenTK.Graphics.Glu' is obsolete: 'Use OpenTK math functions instead.' for function
but if I use function
instead, the values are not set and my application shows wrong graphic.

Have I misunderstood something ?
Any help appreciated.


Comment viewing options

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

Regarding GLU, this has been deprecated upstream, there's nothing we can really do about that (other than reimplemeting GLU methods in OpenTK.Math, help is always appreciated on this). You can disable deprecation warnings completely through your project properties (go to compile tab and enter the numerical value "0612" to the relevant field).

Matrix4.LookAt returns a matrix that you have to apply yourself. The math toolkit doesn't access OpenGL directly, it is completely independent as a module!

Matrix4d lookat = Matrix4.LookAt(...);
GL.MultMatrix(ref lookat);
Jablo's picture

Thanks so far,

will the GLU methods remain part of compatibility dll and will this dll be kept in current versions ?

the Fiddler's picture

Yes, OpenTK.Compatibility will be kept as is in future versions.

Jablo's picture

Thanks, this was important to know (because we have to use tesselation).

One question left, if I want to use orthogonal projection in the same way (create matrix and apply to current) as with perspective projection,
it does not work the way I thouth it must be correct.
//*#1# works as expected (old way), but //*#2# results in an empty screen

Does I miss the basics? Thanks for your help.

GL.MatrixMode( MatrixMode.Projection );
GL.Viewport( 0, 0, width, height );
double dAspRat = (double)width / (double)height;
if (boPerspective) {
	OpenTK.Matrix4d mProjection = OpenTK.Matrix4d.Perspective( OpenTK.MathHelper.PiOver4, dAspRat, 0.1, 20.0 );
	GL.MultMatrix( ref mProjection );
else {
	double dSize = dSizeScene / 2.0;
	GL.Ortho( -dSize * dAspRat, dSize * dAspRat, -dSize, dSize, 0.1, 20.0 );
	OpenTK.Matrix4d mProjection = OpenTK.Matrix4d.CreateOrthographic( dSizeScene * dAspRat, dSizeScene, 0.1, 20.0 );
	GL.MultMatrix( ref mProjection );
OpenTK.Matrix4d mLookAt = OpenTK.Matrix4d.LookAt(
	0.0, 0.0, 1.1, // eye
	0.0, 0.0, 0.0, // center
	0.0, 1.0, 0.0  // up
GL.MultMatrix( ref mLookAt );
the Fiddler's picture

Right now, there's no good alternative to GLU tesselation, which is the most useful part of GLU. I hope this can change at some future point (if you happen to learn of a free alternative, please say so!)

The equivalent method to GL.Ortho is called Matrix4d.CreateOrthographicOffCenter. It accepts the same parameters and should return the exact same matrix (if it doesn't, please file a bug):

OpenTK.Matrix4d mProjection = OpenTK.Matrix4d.CreateOrthographicOffCenter( -dSize * dAspRat, dSize * dAspRat, -dSize, dSize, 0.1, 20.0 );
GL.MultMatrix( ref mProjection );

CreateOrthographic is defined like this:

        public static Matrix4d CreateOrthographic(double width, double height, double zNear, double zFar)
            Matrix4d result;
            CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result);
            return result;

which explains why your scene appears empty: your original projection has twice the width and height of the projection you are creating with code>Matrix4d.CreateOrthographic.

Jablo's picture

The projection matrix is equal in both cases, if have checked it with GL.GetDouble( GetPName.ProjectionMatrix, out m );
There must be something else what GL.Ortho does additionally.
Any hints ?

the Fiddler's picture

GL.Ortho simply constructs an orthographic projection and multiplies the current matrix with it (reference). If the projection matrices are identical, then the problem lies elsewhere.

Are you resetting the matrix mode back to modelview afterwards? (Your code above does not, but I thought you just pasted the important parts, leaving the rest out).

Jablo's picture

The projection matrix is NOT equal in both cases. I have compared it inattentively !
The element M44 is different:
- GL.Ortho generated M44=1.0
- the combination of OpenTK.Matrix4d.CreateOrthographic and GL.MultMatrix generates M44=0.0

If I adjust M44 manually the graphic output is ok.
OpenTK.Matrix4d mProjection = OpenTK.Matrix4d.CreateOrthographic( dSizeScene * dAspRat, dSizeScene, 0.1, 20.0 );
mProjection.M44 = 1.0;
GL.MultMatrix( ref mProjection );

This must be the extra functionality which GL.Ortho does automatically ?

the Fiddler's picture

Or a bug, more likely. I distinctly recall this issue being fixed on a previous release, which makes me suspect something sinister having to do with merging feature branches back to trunk.

Can you please file a bug report?