Archived

This topic is now archived and is closed to further replies.

Forcas

Getting started in D3D8

Recommended Posts

Forcas    181
Hey. I''m mostly interested in programming 2d games, but from what I can tell, D3D8 is the best way to make them in windows, because of alpha blending and image rotation. Anyway, I opened up the documentation, followed the tutorials, and ended up with this.
#define WIN32_LEAN_AND_MEAN
#include 
#include 
#include 

//Globals////////////////////////
HWND hwnd; 
MSG msg; 
BOOL Game = 1;
LPDIRECT3D8 lpd3d;
LPDIRECT3DDEVICE8 lpd3d_device;



LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "Project2";
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{
              
         
    WNDCLASSEX wincl;      

    
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;     
    wincl.style = CS_DBLCLKS;                
    wincl.cbSize = sizeof(WNDCLASSEX);

    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; 
    wincl.cbClsExtra = 0;                     
    wincl.cbWndExtra = 0;                     
    
    wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);

   
    if(!RegisterClassEx(&wincl)) return 0;

   
    hwnd = CreateWindowEx(
           0,                  
           szClassName,        
           "Project 2",         
           WS_POPUP,
           CW_USEDEFAULT,       
           CW_USEDEFAULT,      
           544,                 
           375,                 
           HWND_DESKTOP,        
           NULL,               
           hThisInstance,       
           NULL                
           );

   
    ShowWindow(hwnd, nFunsterStil);
 
	///Initialize Graphics /////
	if(FAILED(lpd3d = Direct3DCreate8(D3D_SDK_VERSION)))
		Game = 0;
	
	//Get Adaptor Display Mode
	D3DDISPLAYMODE d3ddm;

	if(FAILED(lpd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm)))
	   return 0;

	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed   = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = d3ddm.Format;

	if(FAILED(lpd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, 
                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &lpd3d_device)))
	{
		MessageBox(hwnd, "Couldn''t Create Device", "ashfasf", MB_OK);
								  return 0;
	}




	while(Game == 1)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			if(msg.message == WM_KEYDOWN)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
   }


	if(lpd3d_device)
		lpd3d_device->Release();
	if(lpd3d)
		lpd3d->Release();
   
    return msg.wParam;
}


LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)               
    {
           case WM_DESTROY:
           PostQuitMessage(0);        
           break;
           default:                   
           return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
 
I end up getting the "Couldn''t create device" error. I figure this has something to do with me switching to full-screen mode. How do I avoid this error message? -Forcas
"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."

Share this post


Link to post
Share on other sites
SikCiv    122
I recommend downloading the D3D8 Sprite wrapper from my site, it has all the code you need to blit in 2D and if u like, use it for your game or rip out the parts you need.

Your Video card may also be too old and not supported by DirectX8, which may be why you are getting that error.

Go to:

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
Forcas    181
bump

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Forcas    181
My video card is a GeForce plus. I''m pretty sure that isn''t too old.

-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
try completely filling out the D3DPRESENT_PARAMETERS structure.

Share this post


Link to post
Share on other sites