dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
755 stars 299 forks source link

remove useless OpenGL instance in SceneControl.scene #106

Closed bitzhuwei closed 1 year ago

bitzhuwei commented 9 years ago

It's about the 'SharpGL.SceneControl' class. In its 'SharpGL.SceneControl.Scene' property there is an OpenGL instance 'gl' created like this: private OpenGL gl = new OpenGL();. (let's call this 'gl' instance 'glA')
Here comes a problem when using the 'SharpGL.SceneControl'. If you use var c = this.sceneControl.Scene.OpenGL.RenderContextProvider;, the c will be null. But actually there is another OpenGL instance(let's call it 'glB') that holds a valid RenderContextProvider. And 'glB' is the one we should have gotten. This 'glB' is instantiated in 'SharpGL.SceneControl''s parent class(SharpGL.OpenGLControl) like this:private readonly OpenGL gl = new OpenGL();. And it has binded to everything that should be. So I think we can force 'glA' pointing to 'glB' by updating the InitializeComponent() method in SharpGL.SceneControl class like this:


        private void InitializeComponent()
        {
            // 
            // OpenGLCtrl
            // 
            this.Name = "OpenGLCtrl";
            this.scene.OpenGL = this.OpenGL;// force 'glA' pointing to 'glB'
        }

And also the 'glA''s instatiation should be removed.
Sorry for my english.

AraHaan commented 4 years ago

bruh can you update this fork please. This shit is bitting me badly where I was like WTF why the fuck is the model not rendering on my form even when I call draw on a scene myself.

dwmkerr commented 4 years ago

This is a monster PR. OK I'll take it commit by commit and see what I can do

dwmkerr commented 4 years ago

@bitzhuwei @AraHaan try v2.4.5 which should fix this. (I.e. the duplicate instance). The other elements of this PR I'll have to pull in separately

AraHaan commented 1 year ago

@dwmkerr thanks, so everything from this pr is now part of the library?

dwmkerr commented 1 year ago

Yes I believe so we can close this one now @AraHaan !