Sign in to follow this  
JuliusDegutis

DirectX 2d game

Recommended Posts

JuliusDegutis    377

Hello, after some time trying again to make something with directX 9, and what I chose is 2D game. For now making only basics of engine, which will help to me make a game. And writing here because need help about drawing objects. Now use LPD3DXSPRITE for painting. But get some "flickering" of moving object. Maybe anybody could say why I get it? Or maybe suggest better way to draw 2D.

 

Painting function:

void Sprite::Render( Texture2D texture, TinyEngine::Rectangle rectangle )
{
D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vPosition( rectangle.X(), rectangle.Y(), 0.0f );
RECT rect;
rect.left =0;
rect.right = 48;
rect.top=0;
rect.bottom=48;
_sprite->Draw( texture.Texture(),
&rect,
&vCenter,
&vPosition,
D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,0.80f) );
}

Texture loading function:

_fileName = fileName;
_width = width;
_height = height;
Vertex g_quadVertices[] =
{
{-1.0f, 1.0f, 0.0f,  0.0f,0.0f },
{ 1.0f, 1.0f, 0.0f,  1.0f,0.0f },
{-1.0f,-1.0f, 0.0f,  0.0f,1.0f },
{ 1.0f,-1.0f, 0.0f,  1.0f,1.0f }
};
D3DXIMAGE_INFO d3dxImageInfo;
D3DXCreateTextureFromFileEx( 
g_dxManager.GetDevice(),
fileName, //"Data//Images//first.png",
width, 
height,
1,  
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
&d3dxImageInfo,
NULL,
&_texture);
g_dxManager.GetDevice()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_dxManager.GetDevice()->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY, 
D3DFVF_XYZ | D3DFVF_TEX1, D3DPOOL_DEFAULT, 
&_vertexBuffer, NULL );
void *pVertices = NULL;
_vertexBuffer->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0);
memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices));
_vertexBuffer->Unlock();
}

And adding project exe to see what flickering I get smile.png

https://www.dropbox.com/s/kr5oketi74q0gu8/Release.7z

Share this post


Link to post
Share on other sites
Endurion    5408

I'd guess that the window client size doesn't match your backbuffer size. The actual client size is 784x602. From the actual window size (800x640) it looks like you tried for 800x600?

 

If it is so, your problem is nothing with DirectX but with your Win32. Try setting a RECT to your wanted client size, call AdjustWindowRect(Ex) on it and use the result RECT for your CreateWindow(Ex) call.

 

 

Also, your message loop seems borked. When I close the game window the program crashes.

Share this post


Link to post
Share on other sites
JuliusDegutis    377

Somehow it works, but now want to know how properly to do it. First I now use

_hwnd = CreateWindow("APPTITLE","APPTITLE",WS_OVERLAPPEDWINDOW,700,200,
SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hinstance,NULL);

and later I use

_parameters.BackBufferCount=1;
_parameters.BackBufferFormat =  D3DFMT_X8R8G8B8;
_parameters.BackBufferWidth = SCREEN_WIDTH;
_parameters.BackBufferHeight = SCREEN_HEIGHT;

What values I need set if I want see 800x600 client size?

Because now Rect make very big window in both screens

 

---

 

K, founded how to fix it and get what I want. Thanks for help :)

Edited by Plutonium

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this