Skip to content

First Look Graphics

Robert Campbell edited this page Oct 14, 2022 · 1 revision

Subsystem Overview

Ultraviolet’s Graphics subsystem is exposed through the IUltravioletGraphics interface, which you can retrieve an instance of by calling UltravioletContext.GetGraphics(). This interface allows you to change the state of the graphics device.

Check out the reference documentation for a complete run-down what what the IUltravioletGraphics interface is capable of. Here’s a brief overview of some of the important points.

Setting the render target can be done with the SetRenderTarget() method. The render target is exactly what it says on the tin—the buffer which is targeted by all of the Framework’s rendering commands. In other words, it’s the canvas on which the Framework draws. By default, the render target is the back buffer, but you can create off-screen buffers and set them as the current target with this method. Passing null here will return to the back buffer.

You can clear the screen to a given color using the Clear() method. Ultraviolet will do this for you at the beginning of each frame, but if you’re not a fan of cornflower blue, there’s nothing stopping you from calling it manually. You can also clear the depth and stencil buffers using this method.

You can set the viewport using the SetViewport() method. This allows you to define a sub-region of the screen in which rendering takes place. Using this method you can, for example, render two different scenes to two different parts of the screen.

You can change the device state using the SetBlendState(), SetDepthStencilState(), SetRasterizerState(), and SetSamplerState() methods. These states allow you to fine-tune how the graphics device renders geometry; check the reference documentation for details. Each state is analogous to the XNA device state of the same name.

Textures can be bound and unbound using the SetTexture(), UnbindTexture(), and UnbindTextures() methods. A texture must be bound to the device before it can be rendered.

The current geometry stream can be changed using the SetGeometryStream() method. The geometry stream is the source of vertices used by subsequent calls to the DrawPrimitives(), DrawIndexedPrimitives(), and DrawInstancedPrimitives() methods, all of which perform the task of rendering geometry to the screen.

Associated Resources

This list is not exhaustive, but should be enough to get you started. Check out the reference documentation for more information.

The Surface2D and Surface3D classes represent two-dimensional and three-dimensional surfaces, respectively. These classes are useful for performing image manipulation on the CPU. You can convert surfaces to textures using the CreateTexture() method.

The Texture2D and Texture3D classes represent two-dimensional and three-dimensional textures, which are similar to surfaces except that they live in GPU memory and therefore cannot be directly manipulated by your program code. Two-dimensional textures are generally used as images, while three-dimensional textures are more often used as lookup tables in shaders.

The RenderTarget2D class represents a two-dimensional render target. Each render target is a collection of RenderBuffer2D instances, each of which represents a particular kind of data: color, depth, stencil, etc. Once you’re done rendering to a render target, you can use its individual buffers as textures.

The GeometryStream class represents a source of vertex data, and can include one or more VertexBuffer and IndexBuffer resources. If you’re planning to update the contents of these buffers more than once, check out the DynamicVertexBuffer and DynamicIndexBuffer resources; they’re optimized for that scenario.

The Effect class represents a shader program, the combination of a vertex shader and a pixel/fragment shader. There Framework provides a simple built-in Effect implementation called BasicEffect, or you can define your own using GLSL.

The SpriteBatch class provides a straightforward interface for drawing 2D images and text. A collection of animated images is defined by the Sprite resource.

Clone this wiki locally