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

## Recommended Posts

I was trying to get a quad drawn on the screen and I'm pretty sure all the code is correct it's just nothing is displayed on the screen. Can anyone give me something like a checklist for drawing a quad on the screen so I can compare it to my code and see if anythings missing. thanks.

##### Share on other sites
I had these problems to in the beginning.

be sure that your modelview and projection matrices are correct.

that was the problem with me.

yooops

##### Share on other sites
What sort of quad? just an arbitrary planar quad in 3D-space, or the more common "Screen Aligned Quad" for doing 2D-in-3D work?

If you want examples, you need to specify what language (C++, VB6, C#..) and API version (8,9,10) you're using.

Jack

##### Share on other sites
Ok info:

I'm Using C++ API V.9 and it's for a 2D tile based game so 2D in 3D. Also while I'm here I was wondering if you could give me pointers as to how I could create large maps made up of seprate textured quads (Tiles)

##### Share on other sites
Are you making sure that the quad is in front of the camera?

##### Share on other sites
Yes, I've been following a tutorial on the net and it's still not showing up. Argh this is annoying.

##### Share on other sites
Aha I fixed it, I didn't realise you had to change SetVertexShader() to SetFVF in Direct3D9

##### Share on other sites
okay, for 2D in 3D then you can completely skip the 3D parts if you want. Theres some neat tricks to be had by using "pure 3D" for 2D graphics (like using the VS), but that's a whole different ball game [smile]

For 2D you'll need yourself a vertex type. Of particular importance is that it's defined with D3DFVF_XYZRHW or the POSITIONT vertex shader semantic:

struct TLVertex{    D3DXVECTOR4 p;   // <---- NOTE: *4* component vector, not 3.    DWORD c;    D3DXVECTOR2 t;};const DWORD FVF_TLVERTEX = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;

When it comes to constructing the geometry you can store it in a vertex buffer or system memory array. Vertex buffers are more efficient, but from a functional stand-point it makes little difference to getting it working.

Of particular interest is that the 'w' component of the position is set to 1.0f. Failing to do this is a good source of strange results [wink]

For simplicity I've skipped it in the following fragment, but you may also want to correct for the texel/pixel offsets (see "Directly mapping texels to pixels" in the SDK documentation).

TLVertex quad[] = {    { {lowX,  lowY,  0.0f, 1.0f}, D3DCOLOR_XRGB( r, g, b ), { 0.0f, 0.0f } },    { {HighX, lowY,  0.0f, 1.0f}, D3DCOLOR_XRGB( r, g, b ), { 1.0f, 0.0f } },    { {lowX,  highY, 0.0f, 1.0f}, D3DCOLOR_XRGB( r, g, b ), { 0.0f, 1.0f } },    { {HighX, highY, 0.0f, 1.0f}, D3DCOLOR_XRGB( r, g, b ), { 1.0f, 1.0f } }};

You can get some useful effects/techniques by changing the Z value between 0.0f and 1.0f, and you can also generate simple gradients by specifying different (r,g,b) colours at each vertex.

The vertex ordering is important. The above is a simple triangle-strip:

0 ---> 1      /     /    /   /  / /2 ---> 3

Pay attention to the "winding order" of the vertices. You can easily check this by setting the D3DRS_CULLMODE render state to D3DCULL_NONE. If your quads appear with that setting then you've got the vertex order wrong - trial and error in re-ordering is usually sufficient.

When it comes to rendering you need to configure the vertex format, data locations (index and/or vertex buffers), textures and any other appropriate render states.

Due to using a simple sysmem array previously, we'll skip the data locations as they're not relevant:

device->SetFVF( FVF_TLVERTEX );device->SetTexture( 0, your_texture_here );device->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, reinterpret_cast< void* >( data ), sizeof( TLVertex ) );

That should be it for a trivial implementation. There are a lot of things you can refine and improve upon, but the above code should work. I remember this stuff off the top of my head as I tend to use it whenever I'm writing any debug code into my applications [wink]

Which, if any, parts of the above don't you understand or is causing you problems.

hth
Jack

##### Share on other sites
Quote:
 Original post by Dom_152Aha I fixed it, I didn't realise you had to change SetVertexShader() to SetFVF in Direct3D9
[lol] Oh well, no need for my lengthy reply then...

Good to hear you got it sorted though!

Cheers,
Jack

##### Share on other sites
Thank's for the reply anyway, I'm sure it will come in useful later on.

1. 1
2. 2
JoeJ
20
3. 3
frob
19
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632204
• Total Posts
3004763

×