alanb's picture

Problem with GLWidget in other controls

Hi,
I asked about this a while ago but no replies, then I was using opensuse 11.3. I just tried again on a fresh install of ubuntu 10.04 and monodevelop 2.4 from badgerports. Again problem persists. I compile and run example GLWidgetTest + added code to change window background. Then cut widget add a vbox and paste glwidget in centre pane and still runs ok. Now place label (or anything) in vbox top pane and program crashes with report attached below. When I remove the label runs ok again!!! Same problem if label in pane following glwidget in hbox.

So can anyone help me and suggest where to start looking or what to alter? I have been holding off doing the 3D bit of my code for a while now but am getting to the point where I really need to use opengl on a GTK mono project and I would like to use opentk anf glWidget embedded in another control if at all possible. Has anyone else experienced this problem?

Code to change color is

protected virtual void OnGlwidget1RenderFrame (object sender, System.EventArgs e)
 
{
 
		int width = 0, height = 0;
		glwidget1.GdkWindow.GetSize(out width, out height);	
		GL.Viewport(0, 0, width, height);
		GL.ClearColor(1.0f,0.5f,0.5f,1.0f);
		GL.Clear(ClearBufferMask.ColorBufferBit);
 
}

Thanks

Alan

Inline Images
AttachmentSize
stacktrace.txt6.17 KB

Comments

Comment viewing options

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

I suggest you send the source code (solution and project) as a compressed file so we can all see the problem you describe.

Regards, ...

the Fiddler's picture

A test case would really help here.

One suggestion: try adding a call to OpenTK.Toolkit.Init() as the first thing in your Main() method. This will try to initialize X in thread mode, which seems to increase stability.

alanb's picture

Ok,
The project is really just the one taken from JTaltons site on sourceforge but have attached after cleaning it. On my system it compiles and runs ok as is, but fails when a label is added to vbox before or after widget. My references to OpenTk are to opentk-1.0.0-rc1/Binaries/OpenTK/Debug/OpenTK.dll. I downloaded the release candidate and it seemed to build ok in Monodevelop 2.4 with 0 errors and 123 warnings see attached file? Cannot attach my resultant dll for you to test as its too big.

Alan

AttachmentSize
GLWidget.tar_.gz14.93 KB
warnings.txt65.79 KB
alanb's picture

Forgot to add,
I can run the supplied examples from within monodevelop see output for simple window below. So I assumed OpenTK.dll was build correctly. Dont know what the vsync failure is.

Alan

Launching sample: "Simple Window"

Size: 2304
System:
Linux

Initializing threaded X11: 1.
Display connection: 172280584, Screen count: 1
Detected configuration: Linux / Mono
Initializing threaded X: success.
Creating default GraphicsMode (24, 16, 0, 0, 0, 2, False).
Creating X11GLNative window.
Display: 172512016, Screen 0, Root window: 272
Registering atoms.
Bits per pixel: 24
Depth: 16
Display: 172280584, Screen: 0, RootWindow: 272
Getting FB config.
Opening render window... Initalizing X11 input driver.
First keycode: 8, last 255
6 keysyms per keycode.
X11GLNative window created successfully (id: 65011714).
Creating GraphicsContext.
GraphicsMode: Index: 210, Color: 24 (8880), Depth: 24, Stencil: 0, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: X11.WindowInfo: Display 172512016, Screen 0, Handle 65011714, Parent: (null)
GraphicsContextFlags: Default
Requested version: 1.0
Creating X11GLContext context: direct, not shared...
Creating temporary context to load GLX extensions.
Loading extensions for OpenTK.Platform.X11.Glx... 1 extensions loaded in 3.1392 ms.
Using legacy context creation... Context created (id: 166285632).
Making context 166285632 current on thread 2 (Display: 172512016, Screen: 0, Window: 65011714)... done!
Loading extensions for OpenTK.Platform.X11.Glx... 1 extensions loaded in 0.0249 ms.
Context supports vsync: True.
Loading extensions for OpenTK.Graphics.OpenGL.GL... 1900 extensions loaded in 237.2512 ms.
VSync = True failed, error code: BAD_CONTEXT.
Entering main loop.

the Fiddler's picture

Thanks, I'll try to find out what is going on here.

alanb's picture

Hi again,

Just downloaded opentk release and compiled and ran examples. Seemed to work ok but gave some error messages for example running Gamewindow simple gave

VSync = True failed, error code: BAD_CONTEXT.
Entering main loop.

but did display. So again tried GLWidget with new opentk libraries but still get problem described above. Is this a fault on my system, or with mono or with opentk??
I really would like to get going with GLWidget but cant. If someone could point me in the right direction I could try to solve it myself.

Thanks

Alan

the Fiddler's picture

Sorry, I all but forgot about this issue. I do not have first-hand experience with GLWidget, but I think you are missing a call to SwapBuffers(). Try adding this line after GL.Clear():

GraphicsContext.CurrentContext.SwapBuffers();

Also make sure your OnGlwidget2RenderFrame method is actually called at runtime (add a breakpoint or print a message to the console just to make sure).

If it still doesn't work, please file a bug report and I'll see what I can do.

gooberking's picture
the Fiddler wrote:

A test case would really help here.

One suggestion: try adding a call to OpenTK.Toolkit.Init() as the first thing in your Main() method. This will try to initialize X in thread mode, which seems to increase stability.

I know this thread is a wee bit old, but I wanted to make mention that this suggestion solved the similar issue I was having using the GLwidget under Linux. It would work, but only if there were no GTK controls, otherwise it would crash. Adding the Toolkit.Init() line fixed it right up.

as an FYI I also had to set the color BPP field to get the Widget to work.