Giter Club home page Giter Club logo

glwpfcontrol's Introduction

OpenTK

OpenTK is a large project. There are many components to work on, and we'd welcome almost any contribution. The community is friendly, welcoming and always ready to help you get your PRs merged!

We have a very active discord server, if you need help, want to help, or are just curious, come join us!

Discord

The Open Toolkit library is a fast, low-level C# binding for OpenGL, OpenGL ES, OpenAL, and OpenCL. It runs on all major platforms and powers hundreds of apps, games and scientific research.

Use OpenTK to add cross-platform 3d graphics, audio, compute and haptics to your C# application. Integrate it into your existing user interface or use it standalone without any external dependencies.

OpenTK comes with simple and easy to follow tutorials for learning modern OpenGL. These are written by the community and represent all of the best practices to get you started.

Learn how to use OpenTK here: https://opentk.net/learn/index.html

A separate github repo with code is available here: https://github.com/opentk/LearnOpenTK The code is similar to the tutorial but not an exact replica.

Project website: https://opentk.net

Official git repository: https://github.com/opentk/opentk

Build Status

Platform Status
Windows Build status
Mono/Linux Build status

Features

  • Create cutting-edge graphics with OpenGL 4.6 and OpenGL ES 3.0
  • Spice up your GUI with 3d acceleration
  • Improve your code flow with strong types and inline documentation
  • Windowing systems to help get you started
  • Input, and other game essentials.
  • Performant, highly optimized and reliable linear algebra library
  • Write once run everywhere

OpenTK is available for Windows, Linux, Mac OS X, *BSD and SteamOS. It can be used standalone or integrated into a GUI (Windows.Forms, WPF, GTK+, Qt, VTK, ...)

An old, unsupported version of OpenTK 1.0 may be included in the Xamarin Android and iOS distribution. The Xamarin fork is not supported or maintained by this project.

Adding support for mobile again is a future goal of the OpenTK project, but is somewhat frustrated by Apple's deprecation of OpenGL. Contributions to re-add support for these platforms are welcomed.

Instructions

OpenTK is available as a NuGet Package.

As of OpenTK 4.8 "Visual C++ Redistributable 2015" is not longer required to run OpenTK 4 on windows. For earlier versions of OpenTK 4 you can install any version of OpenTK.redist.glfw >= 3.3.8.35 to remove the "Visual C++ Redistributable 2015" requirement. See https://github.com/opentk/glfw-redist for more details.

News

2022-09-24

OpenTK 5.0.0 is still under active development and usage.

Preview releases are running non-trivial applications successfully on .Net 6 across all platforms.

Please drop by the discord for the latest updates!

2020-10-02

OpenTK 4.0.0 is released with full availability.

Key changes:

  • Full support for .Net Core 3.1
  • Brand new GLFW-based windowing system
  • Brand new GLFW-based input system
  • Removed all platform-specific backends (and fixed every xplat bug!)
  • Math library performance improvements and fixes
  • All new OpenAL bindings
  • All new OpenCL Bindings
  • Total restructure of all packages into a modular system with a number of packages. The OpenTK Nuget package is now a metapackage that will automatically download all of these for you.

OpenTK 4.0.0 is entirely MIT licensed.

We're excited to see what you can build with this!

https://www.nuget.org/packages/OpenTK

2020-04-06

Oops! Forgot to update the news! OpenTK 4.0.0 PREVIEW is now available on Nuget.

https://www.nuget.org/packages/OpenTK

2020-04-06

OpenTK 3.2.0 is available.

This adds bindings for the wgl_dx_interop extension and support for joysticks with > 64 buttons.

https://www.nuget.org/packages/OpenTK/3.2.0

2019-08-04

OpenTK 3.1.0 is available.

https://www.nuget.org/packages/OpenTK/3.1.0

https://www.nuget.org/packages/OpenTK.GLControl/3.1.0

2018-10-19

Work is well underway on OpenTK 4.0, which targets .netstandard 2.0.

We would welcome any contributions!

Click here to view the tracking issue.

2018-06-07

OpenTK 3.0.1 is available.

https://www.nuget.org/packages/OpenTK/3.0.1

