Jump to content
  • Advertisement
Sign in to follow this  
asafpolt

2d rendering

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm writing a game and can't figure out how to draw 2d to screen coordinates. I want to display the score and some other data on fixed screen coordinates. How do I do it? Thanks, Asaf Polturak, Israel.

Share this post


Link to post
Share on other sites
Advertisement
Hi theer asafpolt,
How are you doing buddy?

The Problem
Rendering 2D screen coordinates.

The Solution
The vertex format that you will use to create your vertices will be the D3DFVF_XYZRHW vertex format.

This will tell direct3d that you will be rendering screenspace coordinates.

e.g. CUSTOM_VERTEX using D3DFVF_XYZRHW

//your structure
struct CUSTOM_VERTEX
{
float x, y, z, rhw,
u, v;
enum
{
FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE
};
};
//creation of your vertex buffer and definition of your vertices
CUSTOM_VERTEX* pData;
CUSTOM_VERTEX data[] = {
//define your vertices here
}};
pDevice->CreateVertexBuffer(sizeof(CUSTOM_VERTEX) * 4, D3DUSAGE_WRITEONLY, CUSTOM_VERTEX::FVF, D3DPOOL_MANAGED, &pVB, NULL);
pVB->Lock(0, 0, (void**)&pData, 0);
memcpy(pData, data, sizeof(CUSTOM_VERTEX) * 4);
pVB->Unlock();

//how to render your vertices
pDevice->SetStreamSource(0, pVB, 0, sizeof(CUSTOM_VERTEX));
pDevice->SetFVF(CUSTOM_VERTEX::FVF);
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);



Then you will just define your vertices with 4 floats and a color for example...
Remember though that screen space coordinates relates to your window and the top left coordinates will be (0.0f, 0.0f, 0.0f) and the bottom right coordinates will be (window_width, window_height, 0.0f)

I hope this helps buddy.
Take care.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!