Author: Marek Biskup
        marbis@kki.net.pl

Released at 23.VIII.1999 somewhere on the net.

All files can be freely copied, modified and used in any productions,
but I would like to recieve an email if you use it in your programs
(if it's not a problem for you).


This file contains some description of the class cScreen.

Class cScreen is the simple class using DirectX, that can help 
you programming graphics under Windows. You don't need to know how DX 
works but you must know a bit about writing programs under Win if you want
do use this class. But don't worry. I've included some examples, that 
you don't need to understand (!). All you have to do is to put your code
into the main.cpp file (about the line number 60 - see main.cpp).

When building the program remember to link ddraw.lib !!
The project file for borland is included.


The body of the class looks like that below:

class cScreen {
public:
	cScreen(void);
	~cScreen(void);

	int init(HWND hMainWindow,int w = 320, int h = 200, int d = 8);
	int SetMode(int newwidth, int newheight, int newbpp);

	void print(char* cz,int x, int y);
	void TextColor(int r, int g, int b);
	void Background(int r, int g, int b);
	void SetPalette(void* f);

	void clear(void);
	int Flip(void);
	void* GetPointer(void);
	int FreePointer(void);
	int Pitch(void);
	BOOL Restore(void);

private:
	int lPitch;
	int width;
	int height;
	int bpp;			// bits per pixel
	int FillColor;
	int textcolor;

	IDirectDraw            *dd;
	IDirectDrawSurface     *FrontBuffer;
	IDirectDrawSurface     *BackBuffer;
	IDirectDrawPalette     *Palette;

	HFONT      				  AppFont;
};

It's an exact copy of file screen.h. You can also see full source
code of all the methods in file screen.cpp.


And what do the functions do?


1)  cScreen(void);

Constructor. 


2)  ~cScreen(void);

Destructor - frees the memory that the screen uses.


3)  int init(HWND hMainWindow,int w = 320, int h = 200, int d = 8);

You must call this function before calling others from this class.
hMainWindow is a handle to main window of the aplication. (see example).
w, h, d are: width, heigth and bits per pixel of the screen that 
you want to create. Default screen is 320x200x8. Functions returns 
FALSE (zero) if it cannot setup some DirectX constants or if it 
cannot setup required screen mode.


4)   int SetMode(int newwidth, int newheight, int newbpp);

Sets new screen mode. I hope you can make out what do the arguments mean.


5)   void print(char* cz,int x, int y);

Prints a string on the screen in the position (x, y).


6)   void TextColor(int r, int g, int b);

Sets new color (r,g,b) of the text that you write with function print.
Default color is yellow(255,255,60).


7)   void Background(int r, int g, int b);

Sets new background color. Default is black(0,0,0).


8)   void SetPalette(void* f);

Sets new palette (in 8bpp mode only). f is a pointer to the array
of 256*3 bytes that contains description of the colors: 
red0, green0, blue0,
red1, green1, blue1,
red2, green2, blue2 ... etc.


9)   void clear(void);

Clears the screen (or rather the back buffer) - fills the screen 
with color set by function Background.


10)   int Flip(void);

Flips the BackBuffer with the FrontBuffer. 


11)   void* GetPointer(void);

Returns the pointer to the screen memory. You can then acces 
the memory directly. After drawing, the Pointer MUST be freed with
function FreePointer!!


12)   int FreePointer(void);
Frees the pointer to the screen mamory (or rather indicates that the 
drawing was ended). After freeing the pointer you can call Flip
(and NOT before).


13)   int Pitch(void);

Distance, in bytes, to the start of next line of the screen memory.
(may be not equal the length of the line). If you want to set point (x,y)
in 320x200x8, do p[Pitch*y+x] = color, and do not do p[320*y+x] = color, 
becouse the second way may not work on all graphics cards.


14)   BOOL Restore(void);

If the screen was lost, it realocates the memory.
(f.e. if you press ALT+TAB - so that the windows if in the front).


---------------------------------------------------------------
What to read:

[1] Wojciech Jawor - "Principia silnika" (in Polish :)
[2] Microsoft - DirectX SDK

In fact most of the code was based on one of the two sources.
(My only work was to write this text :))

I hope this class will help you. If you like it or if you managed to 
use it somewhere, please send me an e-mail. 

Best wishes.



                    Marek Biskup
                    marbis@kki.net.pl


P.S. The example is pretty fast although it was written in pure C++
(no assembler inline!). If you'd like to make it faster you can assume
Pitch = 320 (but it's not fair) or/and rewrite the bump procedure in 
assembler. I think writing some parts of the cScreen class in assembler
is not neccesary, because it's function aren't called very ofted, and
mostly they just call some DirectX procedures.

