#pragma once
#include "CPInit.h"
#include <string>
#include <iostream>
#ifdef USE_SDL
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_rotozoom.h"
#ifdef USE_OPENGL
#include "SDL/SDL_opengl.h"
#endif
#else
#include <d3d9.h>
#include <d3dx9.h>
#include "dxgraphics.h"
#endif
#include "CPGraphicsTypes.h"
using namespace std;
#ifdef USE_SDL
// utility function needed for SDL:
bool IntersectCPRect( CPRECT& dest, const CPRECT src1, const CPRECT src2);
#endif
class CPGraphicsEngine;
class CPTexture
{
public:
CPTexture();
~CPTexture(void);
friend class CPGraphicsEngine; // to allow it to get to the native texture...
bool LoadTextureFromFile(char* filename, CPCOLOR color, bool createDirectlyInVideoMemory); //true==surface, false==texture
bool CreatedInVideoMemory(); // checks if surface created. "return true;" in Linux.
bool CreateOffscreenTexture(int width, int height);
#ifdef USE_SDL
int GetWidth();
int GetHeight();
#endif
private:
#ifdef USE_SDL
SDL_Surface* m_nativeSurface;
#ifdef USE_OPENGL
// OpenGL support
GLenum texture_format;
GLint nOfColors;
#endif
static SDL_Surface* CreateDisplayFormatSurface(int width, int height);
#else
LPDIRECT3DTEXTURE9 m_nativeTexture;
LPDIRECT3DSURFACE9 m_nativeSurface;
#endif
long GetNativeTexture();
bool isSurface;
};
class CPGraphicsEngine
{
public:
CPGraphicsEngine(void);
~CPGraphicsEngine(void);
bool Init_Graphics( long windowPointer /*hwnd*/, int width, int height, int fullscreen );
void DrawTexture( float x, float y, int width, int height, float sx, float sy, float angle, unsigned char alpha, CPTexture& texture, CPRECT *rc, bool FixAngle );
void DrawStretchTexture( CPTexture& texture, CPRECT sourceRect, CPRECT destRect );
void DrawTextToRect( std::string text, CPRECT rect, CPCOLOR color );
bool StartFrame();
void EndFrame();
private:
bool m_initialized; // is object initialized?
int m_screenWidth;
int m_screenHeight;
bool m_inFrame; // is a frame started?
#ifdef USE_SDL
SDL_Surface* m_screen; // screen surface
TTF_Font* m_font; // font
#else
LPD3DXSPRITE m_spriteHandler; // sprite drawing object
LPD3DXFONT m_font; // font
#endif
};
#ifdef USE_OPENGL
bool init_GL(int width, int height, int fullscreen);
#endif