pub struct Context { /* private fields */ }Expand description
The overarching state of the crate. Intended to live outside of the main game loop.
This is the struct you can get a GraphicsContext from, and which should live as long as you’re drawing anything. Illustrated:
use fae::Context;
let mut fae_context: Context = Context::new();
loop {
// Here's your gameloop, and now you want to draw something.
// First, create the GraphicsContext with start_frame.
let mut ctx: fae::GraphicsContext = fae_context.start_frame(width, height, dpi_factor);
// Then do your rendering stuff.
spritesheet.draw(&mut ctx)
/* ... */
.finish();
// Finish frame and consume the GraphicsContext.
ctx.finish_frame();
// swap buffers, fae_context.synchronize(), etc.
}This construct makes the state of fae more clear, as you can only have access to either the Context or the GraphicsContext, as well as providing a good synchronization point (start_frame) where the window’s state is passed to fae, ensuring that all rendering operations are done based on up-to-date information.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Context
pub fn new() -> Context
Creates a new GraphicsContext. See the Safety section.
§Safety
Basically everything in fae assumes that it can call OpenGL, so please ensure you have called something along the lines of:
unsafe { fae::gl::load_with(|symbol| context.get_proc_address(symbol) as *const _); }Before creating a Context.
The width, height and dpi_factor are only initial values; they
are updated in the call to
Context::start_frame().
Sourcepub fn is_legacy(&self) -> bool
pub fn is_legacy(&self) -> bool
Returns true when running in legacy mode (OpenGL 3.3+ optimizations off).
Sourcepub fn get_opengl_version(&self) -> &OpenGlVersion
pub fn get_opengl_version(&self) -> &OpenGlVersion
Returns the OpenGL version if it could be parsed.
Sourcepub fn synchronize(&mut self)
pub fn synchronize(&mut self)
Tries to ensure that all the commands queued in the GPU have been processed.
Call this after swap_buffers to ensure that everything after this happens only after the frame has been sent to the screen, but don’t trust this to actually work. Doing vsync properly with OpenGL is a mess, as far as I know.
Sourcepub fn start_frame(
&mut self,
width: f32,
height: f32,
dpi_factor: f32,
) -> GraphicsContext<'_>
pub fn start_frame( &mut self, width: f32, height: f32, dpi_factor: f32, ) -> GraphicsContext<'_>
Creates a GraphicsContext for this frame.
The parameters width and height are the dimensions of the
window, and dpi_factor is a multiplier, such that: width * dpi_factor is the window’s width in physical pixels, and
height * dpi_factor is the height in physical pixels.
Sourcepub fn render(
&mut self,
width: f32,
height: f32,
clear_color: (f32, f32, f32, f32),
)
pub fn render( &mut self, width: f32, height: f32, clear_color: (f32, f32, f32, f32), )
Renders the frame with the given width, height and
clear_color.
The clear_color is defined between 0.0 and 1.0, and the
components are (red, green, blue, alpha).
See
Context::start_frame
for more information on what width and height are,
specifically.
This should generally be called after
GraphicsContext::finish_frame,
but can also be used to redraw the previous frame.