Archived

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

Ilankt

"Easy" 2D in Direct3D?

Recommended Posts

Ilankt    229
i want to do a 2D game, and put all the graphics in screen cordinations (0,0=top left of screen) how? [edited by - ilankt on May 26, 2003 10:26:05 AM]

Share this post


Link to post
Share on other sites
EdR    117
The easiest way is to call a DirectX7 DirectDraw function. I don''t really know in D3D. DrawPrimitive, perhaps?

Share this post


Link to post
Share on other sites
Ilankt    229
I''m using DrawPrimitive but it''s not the problem...
the problem is the position that the D3D put''s the graphic (Center)

Share this post


Link to post
Share on other sites
Drazgal    368
Well assuming your are using ortho projection (and a LeftHand system i.e D3DXMatrixOrthoLH) for your projection matrix then the following world transformation will aloow you to use top left of the screen as 0,0

D3DXMatrixTranslation(&World,X - (ScreenWidth/2),(ScreenHeight/2) - Y,0);

Direct3DDevice->SetTransform( D3DTS_WORLD, &World);

or you can make your ortho projection as D3DXMatrixOrthoOffCenterLH

Deadpan Studios

Share this post


Link to post
Share on other sites
OklyDokly    122
Why not use transformed and lit vertices defined as follows:


  

#define VERTEXSHADER D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1

struct CUSTOMVERTEX
{
D3DXVECTOR4 p; // Vertex position

D3DCOLOR color; // Vertex color

float tu, tv; // Vertex texture coordinates

};



As far as I''m aware, p.x and p.y in this case are the screen coordinates.

p.z is the value to write to the Z-Buffer (between 0.0f and 1.0f), will be translated by Direct 3D

and p.w is the arbitrary w coordinate.

Just set up the vertex buffer as a CUSTOMVERTEX vertices as normal, using VERTEXSHADER as the Flexible Vertex Format Flags, and then you should be able to draw this as normal. Although, I''m not sure how matrix tranformations work for T&L buffer

Share this post


Link to post
Share on other sites