OpenGL.Net icon indicating copy to clipboard operation
OpenGL.Net copied to clipboard

Setting System.Windows.Forms control context

Open katz1 opened this issue 5 years ago • 4 comments

Hi!

I am trying to create an OpenGL.GlControl in a WPF window with a 3.3 core OpenGL context, using OpenGL.NET 0.7.1 from NuGet. The wiki here suggests to use the ContextVersion property of the control.

If I try to enter anything to the ContextVersion property via the Properties tab of MSVC 2015, my xaml will be turned to something like this:

<WindowsFormsHost Grid.Column="0" Margin="20">
	<opengl:GlControl ContextCreated="GlControl_ContextCreated" Render="GlControl_Render" >
		<opengl:GlControl.ContextVersion>
			<Khronos:KhronosVersion VersionId="0"/>
		</opengl:GlControl.ContextVersion>
	</opengl:GlControl>
</WindowsFormsHost>

Which gives a compile error: error MC3065: 'VersionId' property is read-only and cannot be set from markup.

I also tried adding the ContextVersion manually to the xaml like this:

<WindowsFormsHost Grid.Column="0" Margin="20">
	<opengl:GlControl ContextCreated="GlControl_ContextCreated" Render="GlControl_Render" ContextVersion="3.3" />
</WindowsFormsHost>

This does compile, but I don't think I end up with a core context, because I can still draw the example triangle with the fixed function pipeline in the GlControl_Render event handler. The control's ContextProfile property is on the default Core.

Here are a few things I log from the GlControl_ContextCreated event handler:

Gl.CurrentRenderer: GeForce GT 630/PCIe/SSE2 Gl.CurrentVersion: Version=4.6 API=gl Gl.CurrentShadingVersion: Version=4.60 API=glsl DeviceContext.CurrentAPI: gl DeviceContext.Version: Version=1.0 API=wgl DeviceContext.IsPixelFormatSet: True

katz1 avatar Oct 16 '18 13:10 katz1

The control's ContextProfile property is on the default Core.

The default value for ContextProfile is Compatibility (source reference)

I think changing it to Core will solve the issue you're facing.

luca-piccioni avatar Oct 16 '18 18:10 luca-piccioni

Thanks for the quick response. My properties tab does claim that Core is the default, it looks like this:

openglnet-properties

I did try setting the ContextProfile manually like this:

<WindowsFormsHost Grid.Column="0" Margin="20">
	<opengl:GlControl ContextCreated="GlControl_ContextCreated" Render="GlControl_Render" ContextProfile="Core" ContextVersion="3.3" />
</WindowsFormsHost>

But the same thing happens, I can use the functions from the triangle example which should not be available in a 3.3 core context.

By the way I installed the following packages in NuGet: OpenGL.Net OpenGL.Net.CoreProfile OpenGL.Net.WinForms

katz1 avatar Oct 17 '18 07:10 katz1

I also tried making the control from code behind instead of xaml, but I experience the same issue:

var conv = new Khronos.KhronosVersionConverter();
var version = (Khronos.KhronosVersion)conv.ConvertFromString("3.3");
var glControl = new GlControl { ContextProfile = GlControl.ProfileType.Core, ContextVersion = version };

katz1 avatar Oct 17 '18 07:10 katz1

That Debug and Robust properties set to Required smell... They are different from the default values, and could make fail context creation due missing extensions.

luca-piccioni avatar Dec 18 '18 22:12 luca-piccioni