Hello,

could be that this is not the right thread for my question but hope,
somebody can help.
I want to use Direct3D9.0 in my Qt application.To test d3d I use sample code
from the sdk.
I can initialize all d3d elements and it seems all is ok. In my render
method I clear the background with blue color and use transformed vertexes
to draw a colored triangle - it is from the second d3d tutorial.
All I get is the blue background. I don't see the triangle anywhere.
I believe the problem is in the device initialization... here my code.

I hope somebody can help.

Thanks, Axel


Cwin3D_DX::Cwin3D_DX(QWidget* parent, const char* name, int cfgId)
: n3d::CrenderWin(), QWidget(parent,name),
pd3d(NULL), pd3dDev(NULL)
{
setFocusPolicy(ClickFocus);
setMouseTracking(true);
setBackgroundMode(NoBackground);

show();
initGraphics(Cvec2l(width(),height()));
}

void Cwin3D_DX::initGraphics(const Cvec2l& vp)
{ D3DDISPLAYMODE d3ddm;
D3DPRESENT_PARAMETERS d3dpp;

if (NULL == (pd3d = Direct3DCreate9(D3D_SDK_VERSION)))
return;
pd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.hDeviceWindow = winId();
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
// Create the D3DDevice
if (FAILED(pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
topLevelWidget()->winId(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dDev)))
return;
// Turn off culling
pd3dDev->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting
pd3dDev->SetRenderState( D3DRS_LIGHTING, FALSE );
// Turn on the zbuffer
pd3dDev->SetRenderState( D3DRS_ZENABLE, TRUE );
}


void Cwin3D_DX::_drwSceneBackground()
{
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color; // The vertex color
};

// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

// Initialize three vertices for rendering a triangle
CUSTOMVERTEX vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
};

pd3dDev->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f,
0 );
if (pd3dBackGrndVB == NULL)
{ // Create the vertex buffer. Here we are allocating enough memory
// (from the default pool) to hold all our 3 custom vertices. We also
// specify the FVF, so the vertex buffer knows what data it contains.
if (FAILED(pd3dDev->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT,
&pd3dBackGrndVB, NULL)))
return;
// Now we fill the vertex buffer. To do this, we need to Lock() the VB
to
// gain access to the vertices. This mechanism is required becuase
vertex
// buffers may be in device memory.
VOID* pVertices;
if (FAILED(pd3dBackGrndVB->Lock( 0, sizeof(vertices),
(void**)&pVertices, 0)))
return;
memcpy(pVertices, vertices, sizeof(vertices));
pd3dBackGrndVB->Unlock();
}
pd3dDev->SetStreamSource( 0, pd3dBackGrndVB, 0, sizeof(CUSTOMVERTEX));
pd3dDev->SetFVF(D3DFVF_CUSTOMVERTEX);
pd3dDev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
}