"Easy" 2D in Direct3D?

Started by
5 comments, last by Ilankt 20 years, 11 months ago
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]
How appropriate, you fight like a cow!
Advertisement
The easiest way is to call a DirectX7 DirectDraw function. I don''t really know in D3D. DrawPrimitive, perhaps?
http://edropple.com
I''m using DrawPrimitive but it''s not the problem...
the problem is the position that the D3D put''s the graphic (Center)
How appropriate, you fight like a cow!
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
ok, i will try this...
BTW, what is: D3DXMatrixOrthoOffCenterLH ?
How appropriate, you fight like a cow!
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
I got a question...
what is sprites?
are they 2D?
How appropriate, you fight like a cow!

This topic is closed to new replies.

Advertisement