#if !defined(AFX_OPENGLBASE_H__A9B9268F_6034_4474_BD07_D33D73E79772__INCLUDED_)
#define AFX_OPENGLBASE_H__A9B9268F_6034_4474_BD07_D33D73E79772__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define CLASS_VERSION 1.00

#include <GL\gl.h>
#include <GL\glu.h>
#include <math.h>

//#if defined(PI)
  //#undef(PI)
//#else
  //#define PI 3.14159265358979323846
//#endif

#if defined(PI)
  #undef PI
  #define PI 3.14159265358979323846
#else
  #define PI 3.14159265358979323846
#endif


#if !defined(TWIDTH)
  #define TWIDTH 512
#endif

#if !defined(THEIGHT)
  #define THEIGHT 1024
#endif

#if defined(D2R)
  #undef(D2R)
#else
  #define D2R PI / 180.0
#endif

#if defined(R2D)
  #undef(R2D)
#else
  #define R2D 180.0 / PI
#endif

#if defined(limit)
  #undef(limit)
#else
  #define limit(x, lo, hi)  ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x)))
#endif

/*
#if defined(gl_setcolor)
  #undef(gl_setcolor)
#else
  #define gl_setcolor(c) glColor3b( ((c)>>1)&0x7F, ((c)>>9)&0x7F,((c)>>17)&0x7F)
#endif
*/

#if defined(gl_setcolor)
  #undef(gl_setcolor)
  #define gl_setcolor(c) glColor3b(((c)>>17)&0x7F, ((c)>>9)&0x7F, ((c)>>1)&0x7F)
#else
  #define gl_setcolor(c) glColor3b(((c)>>17)&0x7F, ((c)>>9)&0x7F, ((c)>>1)&0x7F)
#endif


#if defined(gl_line)
  #undef(gl_line)
#else
  #define gl_line(x1,y1,x2,y2) glBegin(GL_LINES), glVertex2d(x1,y1), glVertex2d(x2,y2), glEnd()
#endif


#if defined(gl_line3d)
  #undef(gl_line3d)
  #define gl_line3d(x1,y1,z1,x2,y2,z2) glBegin(GL_LINES), glVertex3d(x1,y1,z1), glVertex3d(x2,y2,z2), glEnd()
#else
  #define gl_line3d(x1,y1,z1,x2,y2,z2) glBegin(GL_LINES), glVertex3d(x1,y1,z1), glVertex3d(x2,y2,z2), glEnd()
#endif


#if defined(gl_dotted_line)
  #undef(gl_dotted_line)
#else
  #define gl_dotted_line(x1,y1,x2,y2) glLineStipple(4, 0xAAAA), glEnable(GL_LINE_STIPPLE), glBegin(GL_LINES), glVertex2d(x1,y1), glVertex2d(x2,y2), glEnd(), glDisable(GL_LINE_STIPPLE)
#endif


#if defined(gl_dotted_line3d)
  #undef(gl_dotted_line3d)
  #define gl_dotted_line3d(x1,y1,z1,x2,y2,z2) glLineStipple(4, 0xAAAA), glEnable(GL_LINE_STIPPLE), glBegin(GL_LINES), glVertex3d(x1,y1,z1), glVertex3d(x2,y2,z2), glEnd(), glDisable(GL_LINE_STIPPLE)
#else
  #define gl_dotted_line3d(x1,y1,z1,x2,y2,z2) glLineStipple(4, 0xAAAA), glEnable(GL_LINE_STIPPLE), glBegin(GL_LINES), glVertex3d(x1,y1,z1), glVertex3d(x2,y2,z2), glEnd(), glDisable(GL_LINE_STIPPLE)
#endif


#if defined(gl_putpixel)
  #undef(gl_putpixel)
#else
  #define gl_putpixel(x1,y1) glBegin(GL_POINTS), glVertex2d(x1,y1), glEnd()
#endif


#if defined(gl_putpixel3d)
  #undef(gl_putpixel3d)
  #define gl_putpixel3d(x1,y1,z1) glBegin(GL_POINTS), glVertex3d(x1,y1,z1), glEnd()
#else
  #define gl_putpixel3d(x1,y1,z1) glBegin(GL_POINTS), glVertex3d(x1,y1,z1), glEnd()
#endif



#define GLWHITE     0xFFFFFF
#define GLYELLOW    0xFFFF00
#define GLBROWN     0xFF8000
#define GLBLUE      0x0000FF
#define GLGREEN     0x00FF00
#define GLBLACK     0x000000
#define GLRED       0xFF0000
#define GLGRAY      0xC0C0C0
#define GLDARKGRAY  0x505050

#pragma comment(lib, "Opengl32.lib")
#pragma comment(lib, "Glu32.lib")

class COpenGLBase : public CWnd
{
// Construction
public:
	COpenGLBase();


                    DWORD           InitGL();                                             // Init OpenGL.
                    DWORD           CreateGLWindow();                                     // Create you wedge window.
					DWORD           CreateGLWindowSlave(HGLRC hRC);           // Create your "slave" OpenGL scenes. Shall be used for second OpenGL scene and so forth.

					DWORD           KillGLWindow();                                       // Kill / destroy you wedge window.

					DWORD           KillGLWindowSlave();                      // Kill / destroy your OpenGL scene created with CraateGLWindowSlave().
	                HGLRC           GetRC();                                  // Returns the RC for your thread. Remember, only one RC per thread.

                    void            glCircle(float x, float y, float r);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COpenGLBase)
	//}}AFX_VIRTUAL

// Implementation
public:
	
	virtual ~COpenGLBase();

	// Generated message map functions
protected:
	//{{AFX_MSG(COpenGLBase)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()


   virtual          DWORD           Render(BOOL flag) = 0;                                         // Render the image. Make sure to swap buffers after a complete render.

                    GLvoid          BuildFont();                                          // Build your wedge display font.
                    GLvoid          KillFont(GLvoid);                                     // Kill / destroy you wedge displau font.
                    GLvoid          glPrint(const char *fmt, ...);
                    float           glGetTextHeight();
	                float           glGetTextWidth(char *pText);
		  
		  virtual	DWORD           SetCurrentContext();

  	                
public:   virtual   DWORD           ResizeGL(int x, int y);

protected:

                    DWORD           m_bInit;                                              // True if window has fully initialized.

                    HGLRC		    m_hRC;							                                  // Permanent Rendering Context
                    HDC             m_hDC;

                    GLuint          m_fontBase;
                    int             m_iFontWidths[256];
                    float           m_fTextHeight;

					long            m_x;
                    long            m_y;

                   	DWORD           glSemiCircle(double x, double y, double r, double start, double stop);
                    DWORD           glSemiFilledCircle(double x, double y, double r, double start, double stop);

private:

                    DWORD           GetTextWidth(char * pText);

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_OPENGLBASE_H__A9B9268F_6034_4474_BD07_D33D73E79772__INCLUDED_)
