_hawk_'s picture

Error handling & Remote Desktop

Hi,

first of all thank you for this nice project.

I have a .NET program which uses xna to draw some simple 3D graphics.
I would like to replace this for 2 reasons:

Get rid of xna dependencies (and installation trouble) and be able to use it with remote desktop and older PCs.

So I made some tests with OpenTK and ran into some problems.
Here a very simple example:

namespace OpenTKTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenTK.Graphics.ColorFormat color = new OpenTK.Graphics.ColorFormat(32);
                OpenTK.Graphics.ColorFormat accum = new OpenTK.Graphics.ColorFormat(0);
                OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(color, 32, 8, 0, accum);
                OpenTK.GLControl control = new OpenTK.GLControl(mode, 1, 1, OpenTK.Graphics.GraphicsContextFlags.Debug);
                this.Controls.Add(control);
            }
            catch (Exception)
            {
            }
        }
    }
}

This runs without any errors on my Windows 7 Laptop.
I also had an example which draws a triangle (like the example in the docs).

If I start this on my Windows 2012 R2 Server (via Remote Desktop) I get an exeption: The requested GraphicsMode is not supported

I started the OpenGL Extension Viewer which says that OpenGL 1.1 is supported and the included sample (rotating head) runs fine.

So my question is: how can I switch to OpenGL 1.1?

The second question is: how to deal with errors?
In this simple example there is a try catch around the gl stuff but still my complete program chrashes after the error.

I was using OpenTK 1.1 beta 4


Comments

Comment viewing options

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

I fixed the Remote Desktop error just a few hours ago: [Win] Fix issue #35 (OpenTK over Remote Desktop) :) Download the code from https://github.com/opentk/opentk and build OpenTK.sln to test.

Are you calling any OpenGL functions after the error (e.g. in a Paint event?) In that case, the crash is to be expected.

Please post the contents of the "Application Output" window in Visual Studio (press "ctrl-w-o" to open.)

_hawk_'s picture

Thank you :)
I compiled the latest version as release and my triangle example works now.

Will have to take a look on how to use the debug libs..

In my simple example there where no further calls to any GL functions.
So how would I just display an empty control if there was any error (maybe a corrupt or missing gl installation) instead of crashing the whole program?

the Fiddler's picture

If you add the control through the designer, and the control crashes during initialization, Windows.Forms will display an empty control with a red X instead. In that case, you just need to ensure that you are not calling any OpenGL functions, as those will crash (this is easy to do if you restrict your OpenGL code to GLControl events like GLControl.Paint.)

If you wish to avoid the designer, you can do the same thing manually using the code you posted: add a custom non-OpenGL Control with a suitable message when GLControl fails to construct.