https://www.nuget.org/packages/OpenTK.GLControl/3.0.1

2018-01-05

OpenTK 3.0.0 is available.

https://www.nuget.org/packages/OpenTK/3.0.0

https://www.nuget.org/packages/OpenTK.GLControl/3.0.0

Building from source

To build OpenTK from source you just need to clone the git repo and open OpenTK.sln in Visual Studio 2019 or later.

git clone https://github.com/opentk/opentk   # Download source code from git
cd opentk                                    # Enter the source directory
# open OpenTK.sln

Alternatively if you want to build using our buildscript you can use build.cmd / build.sh which require .net 6 to be installed.

git clone https://github.com/opentk/opentk   # Download source code from git
cd opentk                                    # Enter the source directory
./build.cmd / ./build.sh                     # Run the build script for your platform

To specify a specific target run:

./build.cmd -t <Target>

Contributing

OpenTK uses and encourages Early Pull Requests. Please don't wait until you're done to open a PR!

  1. Install Git and the .Net Core SDK
  2. Fork OpenTK
  3. Create a branch on your fork.
  4. Add an empty commit to start your work off (and let you open a PR): git commit --allow-empty -m "start of [thing you're working on]"
  5. Open a Pull request with [WIP] in the title. Do this before you actually start working.
  6. Make your commits in small, incremental steps with clear descriptions.
  7. Tag a maintainer when you're done and ask for a review!

Click here for good first issues.

Click here for everything we need help with.

Requirements

  • Windows (7/8,10), Linux, Mac OS X, *BSD, SteamOS, Android or iOS
  • For graphics, OpenGL drivers or a suitable emulator, such as ANGLE
  • For audio, OpenAL drivers or OpenAL Soft
  • To develop desktop applications: Visual Studio, Rider, or the command line tools.
  • To develop Android applications: Visual Studio and Xamarin
  • To develop iOS applications: Visual Studio, Xamarin and XCode

Documentation

API Documentation is available on the official website or inline from favourite IDE.

You can also browse the full API on the official website

Additional information can be found in the OpenTK Manual.

Technical documentation about the implementation of OpenTK can be found in the Technical Wiki.

Need Help?

Come chat with us on Discord.

We're happy to help with anything from learning OpenGL to advanced OpenTK questions.

License

The Open Toolkit is distributed under the permissive MIT/X11 license and is absolutely free.

glwpfcontrol's People

Contributors

bboldenow avatar bezo97 avatar eschryn avatar francotiveron avatar itee avatar justin113d avatar kaktusbot avatar marcotod1410 avatar nogginbops avatar simi4 avatar softwareantics avatar svabik avatar utkumaden avatar varon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glwpfcontrol's Issues

Control does not display on device with 2 GPUs (sometimes)

I believe this is occurring because the GL context and the DX context are running on different devices. We might need to do some fancy stuff to get them to occupy the same one.

I have a test setup we can replicate this on, but we need to figure out if either:
a) the wrong GL device is being used
b) the wrong DX device is being used.

Would love some thoughts on how we can detect this.

Blurred texture wpf control Width issue.

I am new to opentk so please forgive me,

I started a new WPF project and with the help of justin113d and lots of confusion later I was finally able to render to the wpf control.

However soon after I noticed that my 100x100 pixel image that I rendered as a texture to two triangles was blurry, I then noticed the edges of the wpf control had white lines down the side of it.

The control is 800x800 and the viewport is 800x800.

Taking a screenshot of the wpf control under the advice of jvbsl I was able to measure the control as 801x800, so resizing the control to 799x800 resolved my pixel blurred issues not only on the lines left+right of the wpf control but the rendered triangle texture as well.

Please let me know if you need further details.

It doesn't work on Parallels Desktop on Mac.

Hello.

I just tried the latest version of glWPFControl,
It doesn't work properly on Parallels Desktop on Mac.

Is Parallels Desktop on Mac not supported?
My environment ↓

PC: iMac 2019 4K
GPU : AMD Radeon Pro 560X
Version of Parallels Desktop : 15
Virtual OS : Windows 11 Pro

スクリーンショット 2022-04-15 23 04 01

