Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

c# - Maximizing OpenTK Window doesnt resize the shown objects

I have the problem, that whenever I maximize the window, the size of the objects doesn't change like it should. If I just resize the window, the objects scale as they should, only maximizing doesn't work.

But the changes happen after the window leaves maximized mode. So after going back to normal window size, I can only see a small part of the rendered object.

The example is really simple; it just draws some triangle.

I don't think there's anything interesting happening; but they included this override:

protected override void OnResize(ResizeEventArgs e)
        {
            GL.Viewport(0, 0, Size.X, Size.Y);
            base.OnResize(e);
        }

So I guess this resizes the objects when resizing the window. I tried something similar for the maximizing event, but it didn't work:

protected override void OnMaximized(MaximizedEventArgs e)
        {
            GL.Viewport(0, 0, Size.X, Size.Y);
            base.OnMaximized(e);
        }

I even put GL.Viewport(0, 0, Size.X, Size.Y); at the beginning of the OnRenderFrame(...)-Function, but that didn't help either. (Size.X and Size.Y are correct all the time, i checked them.)

question from:https://stackoverflow.com/questions/65909404/maximizing-opentk-window-doesnt-resize-the-shown-objects

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should first call base.OnResize and then update the viewport size, you don't need to override OnMaximized:

protected override void OnResize(ResizeEventArgs e)
{
    base.OnResize(e); // this should be called immediately
    GL.Viewport(0, 0, Size.X, Size.Y);
}

Looking at the OpenTK source code you can see that Size is updated in base.OnResize(e) method so you are using stale values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...