Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL margin alignment issue #8276

Closed
crener opened this issue Jun 4, 2022 · 2 comments
Closed

OpenGL margin alignment issue #8276

crener opened this issue Jun 4, 2022 · 2 comments
Labels
bug help-wanted A contribution from the community would be most welcome.

Comments

@crener
Copy link

crener commented Jun 4, 2022

Describe the bug
When creating an OpenGL context (using Avalonia.OpenGL.Controls.OpenGlControlBase) with margin the position of the control is offset so that it moves to the bottom right corner of the control area rather than the center like I would expect.

To Reproduce
Steps to reproduce the behavior:

  1. Create new project
  2. Create an OpenGL control (inherit from Avalonia.OpenGL.Controls.OpenGlControlBase) - See example control
  3. Add the OpenGL to the main window and set a margin like this Margin="30"
  4. Make sure you have .With(new Win32PlatformOptions { UseWgl = true }) in the AppBuilder Config
  5. Start program

OpenGL Control:

using System;
using Avalonia;
using Avalonia.Media;
using Avalonia.OpenGL;

namespace OpenGLIssue.Views;

public class OpenGLControl : Avalonia.OpenGL.Controls.OpenGlControlBase, IAffectsRender
{
    public event EventHandler? Invalidated;

    public OpenGLControl()
    {
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        InvalidateVisual();
        return new Size(availableSize.Width, Math.Min(availableSize.Width, availableSize.Height));
    }

    protected override void OnOpenGlRender(GlInterface gl, int frameBuffer)
    {
        gl.Clear(16384);
    }
    
    protected override void OnOpenGlInit(GlInterface gl, int fb)
    {
        gl.ClearColor(1f, 192 / 255f, 202 / 255f, 1f);
    }

    protected override void OnOpenGlDeinit(GlInterface gl, int fb)
    {
    }
}

MainWindow:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:OpenGLIssue.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:OpenGLIssue.Views"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="OpenGLIssue.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="OpenGLIssue"
        Width="300" Height="300">

    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>

    <views:OpenGLControl 
        Margin="30"/>

</Window>

Expected behavior
Looking at the second screenshot I would expect it to render inside the blue area rather than being offset as that is where the margin says it should be

Screenshots
image
This is how it looks when rendering but using the Dev tools to render actual control size you can see that the OpenGL control isn't correctly positioned.
image

Desktop (please complete the following information):

  • OS: Windows 10 Pro 10.0.19043 Build 19043
  • Version 0.10.13, 0.10.14

Additional context
Add any other context about the problem here.

@crener crener added the bug label Jun 4, 2022
@maxkatz6
Copy link
Member

maxkatz6 commented Jun 4, 2022

As @kekekeks suggested, draw image call is invalid. Should be

            context.DrawImage(_bitmap, new Rect(_bitmap.Size), new Rect(Bounds.Size));

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs#L37

@maxkatz6 maxkatz6 added the help-wanted A contribution from the community would be most welcome. label Jun 4, 2022
@jp2masa
Copy link
Contributor

jp2masa commented Feb 4, 2023

This was fixed in #8728, then the control was reworked on #10014, I tested it now and it works fine. This can be closed.

@maxkatz6 maxkatz6 closed this as completed Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

No branches or pull requests

3 participants