Here is the error message ↓
スクリーンショット 2022-04-15 23 05 05

And, GLWpfControl on Bootcamp may or may not work on some Macs.
(Both are Windows 11 Pro)

◯ It works on Bootcamp of iMac 2019.
(GPU : Radeon Pro 560).

✗ It doesn't work on Bootcamp of Macbook Pro 2015.
(GPU : Intel Iris Pro Graphics).

GLControl using WindowsFormsHost works on Bootcamp,
But there is a flickering problem when moving the View...
So I'd rather use GLWpfControl if possible !

Antialiasing & Stencil buffer not working

Hi all. Thank you for excellent work. Easy to implement - very fast and convenient. For Apps with WPF and OpenGL it is a must.
I just want to indicate that the antialiasing as well as the stencil buffer are not working. These two features would be very welcome. As your PresentationParameters structure has already reserved members MultiSampleQuality, EnableAutoDepthStencil I presume that you have already plan to implement them. Looking forward to those features.

Image loads flipped in X and Y

Hi!

I am loading image data using this control, and it works great, except my image is inverted in X and Y.

Is there a simple way to fix this? Code below:

public static int LoadTexture()
        {
            byte[] bytes = _gv.GetTextureBytes(frameNum);// grabs image data

            int tex;
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            GL.GenTextures(1, out tex);
            GL.BindTexture(TextureTarget.Texture2D, tex);

        
            GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, InternalFormat.CompressedRgbaS3tcDxt1Ext, width, height, 0, _gv.FrameBytes, bytes);


            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            return tex;
        }

        public static void DrawImage(int image)
        {
            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();

     
            GL.Ortho(0, width, 0, height, -1, 1);

            GL.MatrixMode(MatrixMode.Modelview);
          

            GL.PushMatrix();
            GL.LoadIdentity();

            GL.Disable(EnableCap.Lighting);

            GL.Enable(EnableCap.Texture2D);

          
            GL.BindTexture(TextureTarget.Texture2D, image);

            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(0, 0);
            GL.Vertex3(0, 0, 0);

            GL.TexCoord2(1, 0);
            GL.Vertex3(width, 0, 0);

            GL.TexCoord2(1, 1);
            GL.Vertex3(width, height, 0);

            GL.TexCoord2(0, 1);
            GL.Vertex3(0, height, 0);

            GL.End();

            GL.Disable(EnableCap.Texture2D);
            GL.PopMatrix();

            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();

            GL.MatrixMode(MatrixMode.Modelview);
        }



        public static void Render()
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            texture = LoadTexture();
            DrawImage(texture);

        }

Multiple WPFControls causes stack overflow with KeyUp/DownEvent Raise event

Problem:
I am using version 4.2.2 and am instantiating multiple GLWpfControls (my application can have multiple tabs with an OGL-based scene) and am encountering a stack overflow upon launching the other GLWpf controller. I've found the root cause of this to be related to the OnKeyUp/OnKeyDown functions that ultimately call RaiseEvent.

Some possible solutions:
I've worked around this in my local repo by checking if the event is handled or not. In my KeyUp/Down callbacks I've set the event's Handled property to true and I made the following edit:

In GLWpfControl.cs:

        internal void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.OriginalSource != this && !e.Handled)
            {
                KeyEventArgs args = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key);
                args.RoutedEvent = Keyboard.KeyDownEvent;
                // \todo I am commenting out because I get an overflow here...
                RaiseEvent(args);
            }
        }

Note that I added the && !e.Handled and am flagging the event as Handled=true in my own key callbacks.

My working theory is that two GLWpfControllers get into an infinite loop by catching/raising the event until the stack overflows.

At the very least, could we get some kind of user-level setting to enable/disable the event handling to avoid this. Or even a setting in Start()'s to protect from this block:

EventManager.RegisterClassHandler(typeof(Control), Keyboard.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);
EventManager.RegisterClassHandler(typeof(Control), Keyboard.KeyUpEvent, new KeyEventHandler(OnKeyUp), true);

Something like

            if ( _settings.RegisterKeyHandlers )
            {
                EventManager.RegisterClassHandler(typeof(Control), Keyboard.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);
                EventManager.RegisterClassHandler(typeof(Control), Keyboard.KeyUpEvent, new KeyEventHandler(OnKeyUp), true);
            }

