glfw: add Window.getFramebufferSize
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
7cbe13941e
commit
96ee2a1dc6
1 changed files with 34 additions and 0 deletions
|
|
@ -488,6 +488,24 @@ pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize)
|
||||||
try getError();
|
try getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves the size of the framebuffer of the specified window.
|
||||||
|
///
|
||||||
|
/// This function retrieves the size, in pixels, of the framebuffer of the specified window. If you
|
||||||
|
/// wish to retrieve the size of the window in screen coordinates, see @ref glfwGetWindowSize.
|
||||||
|
///
|
||||||
|
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
|
||||||
|
///
|
||||||
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
|
///
|
||||||
|
/// see also: window_fbsize, glfwWindow.setFramebufferSizeCallback
|
||||||
|
pub inline fn getFramebufferSize(self: Window) Error!Size {
|
||||||
|
var width: c_int = 0;
|
||||||
|
var height: c_int = 0;
|
||||||
|
c.glfwGetFramebufferSize(self.handle, &width, &height);
|
||||||
|
try getError();
|
||||||
|
return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) };
|
||||||
|
}
|
||||||
|
|
||||||
test "defaultHints" {
|
test "defaultHints" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
@ -689,3 +707,19 @@ test "setAspectRatio" {
|
||||||
|
|
||||||
try window.setAspectRatio(4, 3);
|
try window.setAspectRatio(4, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getFramebufferSize" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null) catch |err| {
|
||||||
|
// return without fail, because most of our CI environments are headless / we cannot open
|
||||||
|
// windows on them.
|
||||||
|
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
defer window.destroy();
|
||||||
|
|
||||||
|
_ = try window.getFramebufferSize();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue