00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00040 #include "CToxiGLRenderer.h"
00041
00042 #ifdef TOXITEA_GL
00043
00044 CToxiGLRenderer::CToxiGLRenderer()
00045 {
00046 }
00047
00048 CToxiGLRenderer::~CToxiGLRenderer()
00049 {
00050 }
00051
00053 void CToxiGLRenderer::sampleDrawScene()
00054 {
00055 glPushMatrix();
00056 glBegin(GL_TRIANGLES);
00057 glColor3f(1.0f,0.0f,0.0f);
00058 glVertex3f( 0.0f, 1.0f, 0.0f);
00059 glColor3f(0.0f,1.0f,0.0f);
00060 glVertex3f(-1.0f,-1.0f, 0.0f);
00061 glColor3f(0.0f,0.0f,1.0f);
00062 glVertex3f( 1.0f,-1.0f, 0.0f);
00063 glEnd();
00064 glPopMatrix();
00065 }
00066
00068 void CToxiGLRenderer::sampleInitScene()
00069 {
00070
00071 }
00072
00074 void CToxiGLRenderer::sampleResizeContext()
00075 {
00076 if(windowHeight==0) windowHeight=1;
00077 glViewport(0,0,windowWidth,windowHeight);
00078 glMatrixMode(GL_PROJECTION);
00079 glLoadIdentity();
00080 gluPerspective(viewportAngle,(GLfloat)windowWidth/(GLfloat)windowHeight,viewportClose,viewportFar);
00081 glMatrixMode(GL_MODELVIEW);
00082 glLoadIdentity();
00083 }
00084
00086 void CToxiGLRenderer::setupRenderer(int _width,int _height,int _bits)
00087 {
00088 this->windowWidth = _width;
00089 this->windowHeight = _height;
00090 this->windowBits = _bits;
00091 }
00092
00094 bool CToxiGLRenderer::createContext()
00095 {
00096 GLuint PixelFormat;
00097
00098 static PIXELFORMATDESCRIPTOR pfd=
00099 {
00100 sizeof(PIXELFORMATDESCRIPTOR),
00101 1,
00102 PFD_DRAW_TO_WINDOW |
00103 PFD_SUPPORT_OPENGL |
00104 PFD_DOUBLEBUFFER,
00105 PFD_TYPE_RGBA,
00106 windowBits,
00107 0, 0, 0, 0, 0, 0,
00108 0,
00109 0,
00110 0,
00111 0, 0, 0, 0,
00112 16,
00113 0,
00114 0,
00115 PFD_MAIN_PLANE,
00116 0,
00117 0, 0, 0
00118 };
00119
00120 if(!(hDC=GetDC(hWnd))) {
00121 MessageBox(NULL,REGISTER_DC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00122 return false;
00123 }
00124
00125 if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {
00126 MessageBox(NULL,REGISTER_PFD,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00127 return false;
00128 }
00129
00130 if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {;
00131 MessageBox(NULL,REGISTER_SET_PFD,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00132 return false;
00133 }
00134
00135 if(!(hRC=wglCreateContext(hDC))) {;
00136 MessageBox(NULL,REGISTER_RC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00137 return false;
00138 }
00139
00140 if(!wglMakeCurrent(hDC,hRC)) {
00141 MessageBox(NULL,REGISTER_SET_RC,ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00142 return false;
00143 }
00144
00145 ShowWindow(hWnd,SW_SHOW);
00146 SetForegroundWindow(hWnd);
00147 SetFocus(hWnd);
00148 resizeContext();
00149 return true;
00150 }
00151
00152
00154 bool CToxiGLRenderer::killContext()
00155 {
00156 if(hRC) {
00157 if (!wglMakeCurrent(NULL,NULL)) {
00158 MessageBox(NULL,RELEASE_DC_RC,ERROR_SHOT_TITLE,MB_OK | MB_ICONINFORMATION);
00159 hRC=NULL;
00160 return false;
00161 }
00162
00163 if (!wglDeleteContext(hRC)) {
00164 MessageBox(NULL,RELEASE_RC,ERROR_SHOT_TITLE,MB_OK | MB_ICONINFORMATION);
00165 hRC=NULL;
00166 return false;
00167 }
00168 return true;
00169 }
00170 return false;
00171 }
00172
00173
00174 void CToxiGLRenderer::swapBuffers()
00175 {
00176 SwapBuffers(hDC);
00177 }
00178
00180 int CToxiGLRenderer::getRendererType()
00181 {
00182 return this->rendererType;
00183 }
00184
00185 #endif