Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Jul 2008
Offline Last Active Aug 26 2011 01:18 AM

Posts I've Made

In Topic: Text on top of everything

30 June 2011 - 11:40 PM

Hi I'm new to XNA and I'm just wondering what is the best way to draw 2D text on top a 3D scene. Is this something I can use SpriteFont for?

Basically in my main class there is a Draw method:

protected override void Draw(GameTime gameTime)

      spriteBatch.DrawString(spriteFont, "Hello world", new Vector2(0.0f, 0.0f), Color.Purple);


...but the text is behind my models. And the models are loaded with a ModelManager:DrawableGameComponent:

modelManager = new ModelManager(this);

which has its own Draw method, so its not like I can just render the text last....because there doesn't seem to be an ordering (that i can see in the code). I'm just looking for a simple solution, doesn't have to be superefficient. What is the best way to do this?

in order for text to be on top of everything, you must render everyrhing FIRST, only after that should you draw your text

In Topic: [DX11] GUI rendering

09 June 2011 - 12:26 AM

there is also anttweakbar http://www.antisphere.com/Wiki/tools:anttweakbar
it's free, has dx11 support and may be what u looking for

In Topic: [C++, DX11] How to get texture size?

02 June 2011 - 03:16 AM

Hello. I load my texture using this code:

D3DX11CreateTextureFromFileA(device, sFilename, 0, 0, &textureResource, 0);

	resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
	resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	resourceDesc.Texture2D.MostDetailedMip = 0;
	resourceDesc.Texture2D.MipLevels = -1;
	device->CreateShaderResourceView(textureResource, &resourceDesc, &shaderTextureResource);

But I can't seem figure how to get texture size/resolution which I need for interface rendering. Can anyone help please? Thank you in advance.

  • you have to query ID3D11Texture2D interface from shaderTextureResource,then you have to get description from it with GetDesc
  • if you don't want or don't know how to query, then u may just call GetDesc from textureResource, it will give you D3D11_TEXTURE2D_DESC structure with all the fields(w,h format e.t.c.) that you need
  • you can also call D3DX11GetImageInfoFromFile to retrieve information about the file

In Topic: D3D10 Index buffer sizes

08 April 2011 - 12:14 PM

the main perfomance problem is draw call and send call
->set matrix/texture
it might be very efficent to do this

select group of objects, that has same texture size
create texture2darray from them
create matrix array for them[for d3d10 you can see sampe in nvidia blendshapes example, or look at the forum, i posted the code long time ago][for d3d11 level 10 there it's called StructuredBuffer[you only need read only!, no need for UAV][i think you already doing similar stuff anyway]
somehow put them into single vertex and index buffer, can be done with d3dxmeshconcatenate i think

then in render:
set texture array
set matrix array[you can set it as shader buffer or as second stream]
*set array of indices of which mesh in that big array is visible[frustum culling][kill them in geometry shader+possibility of occlusion integration with HZB]
draw batch

that method will singificantly reduce draw calls for static geometry[since it can be preprpocessed]
for dynamic geometry you gonna be needing ->UpdateSubResource or Better ->Map with discard flag, but it might throttle bandwitdth

generall it's better to have less draw cals

p.s. with that frustum killing you might restructure you code, so your VS be passthorugh and GS actually executed VS only in case it was't frustum culled, but it's up to you, if you don't have lot's of polygos in frame u don't need it.

In Topic: D3D10 Index buffer sizes

08 April 2011 - 01:08 AM

there are 2 limitations on creating buffers[whatever they be invex/vertex/texture or just buffer]
  • IT MUST be aligned to 16, if it's not that creation will fail
  • for d3d10 the buffer ByteWidth or totalsize must be less then 128*1024*1024 aka 128MB
p.s. i'v tested with idea of putting entire mesh into big buffer, it will fit in most cases
you can improve perofmrnce by using texture2darray like texture atlas in d3d9 that will singificantly reduce draw calls
your send your world matrix much less, if you also put it into buffer, and index to it from shader or you can put it directly via vertex streams specifying flag per instance

you should do perfomance tests on your app, but in general reducing complexity of shaders and reducing draw calls is a good idea.