2D "map" background with D3D

knotree

Newcomer
Hello,

My aim is the following: For short I want to be able to draw little textured squares representing units on a big map, this big map is only a big .bmp file. I do know how to to this with directDraw it is rather simple but this API is now deprecated and we decide to forget about this solution.

The problem for me is how to have a backgroung image ??? I known there are many solutions but i'am new to D3D so....

thanks for your help

K.
 
You need to look at "TL Quads" - or, more generally, transformed and lit geometry.

Verticies of the form: D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 are essentially 2D; so creating a triangle list or triangle strip of these verticies will serve your purpose.

A TL Quad with Z==1.0f will be drawn at the back of the screen, which is probably what you want for your background.

Setting the Z to intermediary values between 0.0f and 1.0f can be used to create imposters in a 3D scene.

hth
Jack
 
Ok thanks a lot,

It seems that it is quite time consumming to learn all that stuff since I'am new to D3D ! And I don't have so much time ;)

Maybe I should buy a already done 2D Graphic engin with simple primitives or going back to DirectDraw

K.
 
it is quite time consumming to learn all that stuff
It's the simplest stuff you'll do with Direct3D. If you intend on rolling your own engines in the future (as opposed to licencing) then it'll be worth the time and effort...

Code:
struct TLVERTEX
{
    D3DXVECTOR4 p;
    DWORD c;
    D3DXVECTOR2 t;
};

#define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;

//Code for creating the geometry:
if( SUCCEEDED( g_pDev->CreateVertexBuffer( sizeof( TLVERTEX ) * 4, 0, FVF_TLVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
    //we succeeded, fill it with useful stuff...
    TLVERTEX *pData;
    g_pVB->Lock( 0, 0, reinterpret_cast< void** >( &pData ), 0 );

    //manipulate pData as an array of 4 verticies:
    pData[0].p = D3DXVECTOR4( x, y, 1.0f, 1.0f );
    pData[0].c = D3DCOLOR_XRGB( 255, 255, 255 );
    pData[0].t = D3DXVECTOR2( u, v );
    //... and so on for the others ...

    g_pVB->Unlock( );
}

//Code for rendering the geometry:
g_pDev->SetFVF( FVF_TLVERTEX );
g_pDev->SetStreamSource( 0, g_pVB, 0, sizeof( TLVERTEX ) );
g_pDev->SetTexture( 0, ... );
g_pDev->DrawPrimitive( ... );

//Don't forget to clean up:
SAFE_RELEASE( g_pVB );

I wrote that off the top of my head in a few minutes... probably not character perfect, but I'm sure you can work with it. All 2D rendering pretty much follows the same pattern.

Hopefully you'll find the above code useful, and might well demonstrate to you that (at least this part of D3D) it isn't too hard.

Jack
 
Back
Top