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 "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
00168 ValidateRect( hWnd, NULL );
00169 }
00170
00172 int CToxiD3DRenderer::getRendererType()
00173 {
00174 return this->rendererType;
00175 }
00176
00177 #endif