Jump to content
  • Advertisement

Archived

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

coderx75

Need DirectX help... BADLY!

This topic is 6178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Peeps! I''ve just recently started gettin'' back into game programmin'' after about 5 years and I''m trying to get up to date on DirectX by converting all my old DOS code to Win32 with DX. I''ve recently bought "Beginning Direct3D Game Programming" from Prima Tech and a few months ago bought "Inside DirectX" & "Inside Direct3D". Now, knowing the landscapes of programming, I like to learn to walk before I try running but this approach isn''t working out. I want to convert my old code little by little, and learn the DirectX architecture along the way. I was hoping to be able to start by accessing the video thru DirectDraw but I am using DX8 which has done away with DDraw and doesn''t seem to be backwards compatible. Is this correct? I tried using the code from Andre LaMothe''s "Direct X-tasy" article but it won''t compile due to incompatible parameters to functions. The "Inside" books are based on DX5 which is seriously out-dated and Prima Tech''s game programming book deals with the common API. I don''t want to use the common API (I like doing things the hard way) and I don''t want to dive into Direct3D until I have successfully accessed the video (using my own 3D routines), DirectSound, DirectInput and DirectPlay. This seems like the best way to ease into things (for me anyway) but I can''t find any good reading on simply accessing the video thru DirectGraphics. Or... am I just mistaken and the out-dated samples should work?

Share this post


Link to post
Share on other sites
Advertisement
Hi!

Well, I''m not a DirectX guru. Trying to lurn that stuff myself

But it is FULLY bacward-compatible! You can use DirectX 1 functions if you like :D *don''t know why you would want that, but hey! it works anyway!*

Good luck!

}+TITANIUM+{

Share this post


Link to post
Share on other sites
I started with DX8, and decided that rather than use DX7 routines (DDraw), I would use DX8 for all my 2d graphics stuff, and its not too bad once you get used to it, just think of sprites as a textured 2d polygon.

Share this post


Link to post
Share on other sites
    
#define WIN32_LEAN_AND_MEAN
#include <d3d8.h>
#pragma comment(lib,"d3d8.lib")

#define ScreenWidth 1024
#define ScreenHeight 768
#define NUMBACKBUFFERS 2
#define InitdwSizeStru(stru) { ZeroMemory(&stru, sizeof(stru)); stru.dwSize = sizeof(stru); }
#define AppName "D3D8 App"


LRESULT CALLBACK MsgHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

LPDIRECT3D8 lpD3D8;
LPDIRECT3DDEVICE8 Tarjeta;
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DSURFACE8 BackBuffer;
D3DLOCKED_RECT BBrect;

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
HWND hWnd;
WNDCLASSEX wc;
MSG msg;

wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=MsgHandler;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance=hInst;
wc.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=AppName;
wc.cbSize=sizeof(WNDCLASSEX);
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc)) return 0;
if (!(hWnd=CreateWindowEx(0,AppName,AppName,WS_EX_TOPMOST | WS_POPUP,0,0,ScreenWidth, ScreenHeight,NULL,NULL,
hInst,NULL))) return 0;

ShowWindow(hWnd,nCmdShow);

lpD3D8=Direct3DCreate8(D3D_SDK_VERSION);
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.BackBufferWidth=ScreenWidth;
d3dpp.BackBufferHeight=ScreenHeight;
d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8; //32 bit color

//d3dpp.BackBufferFormat=D3DFMT_R5G6B5; //16 bit color

d3dpp.BackBufferCount=NUMBACKBUFFERS;
d3dpp.Windowed=FALSE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=hWnd;
d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

if (FAILED(lpD3D8->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&Tarjeta))) return 0;

ShowCursor(FALSE);

PeekMessage( &msg, NULL, 0, 0,PM_NOREMOVE);

while (msg.message!=WM_QUIT) {
if (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
//Tarjeta->Clear(0, NULL,D3DCLEAR_TARGET,0x00000000, 1.0f, 0);

Tarjeta->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&BackBuffer);
BackBuffer->LockRect(&BBrect,NULL,D3DLOCK_NOSYSLOCK);

/*Draw your stuff here, BBrect.pBits is a void pointer to the backbuffer,
BBrect.Pitch is a DWORD containing the offset (in bytes) from the beginning
of a scanline to the next one*/


BackBuffer->UnlockRect();
BackBuffer->Release();
Tarjeta->Present(NULL,NULL,NULL,NULL);
}}
return 0;
}

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ switch(message)
{
case WM_DESTROY:

Tarjeta->Release();
lpD3D8->Release();

PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}


There you go, sorry for the lack of comments and error checking.

------------------------------------------------------
Cuando miras al abismo el abismo te devuelve la mirada.
F. Nietzsche

Edit: cleaned a bit

Edited by - Abominacion on November 19, 2001 6:29:52 PM

Share this post


Link to post
Share on other sites
WOOHOO!!! Thanks guyz, I got it to work! I''m a DirectX programmer now! =) hehehehe, okay, down chubby =b

Gotta go, I''ve got games to write =)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!