JBeighel's picture

GraphicsModeException when creating GLControl

When I attempt to create the GLControl I get the following exception:

OpenTK.Graphics.GraphicsModeException: Invalid or unsupported GraphicsMode.
  at OpenTK.X11GLControl..ctor (OpenTK.Graphics.GraphicsMode mode, System.Windows.Forms.Control control) [0x00000] in <filename unknown>:0 
  at OpenTK.GLControlFactory.CreateGLControl (OpenTK.Graphics.GraphicsMode mode, System.Windows.Forms.Control control) [0x00000] in <filename unknown>:0 
  at OpenTK.GLControl.OnHandleCreated (System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.UserControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] in <filename unknown>:0

The line causing it is "cglGLView = new GLControl();" in the constructor for my windows forms class.

public GLForm() {
			//Initialize Log label
			clblLog = new Label();
 
			clblLog.Top = 485;
			clblLog.Left = 0;
			clblLog.Width = 800;
			clblLog.Height = 125;
			clblLog.Text = "";
 
			Controls.Add(clblLog);
 
			cbGLReady = false;
 
			cglGLView = new GLControl();
 
			//Position and configure the controls
			cglGLView.Top = 0;
			cglGLView.Left = 0;
			cglGLView.Width = 640;
			cglGLView.Height = 480;
 
			//Define callbacks for the controls
			cglGLView.Load += new EventHandler(GLViewLoading);  
			cglGLView.Paint += new PaintEventHandler(GLViewPainting); 
			Controls.Add(cglGLView);
 
			//Position and configure the form
			this.Width = 775;
			this.Height = 670;
			this.FormBorderStyle = FormBorderStyle.FixedSingle;
 
			return;
		}

I'm running Ubuntu 13.10, with Mono 2.10. The graphics card is a NVidia Quadro FX 370M, however I'm using the Nouveau driver. I do have Mesa 9 installed which I thought would be enough to let this run.

Is there some other package I'm missing to get this running, or will I need to switch to the NVidia drivers for my card to get any sort of OpenGL to work?

Thanks for any help.


Comments

Comment viewing options

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

"OpenTK.Graphics.GraphicsModeException: Invalid or unsupported GraphicsMode."

It appears that Nouveau does not support the default GraphicsMode in OpenTK, which is (color: 32, depth: 24, stencil: 8, antialiasing: 0) in OpenTK 1.1 and (color: 32, depth: 16, stencil: 0, antialiasing: 0) in 1.0.

Run "glxinfo" in a terminal to get a list of supported GraphicsModes and set one of those explicitly in the GLControl constructor. Unfortunately, there's doesn't appear to be one unified mode that is supported across all hardware and operating systems.

JBeighel's picture

I tried that but I'm getting the same result.

According to the man page glxinfo -b will give me the best visual, running that it tells me 33. I can't find any mode in the list with an ID of 33, I'm not sure what that means.

So I picked another one from the list with this command:
glxinfo -v | grep "ID: 22" -A7
This gives me the following mode:
Visual ID: 22 depth=24 class=DirectColor, type=window,pixmap,pbuffer
bufferSize=32 level=0 renderType=rgba doubleBuffer=1 stereo=0
rgba: redSize=8 greenSize=8 blueSize=8 alphaSize=8 float=N sRGB=N
auxBuffers=0 depthSize=24 stencilSize=8
accum: redSize=0 greenSize=0 blueSize=0 alphaSize=0
multiSample=0 multiSampleBuffers=0
visualCaveat=None
Opaque.

Here's the code I tried to use that in the GLControl constructor:
GraphicsMode oGMode;
ColorFormat oCFormat, oCAccum;

oCFormat = new ColorFormat(8, 8, 8, 8);
oCAccum = new ColorFormat(0, 0, 0, 0);
oGMode = new GraphicsMode(oCFormat, 24, 8, 0, oCAccum, 2, false);
cglGLView = new GLControl(oGMode);

I tried a few other modes from the list glxinfo provided, but all end with the same exception being thrown. Am I doing something wrong in translating the mode from what glxinfo is telling me to the GraphicsMode object?

the Fiddler's picture

Your code looks ok. It might be worth trying a ColorFormat without an alpha channel, i.e. (8, 8, 8, 0).

As a sanity test, does "glxgears" work?

I have a system running Nouveau on Mesa 9.x, I will try to see if I can reproduce the issue over the weekend. (Last time I tried, OpenTK was working fine there.)

JBeighel's picture

glxgears does work. I had hoped the -info switch might reveal the display mode it uses, but no such luck. It does say that it's using OpenGL 3.0 with Mesa 9.2.1 on the Nouveau driver for what that might be worth. Which reminds me, I never mentioned that I had the 1.1 beta 2 build of OpenTK dated 2013-12-05.

Also as an aside all of the code I had written, even with the various display mode settings, works perfectly on Windows. I suppose it's some comfort that my code is good.

I'll try some more display setting combinations later on and hope to get lucky.

the Fiddler's picture

Can you please try with github master from https://github.com/opentk/opentk? There is a fix specifically for Linux and there is a good chance it will work.

JBeighel's picture

Guess I should have brought up the OpenTK version first. I'll build from github soon as I have time, probably tonight some time. I also grabbed the 1.0 version of OpenTK and the GL control loaded just fine with default values.

I'll let you know how the build from github goes soon as I can.

JBeighel's picture

I pulled down the version from github and compiled it on the command line using xbuild. It reported 2032 warnings, but no errors in case that means anything.

Running it with the default graphics mode, as well as picked options from what glxinfo lists, results in the "OpenTK.Graphics.GraphicsModeException: Invalid or unsupported GraphicsMode." exception being thrown when the GLControl is created.

JBeighel's picture

I pulled down the version from github and compiled it on the command line using xbuild. It reported 2032 warnings, but no errors in case that means anything.

Running it with the default graphics mode, as well as picked options from what glxinfo lists, results in the "OpenTK.Graphics.GraphicsModeException: Invalid or unsupported GraphicsMode." exception being thrown when the GLControl is created.

the Fiddler's picture

Thanks for testing, can you please post the debug log from the output window of MonoDevelop? This should give us an idea of what is going wrong.

Most warnings come from the generated bindings (mismatches in the doc string parameters, dubious CLSCompliant warnings). I'm gradually fixing them, but they are safe to ignore for now.

the Fiddler's picture

Ok, I managed to reproduce the issue. Filed under https://github.com/opentk/opentk/issues/17, investigating.