c# - How to make primitives correctly overlay sprites in DirectX (2D) -


i've got problem rendering sprites , primitives in direct3d9. i'm trying make simple 2d game using sprites, i've found out i'll need primitives draw simple squares, lines, etc. problem overlaying.

if draw primitives using device.drawuserprimitives(), fine, primitives rendered correctly. if draw sprites using sprite.draw(), it's fine. if want draw both sprites , primitives, sprites automatically overlays primitives or make them black.

i've tried disabling z buffer, disabling writing in z buffer while rendering sprites, etc. same. managed make primitives overlay sprites changing z position, primitives black... :(

note, please, i've tried rendering primitives both before , after drawing sprites. didn't help.

i'll post here snippets of drawing sprites , primitives (variable names changed understand i'm drawing if don't know c# , slimdx):

msprite.begin(spriteflags.objectspace | spriteflags.donotmodifyrenderstate); msprite.draw(texture, centervector, positionvector, color); // positionvector = vector3.zero in example msprite.flush();  (...)  device.vertexdeclaration = vertexdecl; device.drawuserprimitives(primitivetype.trianglefan, m_fan1.length - 2, m_fan1); 

...where m_fan1 structure containing vector4 position , int color , vertexdecl declares these vertex elements.

m_fan1[0] = new transformedcolored(new vector4(100.0f, 100.0f, 1.0f, 1.0f), color.green); m_fan1[1] = new transformedcolored(new vector4(0.0f, 0.0f, 1.0f, 1.0f), color.green); m_fan1[2] = new transformedcolored(new vector4(200.0f, 0.0f, 1.0f, 1.0f), color.green); m_fan1[3] = new transformedcolored(new vector4(200.0f, 200.0f, 1.0f, 1.0f), color.green); m_fan1[4] = new transformedcolored(new vector4(0.0f, 200.0f, 1.0f, 1.0f), color.yellow); m_fan1[5] = new transformedcolored(new vector4(0.0f, 0.0f, 1.0f, 1.0f), color.green); 

by way:

  1. if change fill mode wireframe, primitives' wireframes drawn correctly.
  2. if primitives overlay sprites, primitives almost black, , more sprites draw, darker primitives are. maybe has alpha?
  3. all primitives rendered correctly until draw sprite. if stop drawing sprites, primitives stay dark / black until reset application.

if need other snippets of source code, write here, please, , i'll update this.

i solved use of sprite.transform();

sprite.transform = matrix.scaling(1, 1, 1) * matrix.translation(x,y, 0); // works 

compared

sprite.transform = matrix.scaling(1, 1, 1) * matrix.translation(x,y, 1); // doesn't work 

i hope helps else encounters problem.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -