1. #pragma once
  2. #include "CPInit.h"
  3.  
  4. #include <string>
  5. #include <iostream>
  6.  
  7. #ifdef USE_SDL 
  8.     #include "SDL/SDL.h"
  9.     #include "SDL/SDL_ttf.h"
  10.     #include "SDL/SDL_image.h"
  11.     #include "SDL/SDL_rotozoom.h"
  12.     #ifdef USE_OPENGL
  13.         #include "SDL/SDL_opengl.h"
  14.     #endif
  15. #else
  16.     #include <d3d9.h>
  17.     #include <d3dx9.h>
  18.     #include "dxgraphics.h"
  19. #endif
  20. #include "CPGraphicsTypes.h"
  21.  
  22. using namespace std;
  23.  
  24. #ifdef USE_SDL
  25. // utility function needed for SDL:
  26. bool IntersectCPRect( CPRECT& dest, const CPRECT src1, const CPRECT src2);
  27. #endif
  28.  
  29. class CPGraphicsEngine;
  30.  
  31. class CPTexture
  32. {
  33. public:
  34.     CPTexture();
  35.     ~CPTexture(void);
  36.  
  37.     friend class CPGraphicsEngine; // to allow it to get to the native texture...
  38.     bool LoadTextureFromFile(char* filename, CPCOLOR color, bool createDirectlyInVideoMemory); //true==surface, false==texture
  39.     bool CreatedInVideoMemory(); // checks if surface created. "return true;" in Linux.
  40.     bool CreateOffscreenTexture(int width, int height);
  41.  
  42. #ifdef USE_SDL
  43.     int GetWidth();
  44.     int GetHeight();
  45. #endif
  46.  
  47. private:
  48. #ifdef USE_SDL
  49.     SDL_Surface* m_nativeSurface;
  50.  
  51.     #ifdef USE_OPENGL
  52.     // OpenGL support
  53.     GLenum texture_format;
  54.     GLint  nOfColors;
  55.     #endif
  56.  
  57.     static SDL_Surface* CreateDisplayFormatSurface(int width, int height);
  58. #else
  59.     LPDIRECT3DTEXTURE9 m_nativeTexture;
  60.     LPDIRECT3DSURFACE9 m_nativeSurface;
  61. #endif
  62.  
  63.     long GetNativeTexture();
  64.     bool isSurface;
  65. };
  66.  
  67. class CPGraphicsEngine
  68. {
  69. public:
  70.     CPGraphicsEngine(void);
  71.     ~CPGraphicsEngine(void);
  72.  
  73.     bool Init_Graphics( long windowPointer /*hwnd*/, int width, int height, int fullscreen );
  74.     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 );
  75.     void DrawStretchTexture( CPTexture& texture, CPRECT sourceRect, CPRECT destRect );
  76.     void DrawTextToRect( std::string text, CPRECT rect, CPCOLOR color );
  77.  
  78.     bool StartFrame();
  79.     void EndFrame();
  80.  
  81.  
  82. private:
  83.     bool m_initialized;     // is object initialized?
  84.     int m_screenWidth;
  85.     int m_screenHeight;
  86.     bool m_inFrame;         // is a frame started?
  87. #ifdef USE_SDL
  88.     SDL_Surface* m_screen;  // screen surface
  89.     TTF_Font* m_font;       // font
  90. #else
  91.     LPD3DXSPRITE m_spriteHandler;   // sprite drawing object
  92.     LPD3DXFONT m_font;              // font
  93. #endif
  94. };
  95.  
  96. #ifdef USE_OPENGL
  97. bool init_GL(int width, int height, int fullscreen);
  98. #endif