#### Archived

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

# "Easy" 2D in Direct3D?

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

## Recommended Posts

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 on other sites
The easiest way is to call a DirectX7 DirectDraw function. I don''t really know in D3D. DrawPrimitive, perhaps?

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

##### Share on other sites
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

##### Share on other sites
ok, i will try this...
BTW, what is: D3DXMatrixOrthoOffCenterLH ?

##### Share on other sites
Why not use transformed and lit vertices defined as follows:

  #define VERTEXSHADER D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1struct 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 on other sites
I got a question...
what is sprites?
are they 2D?

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

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

• Total Topics
631442
• Total Posts
3000088
×