Skip to content

Commit 0d1c35e

Browse files
authored
Fix scale factor when using GLFW. (#83)
1 parent e425b10 commit 0d1c35e

File tree

15 files changed

+29
-37
lines changed

15 files changed

+29
-37
lines changed

crates/processing_pyo3/src/glfw.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ impl GlfwContext {
3131
}
3232

3333
#[cfg(target_os = "macos")]
34-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
34+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
3535
use processing::prelude::surface_create_macos;
36+
let (scale_factor, _) = self.window.get_content_scale();
3637
surface_create_macos(
3738
self.window.get_cocoa_window() as u64,
3839
width,
@@ -42,8 +43,9 @@ impl GlfwContext {
4243
}
4344

4445
#[cfg(target_os = "windows")]
45-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
46+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
4647
use processing::prelude::surface_create_windows;
48+
let (scale_factor, _) = self.window.get_content_scale();
4749
surface_create_windows(
4850
self.window.get_win32_window() as u64,
4951
width,
@@ -53,8 +55,9 @@ impl GlfwContext {
5355
}
5456

5557
#[cfg(all(target_os = "linux", feature = "wayland"))]
56-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
58+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
5759
use processing::prelude::surface_create_wayland;
60+
let (scale_factor, _) = self.window.get_content_scale();
5861
surface_create_wayland(
5962
self.window.get_wayland_window() as u64,
6063
self.glfw.get_wayland_display() as u64,
@@ -65,8 +68,9 @@ impl GlfwContext {
6568
}
6669

6770
#[cfg(all(target_os = "linux", feature = "x11"))]
68-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
71+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
6972
use processing::prelude::surface_create_x11;
73+
let (scale_factor, _) = self.window.get_content_scale();
7074
surface_create_x11(
7175
self.window.get_x11_window() as u64,
7276
self.glfw.get_x11_display() as u64,

crates/processing_pyo3/src/graphics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Graphics {
176176
init(config).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
177177

178178
let surface = glfw_ctx
179-
.create_surface(width, height, 1.0)
179+
.create_surface(width, height)
180180
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
181181

182182
let surface = Surface {

examples/animated_mesh.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> {
2424

2525
let width = 600;
2626
let height = 600;
27-
let scale_factor = 1.0;
28-
29-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
3028
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3129

3230
let grid_size = 20;

examples/background_image.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> {
2323

2424
let width = 400;
2525
let height = 400;
26-
let scale_factor = 1.0;
27-
28-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2927
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3028
let image = image_load("images/logo.png")?;
3129

examples/box.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> {
2323

2424
let width = 400;
2525
let height = 400;
26-
let scale_factor = 1.0;
27-
28-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2927
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3028
let box_geo = geometry_box(100.0, 100.0, 100.0)?;
3129

examples/custom_attribute.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> {
2424

2525
let width = 600;
2626
let height = 600;
27-
let scale_factor = 1.0;
28-
29-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
3028
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3129

3230
let custom_attr = geometry_attribute_create("Custom", AttributeFormat::Float)?;

examples/glfw.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ impl GlfwContext {
3131
}
3232

3333
#[cfg(target_os = "macos")]
34-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
34+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
3535
use processing_render::surface_create_macos;
36+
let (scale_factor, _) = self.window.get_content_scale();
3637
surface_create_macos(
3738
self.window.get_cocoa_window() as u64,
3839
width,
@@ -42,8 +43,9 @@ impl GlfwContext {
4243
}
4344

4445
#[cfg(target_os = "windows")]
45-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
46+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
4647
use processing_render::surface_create_windows;
48+
let (scale_factor, _) = self.window.get_content_scale();
4749
surface_create_windows(
4850
self.window.get_win32_window() as u64,
4951
width,
@@ -53,8 +55,9 @@ impl GlfwContext {
5355
}
5456

5557
#[cfg(all(target_os = "linux", feature = "wayland"))]
56-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
58+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
5759
use processing_render::surface_create_wayland;
60+
let (scale_factor, _) = self.window.get_content_scale();
5861
surface_create_wayland(
5962
self.window.get_wayland_window() as u64,
6063
self.glfw.get_wayland_display() as u64,
@@ -65,8 +68,9 @@ impl GlfwContext {
6568
}
6669

6770
#[cfg(all(target_os = "linux", feature = "x11"))]
68-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
71+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
6972
use processing_render::surface_create_x11;
73+
let (scale_factor, _) = self.window.get_content_scale();
7074
surface_create_x11(
7175
self.window.get_x11_window() as u64,
7276
self.glfw.get_x11_display() as u64,

examples/gltf_load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn sketch() -> error::Result<()> {
2424
let mut glfw_ctx = GlfwContext::new(width, height)?;
2525
init(Config::default())?;
2626

27-
let surface = glfw_ctx.create_surface(width, height, 1.0)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
2828
let graphics = graphics_create(surface, width, height)?;
2929

3030
let gltf = gltf_load(graphics, "gltf/Duck.glb")?;

examples/lights.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> {
2323

2424
let width = 400;
2525
let height = 400;
26-
let scale_factor = 1.0;
27-
28-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2927
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3028
let box_geo = geometry_box(100.0, 100.0, 100.0)?;
3129
let pbr_mat = material_create_pbr()?;

examples/materials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn sketch() -> error::Result<()> {
2323
let mut glfw_ctx = GlfwContext::new(width, height)?;
2424
init(Config::default())?;
2525

26-
let surface = glfw_ctx.create_surface(width, height, 1.0)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2727
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
2828
let sphere = geometry_sphere(30.0, 32, 18)?;
2929

0 commit comments

Comments
 (0)