# Software Graphics Library

## Recommended Posts

EDI    3679
Greetings all, I am not sure this is the best place for it, but I put together a small 'general purpose' 2D Software Blitting library (which i am probabably going to use in the pure software adapter for Morning's Wrath, while I am sure 99.9% of the people out there won't find this useful, I have decided to make this code free to the general public with no restrictions. Use at your own risk, I am not responsible if somthing breaks or doesnt work right [grin] Note that the code is highly unoptimized, and was written in about three hours. The purpose of this library was to provide a pure software solution for a 2D, 32bit blitter. The code was written with intent of providing a software 'reference' adapter, which can be potentialy used for detecting improper rendering on Hardware Adapters, and maybe for 'safe mode' running of the game (no evil D3D lockups) it has the following function set:
SWGLColor SWGLMakeColor(Channel r,Channel g,Channel b,Channel a);
SWGLScissor SWGLMakeScissor(long x1,long y1,long x2,long y2);
SWGLImage* SWGLCreateImage(long width,long height);
void SWGLDestroyImage(SWGLImage* image);
void SWGLBlt(SWGLImage* di,long dx,long dy,long dw,long dh,SWGLImage* si,
long sx,long sy,long sw,long sh,SWGLColor blend,SWGLScissor* scissor);


most of these functions should be self explanatory, but I will explain two in detail. WTF is a Scissor? A scissor, is an object which must be supplied to a blitter, it is used to clip the destination output. This is very important, because if you blit outside of the destination memory area, you are in for trouble. A scissor's properties define the top left and bottom right of a scissor rectangle to which the output on the destination will be clipped. The blitter! The blitter is fairly feature rich, it supports: -Stretching/Shrinking -Source Constant Alpha -Source Per-Pixel Alpha -Source Color Modulation -Color Fill with Constant Alpha Here is an explanation of the parameters: SWGLImage* di - the destination image long dx - the destination x long dy - the destination y long dw - the destination width long dh - the destination height SWGLImage* si - the source image (if NULL a color fill is performed) long sx - the source x (must be in bounds(not scissored)) long sy - the source y (must be in bounds(not scissored)) long sw - the source width (must be in bounds(not scissored)) long sh - the source height (must be in bounds(not scissored)) SWGLColor blend - a color that controls constant alpha and modulation SWGLScissor* scissor - a scissor used to clip the output on the dest Here is it's variant operation: If si is an image: -blend's R G and B components denote modulation example; if R is 255 and G is 0 and B is 0, then output will show only 100% of the red channel. -blend's A component specifies constant alpha in the range of 0(transparent) to 255(opaque) If si is null: -blend's R G and B components are used as the color, for the color fill -blend's A component specifies constant alpha (for the color specified in blend) in the range of 0(transparent) to 255(opaque) Hopefully somone enjoys this =D Here are the files =) swgl.h swgl.cpp

##### Share on other sites
Rob Loach    1504
That's pretty cool, Raymond. Reminds me of SDL [smile].