Skip to content

Dose sdl.SetHint(Sdl.HintWindowsDpiAwareness, "system"); not work? #2316

@Cn-mjt44

Description

@Cn-mjt44

I create a sdl opengl window in 1280x720, but it scale by system hdpi.
So I try to use sdl.SetHint(Sdl.HintWindowsDpiAwareness, "system") to disable that function, but is looks not work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Silk.NET.Assimp;
using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
using Silk.NET.SDL;
using Silk.NET.Windowing;

namespace SpaceFlight
{
    public class Game
    {

        private static GL? _gl = null;
        private static IWindow? _window = null;
        private static IInputContext? _input = null;
        internal static readonly HashSet<GameObject> allGameObjects = new HashSet<GameObject>();



        public static GL? gl => _gl;
        public static Sdl sdl => SdlProvider.SDL.Value;
        public static IWindow? window => _window;
        public static IInputContext? input => _input;

        public Game(string name)
        {
            if (_window != null) throw new Exception("Game arrady start");
            sdl.SetHint(Sdl.HintWindowsDpiAwareness, "system");
            Silk.NET.Windowing.Window.PrioritizeSdl();
            //Silk.NET.Windowing.Window.PrioritizeGlfw();
            WindowOptions options = new WindowOptions(true, new Vector2D<int>(Sdl.WindowposUndefined, Sdl.WindowposUndefined), new Vector2D<int>(1280, 720), 0.0, 0.0, GraphicsAPI.Default, name, WindowState.Normal, WindowBorder.Resizable, isVSync: false, shouldSwapAutomatically: true, VideoMode.Default);
            _window = Silk.NET.Windowing.Window.Create(options);
            _window.Load += Loaded;
            _window.Update += Update;
            _window.Render += Render;
            _window.Run();
        }

        private void Loaded()
        {
            _gl = _window?.CreateOpenGL();
            _input = _window?.CreateInput();
            // gl?.DepthFunc(DepthFunction.Gequal);
            gl?.ClearColor(0,0,0,1);
            gl?.ClearDepth(0);
            gl?.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
        }

        private void Update(double delta)
        {
            List<GameObject> cache = new List<GameObject>(from x in allGameObjects where !x.Destoryed select x);
            foreach(GameObject gameObject in cache) gameObject.Update(delta);
        }

        private void Render(double delta)
        {
            gl?.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
            gl?.Viewport(0,0,(uint)_window.Size.X,(uint)_window.Size.Y);
            List<GameObject> cache = new List<GameObject>(from x in allGameObjects where !x.Destoryed select x);
            Dictionary<uint,HashSet<GameObject>> objectAndSignal = new Dictionary<uint, HashSet<GameObject>>();
            foreach(GameObject gameObject in cache)
            {
                foreach(uint signal in gameObject.RenderSignal())
                {
                    if(!objectAndSignal.TryGetValue(signal,out HashSet<GameObject>? list))
                    {
                        list = new HashSet<GameObject>();
                        objectAndSignal.Add(signal,list);
                    }
                    list.Add(gameObject);
                }
            }

            List<KeyValuePair<uint,HashSet<GameObject>>> values = new List<KeyValuePair<uint, HashSet<GameObject>>>(objectAndSignal);
            for (int i = 0; i < values.Count; i++)
            {
                var a = values[i];
                for (int j = i + 1; j < values.Count; j++)
                {
                    var b = values[j];
                    if (a.Key > b.Key)
                    {
                        values[j] = a;
                        values[i] = b;
                        a = b;
                    }
                }
            }

            for (int i = 0; i < values.Count; i++)
            {
                uint signal = values[i].Key;
                foreach(GameObject gameObject in values[i].Value)
                {
                    gameObject.Render(delta,signal);
                }
            }
        }

        public void Destory()
        {
            _window?.Close();
            _window = null;
            _gl = null;
            _input = null;
        }
    }
}
  • Scale by system
    scale by system
  • Not scale by system
    not scale by system

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions