Skip to content

Commit

Permalink
viewport: fix resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
redthing1 committed Jul 16, 2024
1 parent 5db2fab commit f533f1d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion source/re/ng/scene.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ abstract class Scene {
if (viewport.sync_maximized) {
// copy output rect from screen bounds
viewport.output_rect = Core.window.screen_bounds;
viewport.resolution = resolution; // copy resolution
Core.log.info(format("synced viewport to screen bounds: %s", viewport.output_rect));
}

// create render target
viewport.render_target = RenderExt.create_render_target(
cast(int) viewport.output_rect.width, cast(int) viewport.output_rect.height
cast(int) viewport.resolution.x, cast(int) viewport.resolution.y
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion source/re/ng/scene2d.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ abstract class Scene2D : Scene {
auto vp = new Viewport2D();
vp.cam = cam;
vp.output_rect = output_rect;
vp.resolution = resolution;
vp.render_target = RenderExt.create_render_target(
cast(int) resolution.x, cast(int) resolution.y
cast(int) vp.resolution.x, cast(int) vp.resolution.y
);
viewports ~= vp;
return vp;
Expand Down
3 changes: 2 additions & 1 deletion source/re/ng/scene3d.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ abstract class Scene3D : Scene {
auto vp = new Viewport3D();
vp.cam = cam;
vp.output_rect = output_rect;
vp.resolution = resolution;
vp.render_target = RenderExt.create_render_target(
cast(int) resolution.x, cast(int) resolution.y
cast(int) vp.resolution.x, cast(int) vp.resolution.y
);
viewports ~= vp;
return vp;
Expand Down
9 changes: 4 additions & 5 deletions source/re/ng/viewport.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ import re.ng.camera.cam3d;

/// represents a view of a scene
abstract class Viewport {
/// the render target texture
/// the render target's texture
public RenderTarget render_target;
/// the render target's output rectangle
public Rectangle output_rect;
/// the render target's resolution
public Vector2 resolution;

/// whether to sync the render target to maximum size
public bool sync_maximized;
/// texture filter
public raylib.TextureFilter filter;

public @property Vector2 resolution() {
return Vector2(render_target.texture.width, render_target.texture.height);
}

void update() {

}
Expand Down

0 comments on commit f533f1d

Please sign in to comment.