"Easy" 2D in Direct3D?
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]
The easiest way is to call a DirectX7 DirectDraw function. I don''t really know in D3D. DrawPrimitive, perhaps?
I''m using DrawPrimitive but it''s not the problem...
the problem is the position that the D3D put''s the graphic (Center)
the problem is the position that the D3D put''s the graphic (Center)
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
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
Why not use transformed and lit vertices defined as follows:
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
#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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement