Crate glium [−] [src]
Easy-to-use, high-level, OpenGL3+ wrapper.
Initialization
This library defines the DisplayBuild trait which is implemented on
glium::glutin::WindowBuilder.
Initialization is done by creating a WindowBuilder and calling build_glium.
extern crate glium; fn main() { use glium::DisplayBuild; let display = glium::glutin::WindowBuilder::new() .with_dimensions(1024, 768) .with_title(format!("Hello world")) .build_glium() .unwrap(); }
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 the window, and also provides some methods related to domains such as events handling.
Overview
OpenGL is similar to a 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 panicks 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.
Reexports
pub use draw_parameters::{BlendingFunction, LinearBlendingFactor, BackfaceCullingMode}; |
pub use draw_parameters::{DepthTest, PolygonMode, DrawParameters, StencilTest, StencilOperation}; |
pub use draw_parameters::{Smooth}; |
pub use vertex::{Vertex}; |
pub use program::{ProgramCreationError}; |
pub use program::ProgramCreationError::{CompilationError, LinkingError, ShaderTypeNotSupported}; |
pub use texture::{Texture, Texture2d}; |
Modules
| backend |
The |
| buffer |
A buffer is a memory location accessible to the video card. |
| debug | |
| draw_parameters |
Describes miscellaneous parameters to be used when drawing. |
| framebuffer |
Framebuffers allow you to customize the color, depth and stencil buffers you will draw on. |
| glutin | |
| index |
In order to draw, you need to provide a source of indices which is used to link the vertices together into primitives. |
| pixel_buffer |
Pixel buffers are buffers that contain two-dimensional texture data. |
| program | |
| 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 |
| vertex |
Contains everything related to vertex sources. |
Macros
| assert_no_gl_error! |
Calls the |
| implement_buffer_content! |
Implements the |
| implement_uniform_block! |
Implements the |
| implement_vertex! |
Implements the |
| program! |
Builds a program depending on the GLSL version supported by the backend. |
| uniform! |
Returns an implementation-defined type which implements the |
Structs
| BlitTarget |
Area of a surface in pixels. Similar to a |
| Frame |
Implementation of |
| IndexBuffer |
A list of indices loaded in the graphics card's memory. |
| LinearSyncFence |
Prototype for a |
| Program |
A combination of shaders linked together. |
| Rect |
Area of a surface in pixels. |
| SyncFence |
Provides a way to wait for a server-side operation to be finished. |
| Version |
Describes a version. |
| VertexBuffer |
A list of vertices loaded in the graphics card's memory. |
Enums
| Api |
Describes an OpenGL-related API. |
| DrawError |
Error that can happen while drawing. |
| GliumCreationError |
Error that can happen while creating a glium display. |
| Handle |
Handle to a shader or a program. |
| SwapBuffersError |
Error that can happen when swapping buffers. |
Traits
| CapabilitiesSource |
Trait for objects that describe the capabilities of an OpenGL backend. |
| DisplayBuild |
Objects that can build a facade object. |
| 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. |
Type Definitions
| Display |
The main object of this library. Controls the whole display. |
| VertexFormat |
Describes the layout of each vertex in a vertex buffer. |