\r
#include "app.h"\r
\r
+// d3d\r
static IDirect3D8 *Direct3D=NULL;\r
IDirect3DDevice8 *Device=NULL;\r
IDirect3DSurface8 *DirectBack=NULL; // Back Buffer\r
\r
static CustomVertex VertexList[4];\r
\r
+// ddraw\r
+#include <ddraw.h>\r
+\r
+LPDIRECTDRAW7 m_pDD;\r
+LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer;\r
+LPDIRECTDRAWSURFACE7 m_pddsBackBuffer;\r
+\r
+// quick and dirty stuff..\r
+static int DirectDrawInit()\r
+{\r
+ HRESULT ret;\r
+\r
+ ret = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ // Set cooperative level\r
+ ret = m_pDD->SetCooperativeLevel( FrameWnd, DDSCL_NORMAL );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ // Create the primary surface\r
+ DDSURFACEDESC2 ddsd;\r
+ ZeroMemory( &ddsd, sizeof( ddsd ) );\r
+ ddsd.dwSize = sizeof( ddsd );\r
+ ddsd.dwFlags = DDSD_CAPS;\r
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;\r
+\r
+ ret = m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer, NULL );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ // Create the backbuffer surface\r
+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; \r
+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;\r
+ ddsd.dwWidth = 320;\r
+ ddsd.dwHeight = 240;\r
+\r
+ ret = m_pDD->CreateSurface( &ddsd, &m_pddsBackBuffer, NULL );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ // clipper\r
+ LPDIRECTDRAWCLIPPER pcClipper = NULL;\r
+ ret = m_pDD->CreateClipper( 0, &pcClipper, NULL );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ ret = pcClipper->SetHWnd( 0, FrameWnd );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ ret = m_pddsFrontBuffer->SetClipper( pcClipper );\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ RELEASE(pcClipper);\r
+\r
+#if 0\r
+ DDSURFACEDESC2 sd;\r
+ memset(&sd, 0, sizeof(sd));\r
+ sd.dwSize = sizeof(sd);\r
+ ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+\r
+ memset(sd.lpSurface, 0xcc, 200*200);\r
+\r
+ ret = m_pddsBackBuffer->Unlock(NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+#else\r
+ DDBLTFX ddbltfx;\r
+ ZeroMemory( &ddbltfx, sizeof(ddbltfx) );\r
+ ddbltfx.dwSize = sizeof(ddbltfx);\r
+ ddbltfx.dwFillColor = 0xff00;\r
+\r
+ ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );\r
+#endif\r
+\r
+ ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+Sleep(2000);\r
+/* Sleep(500);\r
+ ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+ Sleep(500);\r
+ ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+ if (ret) { LOGFAIL(); return 1; }\r
+*/\r
+ return 0;\r
+}\r
+\r
+\r
int DirectInit()\r
{\r
D3DPRESENT_PARAMETERS d3dpp; \r
D3DDISPLAYMODE mode;\r
- D3DDEVTYPE dt = D3DDEVTYPE_HAL;\r
int i,u,ret=0;\r
\r
memset(&d3dpp,0,sizeof(d3dpp));\r
#endif\r
\r
// Try to create a device with hardware vertex processing:\r
- for (u=0;u<2;u++)\r
+ for (i=0;i<3;i++)\r
{\r
- for (i=0;i<4;i++)\r
- {\r
- int behave=D3DCREATE_HARDWARE_VERTEXPROCESSING;\r
+ int behave=D3DCREATE_HARDWARE_VERTEXPROCESSING;\r
\r
- // Try software vertex processing:\r
- if (i==1) behave=D3DCREATE_MIXED_VERTEXPROCESSING;\r
- if (i==2) behave=D3DCREATE_SOFTWARE_VERTEXPROCESSING;\r
+ // Try software vertex processing:\r
+ if (i==1) behave=D3DCREATE_MIXED_VERTEXPROCESSING;\r
+ if (i==2) behave=D3DCREATE_SOFTWARE_VERTEXPROCESSING;\r
\r
- Direct3D->CreateDevice(D3DADAPTER_DEFAULT,dt,FrameWnd,behave,&d3dpp,&Device);\r
- if (Device) break;\r
- }\r
+ Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,FrameWnd,\r
+ behave|D3DCREATE_MULTITHREADED,&d3dpp,&Device);\r
if (Device) break;\r
- dt = D3DDEVTYPE_REF;\r
}\r
\r
- if (Device==NULL) return 1;\r
+ if (Device==NULL)\r
+ {\r
+#if 0\r
+ // try ref\r
+ Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,FrameWnd,\r
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_MULTITHREADED,&d3dpp,&Device);\r
+ if (Device==NULL) goto fail0;\r
+ HMODULE test = LoadLibrary("d3d8d.dll");\r
+ if (test != NULL) FreeLibrary(test);\r
+ else {\r
+ error("Sorry, but this program requires Direct3D with hardware acceleration.\n\n"\r
+ "You can try using Direct3D software emulation, but you have to install "\r
+ "DirectX SDK for it to work\n(it seems to be missing now).");\r
+ goto fail1;\r
+ }\r
+#else\r
+ goto fail1;\r
+#endif\r
+ }\r
\r
Device->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&DirectBack);\r
- if (DirectBack==NULL) return 1;\r
+ if (DirectBack==NULL) goto fail1;\r
\r
Device->CreateVertexBuffer(sizeof(VertexList),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBuffer);\r
- if (VertexBuffer==NULL) return 1;\r
+ if (VertexBuffer==NULL) goto fail2;\r
\r
- ret=TexScreenInit(); if (ret) return 1;\r
+ ret=TexScreenInit(); if (ret) goto fail3;\r
\r
//FontInit();\r
\r
// Set up texture modes:\r
Device->SetTextureStageState(0,D3DTSS_ADDRESSU,D3DTADDRESS_CLAMP);\r
Device->SetTextureStageState(0,D3DTSS_ADDRESSV,D3DTADDRESS_CLAMP);\r
+\r
return 0;\r
+\r
+fail3:\r
+ RELEASE(VertexBuffer)\r
+fail2:\r
+ RELEASE(DirectBack)\r
+fail1:\r
+ RELEASE(Device)\r
+fail0:\r
+ RELEASE(Direct3D)\r
+\r
+ // error("Failed to use Direct3D, trying DirectDraw..");\r
+\r
+ // try DirectDraw\r
+ return DirectDrawInit();\r
}\r
\r
void DirectExit()\r
{\r
//FontExit();\r
- //TexScreenExit();\r
+ TexScreenExit();\r
\r
RELEASE(VertexBuffer)\r
RELEASE(DirectBack)\r
memcpy(lock,VertexList,sizeof(VertexList));\r
VertexBuffer->Unlock();\r
\r
+ ret=Device->BeginScene();\r
+ if (ret) dprintf2("BeginScene failed\n");\r
ret=Device->SetTexture(0,TexScreen);\r
if (ret) dprintf2("SetTexture failed\n");\r
ret=Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));\r
if (ret) dprintf2("SetVertexShader failed\n");\r
ret=Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);\r
if (ret) dprintf2("DrawPrimitive failed\n");\r
+ ret=Device->EndScene();\r
+ if (ret) dprintf2("EndScene failed\n");\r
\r
return 0;\r
}\r