Expand description
Easy-to-use, high-level, OpenGL3+ wrapper.
Glium is based on glutin - a cross-platform crate for building an OpenGL window and handling application events.
Glium provides a Display which uses glutin for the Window and its associated GL Context.
§Initialization
The initialisation of a simple glium display occurs in two steps.
extern crate glium;
// Use the re-exported winit dependency to avoid version mismatches.
// Requires the `simple_window_builder` feature.
use glium::winit;
fn main() {
// 1. The **winit::EventLoop** for handling events.
let event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
// 2. Create a glutin context and glium Display
let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
}The display object is the most important object of this library and is used when you build
buffers, textures, etc. and when you draw.
You can clone it and pass it around. However it doesn’t implement the Send and Sync traits,
meaning that you can’t pass it to another thread.
The display has ownership of both the window and context, and also provides some methods related to domains such as events handling.
§Overview
OpenGL is similar to drawing software: you draw something, then draw over it, then over it again, etc. until you are satisfied of the result.
Once you have a display, you can call let mut frame = display.draw(); to start drawing. This
frame object implements the Surface trait and provides some functions
such as clear_color, but also allows you to draw with the rendering pipeline.
In order to draw something, you will need to pass:
- A source of vertices (see the
vertexmodule) - A source of indices (see the
indexmodule) - A program that contains the shader that the GPU will execute (see the
programmodule) - A list of uniforms for the program (see the
uniformsmodule) - Draw parameters to customize the drawing process (see the
draw_parametersmodule)
Once you have finished drawing, you can call frame.finish() to swap buffers and present the
result to the user.
§OpenGL equivalents in glium
- Bind points: Glium automatically binds and unbinds buffers, textures, etc. in an optimized way.
- Buffers: Buffers are strongly typed and can be used through
vertex::VertexBuffer,index::IndexBufferoruniforms::UniformBuffer. - Debug output: If you compile in debug mode, glium registers a debug output callback and panics if an OpenGL error happens.
- Framebuffer Objects: FBOs are automatically managed by glium and are stored in the
Contextobject. You can specify the attachments that you wish with theframebuffermodule. - Instancing: Instancing is done either by passing a
vertex::EmptyInstanceAttributesmarker or one or several references to vertex buffers wrapped inside aPerInstancestruct. See thevertexmodule for more infos. - Memory barriers: Calling
glMemoryBarrieris automatically handled by glium, however you still need to callmemoryBarrier()in your GLSL code in some situations. - Programs: See the
programmodule. - Query objects: The corresponding structs are in the
draw_parametersmodule. They are passed as draw parameters. - Renderbuffer: See the
framebuffermodule. - Render to texture: If you just want to draw on a texture, you can call
texture.as_surface(). For more advanced options, see theframebuffermodule. - Samplers: Samplers are automatically managed by glium and are stored in the
Contextobject. You can specify how a texture should be sampled by using aSamplerdummy object in theuniformsmodule. - Shaders: You can’t manually create individual shaders. Instead you must create whole programs at once.
- Textures: Textures are strongly typed and are found in the
texturemodule. - Uniform blocks: If your program uses uniform blocks, you must pass a reference to a uniform buffer for the name of the block when drawing.
- Vertex array objects: VAOs are automatically managed by glium if the backend supports them.
Re-exports§
pub use crate::draw_parameters::Blend;pub use crate::draw_parameters::BlendingFunction;pub use crate::draw_parameters::LinearBlendingFactor;pub use crate::draw_parameters::BackfaceCullingMode;pub use crate::draw_parameters::Depth;pub use crate::draw_parameters::DepthTest;pub use crate::draw_parameters::PolygonMode;pub use crate::draw_parameters::DrawParameters;pub use crate::draw_parameters::StencilTest;pub use crate::draw_parameters::StencilOperation;pub use crate::draw_parameters::Smooth;pub use crate::index::IndexBuffer;pub use crate::vertex::VertexBuffer;pub use crate::vertex::Vertex;pub use crate::vertex::VertexFormat;pub use crate::program::Program;pub use crate::program::ProgramCreationError;pub use crate::program::ProgramCreationError::CompilationError;pub use crate::program::ProgramCreationError::LinkingError;pub use crate::program::ProgramCreationError::ShaderTypeNotSupported;pub use crate::texture::Texture2d;pub use crate::backend::glutin::Display;pub use crate::backend::glutin::glutin;pub use crate::backend::winit;
Modules§
- backend
- The
backendmodule allows one to link between glium and the OpenGL context.. - buffer
- A buffer is a memory location accessible to the video card.
- debug
- draw_
parameters - Describes miscellaneous parameters to be used when drawing.
- field
- Field utils
- framebuffer
- Framebuffers allow you to customize the color, depth and stencil buffers you will draw on.
- index
- In order to draw, you need to provide a way for the video card to know how to link primitives together.
- memory_
object - Contains everything related to external API memory objects.
- pixel_
buffer Deprecated - Moved to the
texturemodule. - program
- Items related to creating an OpenGL program.
- semaphore
- Contains everything related to external API semaphores.
- texture
- A texture is an image loaded in video memory, which can be sampled in your shaders.
- uniforms
- A uniform is a global variable in your program. In order to draw something, you will need to
give
gliumthe values of all your uniforms. Objects that implement theUniformtrait are here to do that. - vertex
- Contains everything related to vertex sources.
Macros§
- assert_
no_ gl_ error - Calls the
assert_no_errormethod on aglium::Displayinstance with file and line number information. - dynamic_
uniform - Returns a Dynamic Uniforms Container to which values can be added later.
- field
- A macro to create a
Field. - implement_
buffer_ content - Implements the
glium::buffer::Contenttrait for the given type. - implement_
uniform_ block - Implements the
glium::uniforms::UniformBlocktrait for the given type. - implement_
vertex - Implements the
glium::vertex::Vertextrait for the given type. - program
- Builds a program depending on the GLSL version supported by the backend.
- uniform
- Returns an implementation-defined type which implements the
Uniformtrait.
Structs§
- Blit
Mask - Mask specifying, which kinds of buffers to copy when blitting between two frame buffers.
- Blit
Target - Area of a surface in pixels. Similar to a
Rectexcept that dimensions can be negative. - Capabilities
- Represents the capabilities of the context.
- Extensions
List - Contains data about the list of extensions.
- Frame
- Implementation of
Surface, targeting the default framebuffer. - Incompatible
Open Gl - Returned during Context creation if the OpenGL implementation is too old.
- Linear
Sync Fence - Prototype for a
SyncFence. - Rect
- Area of a surface in pixels.
- Sync
Fence - Provides a way to wait for a server-side operation to be finished.
- Version
- Describes a version.
Enums§
- Api
- Describes an OpenGL-related API.
- Draw
Error - Error that can happen while drawing.
- Handle
- Handle to a shader or a program.
- Profile
- Describes the OpenGL context profile.
- RawUniform
Value - A raw value of a uniform. “Raw” means that it’s passed directly with
glUniform. Textures for example are just passed as integers. - Read
Error - Error that can happen while reading.
- Swap
Buffers Error - Error that can happen when swapping buffers.
- Uuid
Error - Describes an error preventing the retrieval of the uuid.
Traits§
- Capabilities
Source - Trait for objects that describe the capabilities of an OpenGL backend.
- GlObject
- Trait for objects that are OpenGL objects.
- Surface
- Object that can be drawn upon.
Functions§
- get_
supported_ glsl_ version - Given an API version, this function returns the GLSL version that the implementation is required to support.