Sign in to follow this  
Makoy

newbie question IDirect3D9::CreateDevice Method

Recommended Posts

Hello I would like to ask which part of the code should I put HRESULT CreateDevice( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface ); should I put it in the winmain or in some classes? Can you guys give me an example in coding it the proper way? Thanks!

Share this post


Link to post
Share on other sites
Hi there Makoy.
This is a suggestion, if you look in the directx sdk folder there should be a file called tutorials:

WhatEverDrive:\DXSDK\Samples\C++\Direct3D\Tutorials

If you are just learning try them, they show how to set up a lot of the stuff. The vertices & matrices are probably the best ones to start with, you could do a click & copy of the whole files to your project folder & use them from there. (you might need to undo any read only attributes on th files).

To answer your quetion anyway, make a function called InitD3D or something and put that function in there, then call it after CreateWindow(..) in WinMain.

But really the layout is in those tutorials.


//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;

// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}

// Turn off culling, so we see the front and back of the triangle
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

// Turn off D3D lighting, since we are providing our own vertex colors
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

return S_OK;
}

Share this post


Link to post
Share on other sites
Yes! Thank you very much stevieboy. I've been trying to figure out some codes you've told me in the tutorials folder and I think it's cool to study those stuff. Thanks a lot for the suggestion and the piece of code. I really appreciate it. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this