Programming Basic Concepts

Assemblies

.NET programs consist of a number of assemlies, the .NET specific term for compilation units. SharpGfx itself is split up into the following assemlies:
  • SharpGfx is the core abstraction.
  • SharpGfx.OpenGL is the abstract OpenGL implementation.
  • SharpGfx.OpenGL.OpenTK is the OpenGL implementation using the OpenTK, which is a bare OpenGL API for C#.
  • SharpGfx.OpenGL.Native is the OpenGL implementation using a minimal bare OpenGL API written in C++ being part of this library.
All conepts you need to know are defined in the SharpGfx assembly. In your project, reference the SharpGfx.OpenGL.OpenTK package to get the implementation. SharpGfx.OpenGL.Native serves for educational purposes and as backup should there be any problems with the OpenTK graphics library. GlslParser is used by the SharpGfx.OpenGL assembly transparent to the programmer.

Composition of 3D Graphics

3D graphic programs model a scene consisting of objects and a camera having a point shape. A coordinate system represents the virtual space of the scene. Objects and the camera can be freely placed, rotated and scaled in this system. The base class for cameras is not surprisingly Camera. The objects are visualized from the perspective of the camera. The base class for visualizations is Rendering. A rendering has a property Scene containig a collection of objects and separately a property Camera. Cameras perform either a perspective or an orthographic projection having base class Projection.
Objects have a geometry represented by classes implementing the IGeometry interface. SharpGfx only supports triangle meshes. SharpGfx supports both the index-based triangle/vertex and the plane vertex list OpenGL triangle mesh formats.
The color and brightness of objects in a rendering is determined by their material (base class Material) and light sources (base class Light). A term in computer graphics, e.g. used in the OpenGL context, for the combination of these two aspects is shading. Also in SharpGfx these two aspects are combined with classes implementing the IShading interface. Using SharpGfx.OpenGL shading can also be defined using the OpenGL low-level programming languge GLSL.
Object geometry and shading together define the surface base class Surface of a particular type object defining all its aspects for visialization.
Finally, a particular type of object can appear at different positions in the virtual world, each represented by an object of with base class Visual. Each visual must be added to the Scene property of the rendering to be visible.

2D Graphics

SharpGfx also supports 2D graphics using a subset of the concepts. There is however less emphasis on this possibility. Consult the API documentation and tutorials for details.

Graphic Pipeline dependent and independent Programming

This text understands the term graphic pipline as the particular combination of API implementation, graphic driver and hardware.
SharpGfx is designed to support graphic pipeline independent programming. This leaves open the opportunity to effortlessly switch to new pipelines. This can be achieved by using the library only through the classes and interfaces of the SharpGfx assembly. The new programming constructs requires a non-abstract type and is thus inherently pipeline dependent. Pipeline independent objects can be created through SharpGfx.Grapic that is the central API class.
Parts of a program directly using a platform dependent assembly of the library become platform dependent themselves.

Initializing and Displaying Graphics

Initializing and displaying graphics can be achieved by the following steps.
  • Choose a particuar pipeline by using to the corresponding assembly implementing it.
  • Create an instance of Graphic from the assembly.
  • Create a Camera.
  • Create a Rendering.
  • Create a Window from an assembly that provides access to a graphic device.
  • Show the rendering in the window.