.Net framework application crashes with System.StackOverflowException: 'Exception_WasThrown'

Hi,

I have .net framework 6.0 and GLWpfControl 4.2.2

I put GLWpfControl in a sub window, it works good for the first show the sub window, but when open the sub window for the second time, press the arrow keys (actually any key) will case System.StackOverflowException: 'Exception_WasThrown'

but there is no stack trace, and not event logs.
I believe something must be cleared on window closing, any advise?

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            Window1 dialog = new Window1();
            dialog.ShowDialog();
        }
    }
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            var settings = new GLWpfControlSettings
            {
                MajorVersion = 2,
                MinorVersion = 1
            };
            OpenTkControl.Start(settings);

            //GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            //GL.Enable(EnableCap.ScissorTest);
        }
}

Control isn't resized correctly

Hi, first of all, thanks for this very useful package, it solves some current issues with OpenTK and its dependencies and is very nice to use.

However, the control displays odd behaviour when it's resized. If put inside a Grid, and the Grid column is resized using a GridSplitter, the control will not update its size until the row is resized... and vice versa. Note: The parent control type seems to be irrelevant, this happens when parenting the GLWpfControl inside other container types, too.

Here's a screen recording (in GIF format) which shows the undesirable behaviour:
https://i.gyazo.com/972ae86b2ff91b09da3fa715075c2302.gif

I'm not sure if this is intentional behaviour, or can be solved via code (perhaps by invalidating something?), but it seems a little strange to me, and I'd probably consider it a bug... unless it's just the way I'm using the control

(Edit) Oh I should mention, in the GIF the magenta area is the control. The space above it is intentional.

How to correct release resources?

I release resouces like

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
            GL.UseProgram(0);

            // Delete all the resources.
            GL.DeleteBuffer(VBO);
            GL.DeleteVertexArray(VAO);
            GL.DeleteBuffer(EBO);

            GL.DeleteProgram(ActiveShader.Handle);

But this won't work.Everytime reopen the window that contains GLWpfControl.I got this exception:
"An unhandled exception of type 'System.ExecutionEngineException' occurred in OpenTK.Graphics.dll".

Bug with multiple monitors - in mode duplicated displays

I was just playing with the GLWpfControl - testing for multiple monitors. Works well with extended monitors - one can drag from display to display. Switching monitor off is no problem.
It crashes, however, in the following scenario (my preferred configuration): Normally I work at FullHD - seeing on both the notebook monitor and external monitor the same stuff (displays are duplicated). When I close the lid of computer - the main monitor shows 4K. It was working fine with GLControl but not with GLWpfControl - yet.
The GLWpfControl.Example in such a case (no matter whether we close the lid or open it) freezes on some lock in PreRender function.
My application (when lid is closed or opened) crashes instead - on some Interop: Message=UCEERR_RENDERTHREADFAILURE (0x88980406).
I guess should be easy to reproduce for anyone.
Seems when the context is given - it is not able to change automatically to match the other monitor settings? But I only speculate here...

The VBO or VAO is support?

Hi,

I found this control that can't write .SwapBuffers();
Have a method to draw the mesh from buffer?

Cannot install NuGet package 4.2.1 / incompatible with .NET 6.0?

While issue #77 now does appear to be fixed, I still cannot use it when targeting .NET 6.0. Any attempt to ex. update the package from 4.1.0 through VS' NuGet Package Manager results in an error while restoring packages (no error code), causing the changes to be rolled back, plus error NU1202, saying that 4.2.1 is incompatible with net6.0-windows[...] and only supports netcoreapp3.1-windows.

Comparing compatible framework information for 4.1.0 and 4.2.1 on NuGet.org, the former is listed as compatible with netcoreapp3.1 (no suffixes) and lists several more computed target frameworks (including ex. net6.0-windows), while the latter only lists netcoreapp3.1-windows (with the suffix) and no computed target frameworks.

To (hopefully) reproduce:

  • Create new WPF application project targeting .NET 6.0
  • Add OpenTK 4.3.0 and GLWpfControl 4.1.0
  • Follow the Readme's Getting Started section
  • Project builds and runs fine

