Skip to content

Commit

Permalink
use logical size when building window
Browse files Browse the repository at this point in the history
  • Loading branch information
Grokmoo committed Dec 24, 2024
1 parent 4e0aacb commit 5470367
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/demo_gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use glutin::surface::{Surface, WindowSurface, GlSurface};
use glutin_winit::DisplayBuilder;
use glutin::display::{GlDisplay, GetGlDisplay};
use winit::application::ApplicationHandler;
use winit::dpi::LogicalSize;
use winit::event::WindowEvent;
use winit::window::Window;
use winit::raw_window_handle::HasWindowHandle;
Expand Down Expand Up @@ -33,7 +34,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let attrs = Window::default_attributes()
.with_title("Thyme GL Demo")
.with_inner_size(winit::dpi::PhysicalSize::new(1280, 720));
.with_inner_size(LogicalSize::new(1280, 720));

let display_builder = DisplayBuilder::new().with_window_attributes(Some(attrs));
let config_template_builder = ConfigTemplateBuilder::new();
Expand Down
9 changes: 6 additions & 3 deletions examples/demo_glium.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winit::{application::ApplicationHandler, event::WindowEvent};
use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, window::Window};
use thyme::{bench, Context, ContextBuilder, GliumRenderer, WinitError, WinitIo};

mod demo;
Expand All @@ -16,10 +16,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let event_loop = glium::winit::event_loop::EventLoop::builder()
.build().map_err(|e| thyme::Error::Winit(WinitError::EventLoop(e)))?;

let attrs = Window::default_attributes()
.with_title("Thyme Demo")
.with_inner_size(LogicalSize::new(window_size[0], window_size[1]));

// create glium display
let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
.with_title("Thyme Demo")
.with_inner_size(window_size[0] as u32, window_size[1] as u32)
.set_window_builder(attrs)
.build(&event_loop);

// create thyme backend
Expand Down
14 changes: 10 additions & 4 deletions src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl AppBuilder {
use glutin::context::{ContextApi, ContextAttributesBuilder, Version, NotCurrentGlContext};
use glutin_winit::DisplayBuilder;
use glutin::display::{GlDisplay, GetGlDisplay};
use winit::dpi::LogicalSize;
use winit::raw_window_handle::HasWindowHandle;
use winit::window::Window;

Expand All @@ -218,8 +219,8 @@ impl AppBuilder {
.build().map_err(|e| Error::Winit(WinitError::EventLoop(e)))?;

let attrs = Window::default_attributes()
.with_title("Thyme GL Demo")
.with_inner_size(winit::dpi::PhysicalSize::new(1280, 720));
.with_title(&self.title)
.with_inner_size(LogicalSize::new(self.window_size.x as u32, self.window_size.y as u32));

let display_builder = DisplayBuilder::new().with_window_attributes(Some(attrs));
let config_template_builder = ConfigTemplateBuilder::new();
Expand Down Expand Up @@ -280,6 +281,8 @@ impl AppBuilder {
/// in this Builder and using the [`GliumRenderer`](struct.GliumRenderer.html).
#[cfg(feature="glium_backend")]
pub fn build_glium(self) -> Result<GliumApp, Error> {
use winit::{dpi::LogicalSize, window::Window};

use crate::winit_io::WinitError;

if self.logger {
Expand All @@ -289,9 +292,12 @@ impl AppBuilder {
let event_loop = glium::winit::event_loop::EventLoop::builder()
.build().map_err(|e| Error::Winit(WinitError::EventLoop(e)))?;

let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
let attrs = Window::default_attributes()
.with_title(&self.title)
.with_inner_size(self.window_size.x as u32, self.window_size.y as u32)
.with_inner_size(LogicalSize::new(self.window_size.x as u32, self.window_size.y as u32));

let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
.set_window_builder(attrs)
.build(&event_loop);

let mut io = crate::WinitIo::new(&window, self.window_size)
Expand Down

0 comments on commit 5470367

Please sign in to comment.