Example #1
0
DDScreen::DDScreen(int w, int h, int bpp, const char *title) throw()
    :Window( title), DDrawWindow(title, w, h, bpp), _w(w), _h(h), _bpp(bpp)
{
    SetClipper( Rect( w, h));
    Clear(0L); Swap();
    SetClipper( Rect( w, h));
    Clear(0L); Swap();
}
Example #2
0
void DDScreen::Open(int w, int h, int bpp, float refresh)
{
    assert( refresh == 0 && "refresh rate is not implemented for DDraw7" );
    _bpp=bpp; _w=w; _h=h;
    if( FAILED( DDrawWindow::GetDisplay().CreateFullScreen( Window::GetHandle(), w, h, bpp ) ) )
    {
        DDScreen_ERROR( Useless::Error("DDrawDDScreen::Open() Mode %ix%ix%i is not supported",w,h,bpp) );
    }
    SetClipper( Rect( w, h));
    Clear(0L); Swap();
    SetClipper( Rect( w, h));
    Clear(0L); Swap();
}
Example #3
0
void DDScreen::OpenWindowed(int w, int h)
{
    _bpp=0; _w=w; _h=h;
    if( FAILED( DDrawWindow::GetDisplay().CreateWindowed( Window::GetHandle(), w, h ) ) )
    {
        DDScreen_ERROR( Useless::Error("DDrawDDScreen::Open() Mode %ix%i is not supported",w,h) );
    }
    Show();
    SetClipper( Rect( w, h));
    Clear(0L); Swap();
}
MyDrawEngine::MyDrawEngine(int width, int height, int bitsPerPixel, HWND hwnd, bool bFullScreen)
{
	HRESULT err;
	DWORD CoopLevel;

	//Hack - I reckon a boolean needs to be passed into GameInit() from wincode.cpp
	//which is then passed into the MyDrawEngine constructor, rather than an extern! - Dan
	mbFullScreen = bFullScreen;


	// Set attributes
	ZeroMemory(&ddsd, sizeof(ddsd));

	bytesPerPixel		= bitsPerPixel/8;
	lpBackBuffer		= NULL;
	lpPrimarySurface	= NULL;
	lpClipper			= NULL;
	memoryPitch			= 0;
	screenHeight		= height;
	screenWidth			= width;
	videoAddress		= NULL;
	mHwnd				= hwnd;

	//Configure cooperative mode flags
	if(mbFullScreen)
	{
		CoopLevel = DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT;
	}
	else
	{
		CoopLevel = DDSCL_NORMAL;
	}

	// to do: add defensive programming
	err=DirectDrawCreateEx(0,(void**)&lpdd,IID_IDirectDraw7,0);
	if (FAILED(err))
	{
		ErrorLogger::Writeln("Could not connect to IDirectDraw7");
		ErrorLogger::Writeln(ErrorString(err));
		lpdd=NULL;
		return;		// No point going any further
	}
	
	// set cooperation level 
	err=lpdd->SetCooperativeLevel(hwnd, CoopLevel);
	if (FAILED(err))
	{
		ErrorLogger::Writeln("Could not set cooperative level");
		ErrorLogger::Writeln(ErrorString(err));
		lpdd->Release();
		lpdd=NULL;
		return;		// No point going any further
	}

	// set display mode
	if( mbFullScreen )
	{
		err=lpdd->SetDisplayMode(width,height,bytesPerPixel*8,0,0);
		if (FAILED(err))
		{
			ErrorLogger::Writeln("Could not set display mode");
			ErrorLogger::Writeln(ErrorString(err));
			lpdd->Release();
			lpdd=NULL;
			return;		// No point going any further
		}
	}

	// Create the primary surface

	// First, make out an "order form" for the surface
	ZeroMemory(&ddsd, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	if( mbFullScreen )
	{
		ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
		ddsd.dwBackBufferCount = 1;
	}
	else
	{
		ddsd.dwFlags = DDSD_CAPS;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
	}

	// Now get the primarySurface
	
	err=lpdd->CreateSurface(&ddsd,&lpPrimarySurface,NULL);
	if(FAILED(err))
	{
		ErrorLogger::Writeln("Failed to create primary surface");
		ErrorLogger::Writeln(ErrorString(err));
		lpdd->Release();
		lpdd=NULL;
		return;		// No point going any further
	}

	// --- Now get the back buffer ---
	if(mbFullScreen)
	{
		// Generic surface capabilities struct
		DDSCAPS2 ddsCaps;

		//Clear it
		ZeroMemory(&ddsCaps, sizeof(ddsCaps));

		ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_FLIP;

		err=lpPrimarySurface->GetAttachedSurface(&ddsCaps,&lpBackBuffer);
	}
	else
	{
		DDSURFACEDESC2 desc;
		ZeroMemory(&desc, sizeof(DDSURFACEDESC2));

		desc.dwSize = sizeof(DDSURFACEDESC2);
		desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
		desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
		desc.dwWidth = width;
		desc.dwHeight = height;

		err = lpdd->CreateSurface(&desc, &lpBackBuffer, NULL);
	}


	if(FAILED(err))
	{
		ErrorLogger::Writeln("Failed to obtain back surface");
		ErrorLogger::Writeln(ErrorString(err));

		lpClipper->Release();
		lpPrimarySurface->Release();
		lpdd->Release();
		lpdd=NULL;

		return;		// No point going any further
	}

	//Create a clipper for the back buffer!

	tagRECT clipArea;
	clipArea.top	= 0;
	clipArea.left	= 0;
	clipArea.bottom	= height;
	clipArea.right	= width;

	// Set clipper for back buffer surface
	// Chris - this function should be made to be more generic,
	// so that it can be applied to any direct draw surface
    SetClipper(1, &clipArea);

	// clear primary and secondary surfaces
	ClearBackBuffer();
	Flip();
	ClearBackBuffer();
}