Surfaces
From SDL.NET
This tutorial shows how to display graphics on the screen by using SDL.NET Surfaces. This tutorial assumes you've successfully completed the Hello World tutorial.
| Table of contents |
Introduction
Surfaces in SDL.NET represent graphical information, much like they do in SDL. You can create new surfaces from scratch or load them from different memory locations like from disk or from a data stream. All surfaces provide properties relative to its containing graphic like Width and Height. They also provide functionality to draw on the surface.
Functionality
These are some of the features of surfaces:
Blit
Fast blitting is the concept of drawing one surface onto another surface. In SDL.NET, the blit function draws the given surface onto the current surface. destinationSurface.Blit(sourceSurface) will draw the sourceSurface onto the destination surface at point 0,0. If you look at the SDL.NET documentation, you will notice a large amount of available functionality for blitting surfaces onto other surfaces.
// Draw the player onto the screen screen.Blit(player, playerLocation)
A common mistake of new SDL users is that they don't update the screen surface after blitting. This is required or the screen will not update with the new surface information and the changes will not be seen.
Primitive Drawing
SDL.NET uses SDL_gfx from primitive drawing on surfaces. This means that it has a large amount of functionality when it comes to being able to draw lines, circles, polygons, triangles, etc. All primitive drawing can be done with or without alpha transparency.
Color Keys, Transparency and Alpha Blending, Oh My!
Color keying is the act of stating which color the surface will treat as transparent when it blits onto a different surface. If you set the TransparentColor property of an SDL.NET surface, it will set that color as the transparent color and skip drawing it when blitting onto another surface.
// Set the color key to magenta surface.TransparentColor = System.Drawing.Color.Magenta; surface.Transparent = true;
This section is saved for discussion of alpha blending.
Collections
SurfaceCollections encapsulate a collection of surfaces in a surface list. This makes management of multiple surfaces extremely easy. Some of the benefits of using SurfaceCollections are that you can use dynamically load a number of surfaces at a time (tiled surfaces) and add and remove surfaces from the collection dynamically.

