views:

334

answers:

2

I'm absolutely new to DirectX and I'd like to draw some untransformed primitives with the most basic Direct3D configuration (for learning purposes). I already drew some primitives with transformed vertices, that is vertices with the D3DFVF_XYZRHW flag set.

Now I'm trying to get the same output with untransformed vertices, but I don't get any visuals on the screen. I changed my FVF and adjusted the vertices but didn't set any transformation matrix (world, view, projection) yet. Is it necessary to set any of those matrices? I'd assume that everything would work just like with transformed vertices when no matrices are set, but obviously that's not the case.

What area (in world-coordinates) is visible by default? What do I have to do in order to make it work?

This is basically what I do:

struct Vertex
{
    float x, y, z;
    D3DCOLOR color;

    static const DWORD format = D3DFVF_XYZ | D3DFVF_DIFFUSE;
};


const Vertex vertices[] =  {
                           {0.0f, 0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)},
                           {0.8f, -0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)},
                           {-0.8f, -0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)}
                           };


pd3dDevice->CreateVertexBuffer(sizeof(vertices), 0, Vertex::format, D3DPOOL_DEFAULT, &pVB, NULL);

VOID* vertexData = 0;
pVB->Lock(0, sizeof(vertices), &vertexData, 0);
memcpy(vertexData, vertices, sizeof(vertices));
pVB->Unlock();



D3DMATRIX matrixIdentitiy;
ZeroMemory(&matrixIdentitiy, sizeof(matrixIdentitiy));
matrixIdentitiy._11 = 1.0f;
matrixIdentitiy._22 = 1.0f;
matrixIdentitiy._33 = 1.0f;
matrixIdentitiy._44 = 1.0f;

pd3dDevice->SetTransform(D3DTS_WORLD, &matrixIdentitiy);
pd3dDevice->SetTransform(D3DTS_VIEW, &matrixIdentitiy);
pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrixIdentitiy);



pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 0.0f, 0);
pd3dDevice->BeginScene();

pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pd3dDevice->SetRenderState(D3DRS_CLIPPING, FALSE);
pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS );

pd3dDevice->SetStreamSource(0, pVB, 0, sizeof(Vertex));
pd3dDevice->SetFVF(Vertex::format);
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

pd3dDevice->EndScene();
pd3dDevice->Present(NULL, NULL, NULL, NULL);

Thanks in advance!

EDIT: Now i got it, lighting was enabled, stupid beginner's mistake. Thanks for your help anyway!

A: 

Well if you set your world, view and projection matrices to identity then what you will get is a simple pass through.

x will range from -1 to 1
y will range from -1 to 1
z will range from 0 to 1 (This bit can cause problems).

If you then define standard untransformed verts and pass them on inside that range they will display on screen.

If that doesn't help post up some code and I'll see what i can suggest.

Edit: Have you got Z-Buffering enabled? Because you don't clear your Z-buffer which could cause odd issues. Everything will render behind this and hence will never render.

Set

pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS );

or

pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );

to test this hypothesis.

It is also very much worth learning how to use PIX and then seeing what happens to your triangle as it goes through the scene.

Edit2:

Its possible that your problem is coming from lighting. Try turning lighting off

ie

pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

Also try changing your Clear to this:

pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 0.0f, 0);

And check to see if your polys are rendering black.

Goz
Good point, I disabled the z-buffer test but the problem still remains.
Paul
A: 

This is basically what I do:

struct Vertex
{
    float x, y, z;
    D3DCOLOR color;

    static const DWORD format = D3DFVF_XYZ | D3DFVF_DIFFUSE;
};


const Vertex vertices[] =  {
                           {0.0f, 0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)},
                           {0.8f, -0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)},
                           {-0.8f, -0.8f, 0.5f, D3DCOLOR_XRGB(255, 255, 255)}
                           };


pd3dDevice->CreateVertexBuffer(sizeof(vertices), 0, Vertex::format, D3DPOOL_DEFAULT, &pVB, NULL);

VOID* vertexData = 0;
pVB->Lock(0, sizeof(vertices), &vertexData, 0);
memcpy(vertexData, vertices, sizeof(vertices));
pVB->Unlock();



D3DMATRIX matrixIdentitiy;
ZeroMemory(&matrixIdentitiy, sizeof(matrixIdentitiy));
matrixIdentitiy._11 = 1.0f;
matrixIdentitiy._22 = 1.0f;
matrixIdentitiy._33 = 1.0f;
matrixIdentitiy._44 = 1.0f;

pd3dDevice->SetTransform(D3DTS_WORLD, &matrixIdentitiy);
pd3dDevice->SetTransform(D3DTS_VIEW, &matrixIdentitiy);
pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrixIdentitiy);



pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 0.0f, 0);
pd3dDevice->BeginScene();

pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pd3dDevice->SetRenderState(D3DRS_CLIPPING, FALSE);

pd3dDevice->SetStreamSource(0, pVB, 0, sizeof(Vertex));
pd3dDevice->SetFVF(Vertex::format);
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

pd3dDevice->EndScene();
pd3dDevice->Present(NULL, NULL, NULL, NULL);
Paul
This is not an answer, it's part of the question! The text should be edited into the question, and the answer deleted.
unwind
Agreed, but there's no delete link.
Paul