Then:

  • Attempt to update GLWpfControl to 4.2.1
  • Encounter aforementioned error NU1202

I guess this is also an issue with the updated build system, maybe (somewhat educated guess) due to it setting the target framework specifically as netcoreapp3.1-windows instead of the more generic netcoreapp3.1?

Incorrect mathematical calculations when used in 32-bit applications

I created a primitive application (.NET Framework 4.6.1) by simply placing the GLWpfControl component in the WPF window.
BugDemo.zip

In the project settings, I specified that the application is 32-bit.

The screenshot below shows the result of calculating the sum of two variables before initializing the GLWpfControl and after initializing it. It can be seen that after initialization, there are problems in calculating the sum.
picture

If I specify in the project settings that the application is 64-bit, then the amount is calculated correctly.

I use OpenTK 3.3.1, OpenTK.GLWpfContol 3.3.0

Rendering Context MakeCurrent Doesn't Work From Other Threads

Sorry, I can't get to Discord via work, hopefully this is the right place to post -

Currently MakeCurrent doesn't work from other threads for rendering contexts - it throws a resource in use exception. This seems like it'd be worthwhile so you can spawn threads for texture loading and the like that can subsequently request the context. If there is a way to do this currently feel free to let me know (or if there's a better place to post requests).

Latest version to nugget

Hello,
Could you please update the nugget package with the latest changes that expose the binding context from the last commit as of now ?
Thank you a lot !

Debugging with e.g. RenderDoc

Hi there and thank's for the great and fast control.
Is there any way to debug my application with some GFWpfControls in it with a tool like RenderDoc?
Is there any tool I can use to do that? I am not getting any information about the application in all tools I tried and I think maybe it's because of the DX<->OGL interop?

What can I do? I would really like to be able to debug my shaders to see 'what's in there' :).
Thanks

Rendering issues when having multiple WPF Windows with seperate GLWpfControls

Ref: mono/SkiaSharp#745 (comment)
Copy of my comments from there and what i tried.

But it does have some problems, it doesn't really seem to like rendering two dock windows (AvalonDock) it gets confused.
firefox_2021-03-23_20-32-23
Some elements suddenly stop showing up, swapping back and forth when zooming.
When I hide my grid element (basically just rendering a bunch of lines) it partially comes back, but other things bug out.

Definitely related to GL, if I swap back to SKElement it renders normally again.
I'm using one SKGLWpfControl per window, and it messes up pretty badly.
If I use SKElement for both it works fine.
Hacky workaround, use SKGLWpfControl for the first Map window, and SKElement for all further created Map windows.
https://github.com/WolfCorps/TacControl/blob/bba4d364548fc18a29d29b2138a8e44de619f7d2/src/DesktopClient/Misc/MapControl.cs#L547-L559
Works nicely too, but of course is missing the performance improvement on the second window.

WolfCorps/TacControl@a90164a
Here is my code, didn't make any changes to SKGLWpfControl itself. I assume the issue is inside OpenTK.GLWpfControl

Edit: I thought this might be the problem.

var window = Window.GetWindow(depObject);

It shares the same context, for both windows, which it seems like it shouldn't.
But even using mainSettings.ContextToUse to select seperate context for both windows, doesn't help.

Changing the code to manually get the correct window handle via Application.Current.Windows, also not better.
Two contexts in two seperate windows will confuse eachother.
Out of ideas at this point, but I also don't really know GL nor any of this code.

I don't have time currently to make a simpler repro, without maybe SkiaSharp/Mapsui/AvalonDock.

GL.Enable(EnableCap.ScissorTest); cause rendering area problem

just one grid contains one GLWPFControl.But use code like this(code from Learn OpenTK project .https://github.com/opentk/LearnOpenTK):
GL.ClearColor(c);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.LoadIdentity();

        _shader.Use();

        GL.BindVertexArray(_vertexArrayObject);

        
        GL.DrawArrays(PrimitiveType.Triangles, 0, 3);

this will cause rendering area less than true window size.(less width with 90pix,less height with 20pix...).But delete GL.Enable(EnableCap.ScissorTest); have no rendering area problem.
here is my environment.
Windows 10
WPF .net core 3.1 App
OpenTK 4.7.1
GLWpfContrl 4.1.0

Flickering and No display, in the Intel HD Graphics

Flickering occurs in the Example program.

This is my environment ↓
キャプチャ2

Black flicker, After that nothing is displayed...
B

At first the graphics appear fine, but while resizing the window by dragging, there is a black flicker, After that it turns black and nothing appears.
(I have not rewritten anything in the program.)

My image is that the buffer is running out of write space.

As long as you have time, I would appreciate your investigation.
Thank you.

Blank screen when running app on microsoft remote desktop

I tested out the wpf control and it works great locally. I tried remoting in to my work computer with remote desktop and when I run it the window is blank white. It doesn't crash but you can't see anything. Both computers have Windows 10 and nvidia graphics cards with the latest drivers. Also remote desktop worked fine on the old winforms gl control.

Assembly and namespaces not found after install via NuGet

Hello, I created a new WPF application for testing and am following the Getting Started instructions in the Readme, but am encountering an issue trying to include GLWpfControl in the window.

Adding xmlns:glWpfControl="clr-namespace:OpenTK.Wpf;assembly=GLWpfControl" to my MainWindow immediately causes error XLS0418 in MainWindow.xaml, i.e. that the assembly "GLWpfControl" could not be found. Additionally, trying to build and run the project regardless then causes error CS0234 to appear from auto-generated code in MainWindow.g.i.cs, i.e. that the type or namespace name "Wpf" couldn't be found in the namespace "OpenTK".

And indeed, IntelliSense offers me all the usual OpenTK namespaces (Audio, Compute, Core, etc.) if I type "OpenTK.[...]" ex. in the window's constructor, but no "Wpf".

I'm using Visual Studio Community 2022 on Windows 10 Pro 21H2, my test project is targeting .NET 6.0, OpenTK and GLWpfControl are the latest stable versions on NuGet (4.7.4 and 4.2.0, respectively).

I'm rather new to WPF, having stuck with WinForms for the longest time, so this might very well be user error. In that case, am I missing something obvious? Is there something else I have to do to reference the assembly correctly, after installing the package? Is the package incompatible with .NET 6.0 and/or VS 2022?

Any help would be very much appreciated.

Turning off vertical sync doesn't have any effect

During some prototyping work, I wanted to compare the performance of GLWpfControl with my current approach for rendering OpenGL content in WPF. I would basically like to measure which approach has the biggest performance overhead. My intent is to open a large window, and compare framerates for both approaches. I don't want to add too much actual content so that the performance overhead is more prominent, so I'm painting a fairly lightweight scene using OpenGL.

This means that I end up with high framerates, even for fairly large windows (3840x1080 in my case, I can't seem to go beyond this size). To get proper FPS results, I disabled Vertical Sync in the NVidia control panel. This has the following effect:

  • In the old approach, the framerate is not capped to 60 FPS anymore, and I get framerates of ~250
  • Using GLWpfControl, the framerate remains capped at 60 FPS.

The second point is a bit unexpected for me since I didn't see anything in the GLWpfControl source code that indicates a fixed framerate. I might be wrong though.

Is this a bug ?
Is this a normal side-effect of the DirectX-OpenGL interop in GLWpfControl ?
Is the framerate capping something I can enable or disable some other way ?

Note that I'm using OpenTK.GLWpfControl version 3.3.0 since I'm using .Net Framework.

GLWpfControl.sln can not execute

I downloaded GLWpfControl-master tutorial from the OpenTK repository, unfortunately, the project can not execute and it is giving me the following error below, I am using Visual Studio 2022 community version. I want to know whether the problem is unique to my machine or there is something I am not doing correctly.

A project with an Output type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution which is references the library project. Set the executable project as the startup project.

Quick Font Support?

does this support Quickfont Library? I tried to implement QuickFont but it rendered nothing :(...
a quick repocode for this:
repo

Provide access to current graphics context

There's currently no way to get the IGraphicsContext that gets created from the control.

I realize there's the ability to pass a custom context via GLWpfControlSettings.ContextToUse, however it would be nice to be able to get the shared one created automatically without having to do it manually.

Issues to Fix

Here is just a place for me to list a few things that I'm going to hopefully fix up with GLWpfControl:

  • VSyncing - Should have the ability to turn on and off just like with GLFW backend for OpenTK.
  • Events should be handed for (hopefully) both the control and real time updating.
  • It seems as though the example project has a stack overflow exception when pressing any key on my machine.

If anyone has any issues they'd like to add to the list just chuck in a comment and that way we can sort them out by priority and get them fixed up.

WGL: The driver does not appear to support OpenGL when calling GLWpfControl.Start

Googling the above error gives me a bunch of Minecraft discussions, so I'm at a loss what I'm doing wrong. I have a large 64-bit Win Forms app, .NET 5, I've converted from DirectX 9 to OpenTK 4.4. I have I get the above error at glControl.Start() when I call this method on a class that inherits from ElementHost. I can run the Example project in this repository fine. I even ran the Example project using ES30, OpenTK 4_4, 64 bit, .NET 5 just fine. I'm unable to use a debugging callback because it wants me to load the bindings or a window first and loading the bindings gives me an error as well. I'm calling this Start() method in the main form's Load event, but I tried calling it from the main form's constructor as well (which is created from Main()).

    public bool Start()
    {
        glControl = new GLWpfControl();
        this.Child = glControl;

        //openGLDebugDelegate = new DebugProc(openGLDebugCallback);
        //GL.DebugMessageCallback(openGLDebugDelegate, IntPtr.Zero);
        var settings = new GLWpfControlSettings();
        settings.MajorVersion = 3;
        settings.MinorVersion = 0;
        //settings.GraphicsProfile = ContextProfile.Any;
        glControl.Start(settings);

        RenderContext = new RenderContextGL(this);
        return true;
    }

how to handle key events in glWpfControl:GLWpfControl ?

i tested mouse events(down, up) and test for keyboard events.

mouse events are works great but key events is not triggering.

i want keyboard event firing at only got focused wpfglcontrol.

i already read issue #31 and i think it is not resolved currently.

is this bug or something?

any solution?

best regards.

Dead Example Links in README

The links to the examples in the README file are dead. Seems like a leftover from a repository ownership transfer, perhaps? Pretty quick fix, I'll be sending the PR soon, opening an issue for tracking reasons.

For additional examples, see [MainWindow.xaml](https://github.com/varon/GLWpfControl/blob/master/src/GLWpfControlExample/MainWindow.xaml#L11) and [MainWindow.xaml.cs](https://github.com/varon/GLWpfControl/blob/master/src/GLWpfControlExample/MainWindow.xaml.cs#L18) in the example project.

High GPU Usage without rendering anything on the screen.

Hi,

I am having issues with GPU usage where a simple test app is using 20% to 30% GPU while idle and without calling the Clear() method or even rendering anything on the screen.

The GPU usage starts at around 4% and within a few seconds it jump to like 15% and if I hit ALT + Enter to switch to full screen mode it climbs to 30% + which is a hell of a lot of usage for a blank screen. I don't have any issues with any other apps on my machine so I am very confidant it's related to GLWpfControl.

My machine specs:
Windows 10
image

Test app GPU usage in task manager:

image

Sample test app:

https://easyupload.io/jifxac
Sorry but Girhub wouldn't let me upload a zip file so I hosted it somewhere else.

Thanks in advance.

Added compatibility Window Remote Desktop in 3.x

It is not shown in Windows Remote Desktop.
I only see a gray screen.
So, looking for a solution, I found the following solution:
#42
By the way, we still use the .Net Framework.
So, I would appreciate it if you could add and release it.

Stencil support

Hi, can we expect the new release with stencil support? As I can see, the code is already there, but it was committed after the latest official 4.1.0. Thanks!

Where to put cleanup (dispose code)

Thansk for a great control!
When I want to dispose GL resources, like textures or frame buffers when the control is no longer used, I found only the Unloaded event provided by WPF. But this event is not called on application shutdown (https://docs.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.unloaded?view=net-5.0).
I opted for Dispatcher.ShutdownStarted but this will only be called on application shutdown and not on other visual changes, which may require disposal and recreation of resources. Of course I could handle both, but this seems hackish to me.

What is your best practice in this case?

One suggestion in the thread
https://stackoverflow.com/questions/1550212/proper-cleanup-of-wpf-user-controls is to override the OnVisualParentChanged.

WinUI 3/.Net5 Support

I'm developing a windows application using WinUI3 and .Net5.0. Unable to use this control. Are there any alternatives available or should link any WPF related dlls?

Flickering when low framerate?

Hi team, default sample in the repos works well, but it' on high framerate which is 60. When I render lot's of objects in the control , flickering occured, i think the source the problem maybee d3dimage . I've grope for solution to prevent flicker on d3dimage but failed. Can anyone help me?

Blank window and keep no response

Hi,

I have OpenTK 4.7.4 and OpenTK.GLWpfControl 4.2.2, installed from NuGet of Visual Studio 2022.
.net framework version 6.0

After put GLWpfControl into the window, the window keep blank and no response.
if remove the "OpenTkControl.Start" call, the window can show up, with text on the control:
"OpenGL content. Call Start() on the control to begin rendering."

what's the problem? do I need to install something else to make it to work?

<Grid> <GroupBox Header="{Loc Rendered}"> <glWpfControl:GLWpfControl x:Name="OpenTkControl"/> </GroupBox> </Grid>

code:
`
public ThreeDWindow()
{
InitializeComponent();

        var settings = new GLWpfControlSettings
        {
            MajorVersion = 4,
            MinorVersion = 2
        };
        OpenTkControl.Start(settings);

        //GL.Enable(EnableCap.Blend);
        //GL.Enable(EnableCap.DepthTest);
        //GL.Enable(EnableCap.ScissorTest);
    }`

Package has dependency to OpenTK v4.3.0 only

Hi,

Thanks a lot for the library. Would it be possible to make this package compatible with the latest OpenTK version (v4.6.7 as time of writting).

Current dependency is setup as OpenTK (>= 4.3.0 && <4.4.0), I guess making it OpenTK (>= 4.3.0) would fix that.

Thanks a lot!

Keep aspect ratio when resized?

Hi, I am using this control to ply a video file, and as such need the aspect ratio to stay the same when the window / usercontrol is resized. I am struggling to find a solution for this. Would you be able to point me in the right direction?

Thanks1

Control rendering black, GL returns error codes refering to the framebuffer.

*I'm targeting .net 5, of course, making a WPF app.
*I'm using Visual Studio Community 2019. My computer only has Intel Integrated Graphics for the gpu.

For some reason, as the title says, the control only renders pitch black.
I've tried changing the OpenGL version on GLWpfControlSettings, and also changing the target framework version from 5.0 to core 3.1, but to no avail.

Here's a snippet of my code:
*Note that i'm inheriting GLWpfControl; i tried using the vanilla GLWpfControl but it also didn't render anything.

//Gets called after InitializeComponent in MainWindow.xaml.cs
public void Initialize()
{
    GLWpfControlSettings settings = new GLWpfControlSettings();
    Start(settings);
}

//Render="GLWpfControl_Render" in the xaml file of the custom control.
void GLWpfControl_Render(TimeSpan delta)
{
    //throw new Exception(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer).ToString());
    // [ returns FramebufferIncompleteMultisample ]

    GL.ClearColor(Color4.White);
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

    throw new Exception(GL.GetError().ToString());
    // [ returns InvalidFramebufferOperationExt ]
}

KeyDown, KeyUp, GotFocus, LostFocus

Is there something I'm missing in order to use these events in the control? MouseMove, SizeChanged, and Render work fine.

<glWpfControl:GLWpfControl
x:Name="OpenTkControl"
KeyUp="OpenTkControl_KeyUp"
MouseMove="OpenTkControl_MouseMove"
LostFocus="OpenTkControl_LostFocus"
GotFocus="OpenTkControl_GotFocus"
Loaded="OpenTkControl_Loaded"
SizeChanged="OpenTkControl_Resize"
Render="OpenTkControl_OnRender"
/>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.