Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

CToxiD3DRenderer.cpp

Go to the documentation of this file.
00001 
00009 /* 
00010         ---- Copyright (C) 2002  Jose Eduardo R. Mourão (eduardo_rdm@hotmail.com) ----
00011           
00012         This file is part of ToxiTea.
00013 
00014     ToxiTea is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 2 of the License, or
00017     (at your option) any later version.
00018 
00019     ToxiTea is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with ToxiTea; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 
00028         For more information and updates visit: 
00029         http://toxitea.sourceforge.net
00030         or mail to: eduardo_rdm@hotmail.com
00031 
00032         COMPILING AND/OR USING YOU ARE ACCEPTING ALL TERMS ABOVE.
00033         THIS LICENSE CAN BE CHANGED ANY TIME FOR ANY REASON WITHOUT NO COMMUNICATION.
00034 */
00035 
00040 #include "CToxiD3DRenderer.h"
00041 
00042 #ifdef TOXITEA_D3D
00043 
00044 CToxiD3DRenderer::CToxiD3DRenderer()
00045 {
00046 }
00047 
00048 CToxiD3DRenderer::~CToxiD3DRenderer()
00049 {
00050 }
00051 
00053 void CToxiD3DRenderer::setupRenderer(int _width,int _height,int _bits)
00054 {
00055         this->windowWidth       = _width;
00056         this->windowHeight      = _height;
00057         this->windowBits        = _bits;
00058 }
00059 
00061 bool CToxiD3DRenderer::createContext()
00062 {
00063         D3D8=Direct3DCreate8(D3D_SDK_VERSION);
00064         if(D3D8==NULL) 
00065                 return false;
00066 
00067         D3DDISPLAYMODE displayMode;
00068 
00069         if(_fullscreen!=true) {
00070                 D3D_hr=D3D8->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &displayMode); 
00071                 if(FAILED(D3D_hr)) 
00072                         return false;
00073         } 
00074         else {
00075                 displayMode.Width=windowWidth; 
00076                 displayMode.Height=windowHeight; 
00077                 displayMode.RefreshRate=0; 
00078                 displayMode.Format=D3DFMT_R5G6B5;
00079         }
00080 
00081         D3DPRESENT_PARAMETERS presentParameters; 
00082         memset(&presentParameters, 0, sizeof(D3DPRESENT_PARAMETERS));
00083 
00084         if (_fullscreen==false)  
00085                 presentParameters.Windowed   = TRUE; 
00086         else 
00087                 presentParameters.Windowed   = FALSE;
00088 
00089         presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; 
00090         presentParameters.BackBufferFormat = displayMode.Format;
00091         presentParameters.BackBufferWidth = displayMode.Width; 
00092         presentParameters.BackBufferHeight = displayMode.Height;
00093 
00094         D3D_hr=D3D8->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
00095                               D3DCREATE_SOFTWARE_VERTEXPROCESSING,
00096                               &presentParameters, &D3D8Device ); 
00097         if (FAILED(D3D_hr)) 
00098                 return false; 
00099 
00100         D3DXMATRIX mat;
00101         
00102         D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, windowWidth/windowHeight, 1.0, 100.0);
00103         D3D8Device->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mat);
00104 
00105         D3DXMatrixIdentity(&mat);
00106         D3D8Device->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);
00107 
00108         D3DXMatrixTranslation(&mat, 0, 0, 10.0);
00109         D3D8Device->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mat);
00110 
00111     D3D8Device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
00112 
00113         D3D8Device->SetRenderState( D3DRS_LIGHTING, FALSE );
00114 
00115         return true;
00116 }
00117 
00119 void CToxiD3DRenderer::resizeContext()
00120 {
00121                                                 
00122 }
00123 
00125 bool CToxiD3DRenderer::killContext()
00126 {
00127         if (D3D8Device)
00128                 D3D8Device->Release();
00129         D3D8Device=NULL;
00130 
00131         if (D3D8)
00132                 D3D8->Release();
00133         D3D8=NULL;
00134         return true;
00135 }
00136 
00138 void CToxiD3DRenderer::sampleDrawnScene()
00139 {
00140 }
00141 
00143 void CToxiD3DRenderer::sampleInitScene()
00144 {
00145 }
00146 
00148 void CToxiD3DRenderer::sampleResizeContext()
00149 {
00150 }
00151 
00152 
00165 void CToxiD3DRenderer::swapBuffers()
00166 {
00167 //      SwapBuffers(hDC);
00168         ValidateRect( hWnd, NULL );
00169 }
00170 
00172 int CToxiD3DRenderer::getRendererType()
00173 {       
00174         return this->rendererType;                                                              
00175 }
00176 
00177 #endif

Generated on Mon Sep 23 23:07:01 2002 for ToxiTea by doxygen1.2.18