c# - Spritebatch removing front faces of Cubes -


picture showing issue

not more can explain issue.

heres main draw method. if change the

controls.draw(spritebatch); spritebatch.end(); spritebatch.begin();  

to

controls.draw(spritebatch); spritebatch.end(); spritebatch.begin(spritesortmode.immediate, null, null, d, rs);  

the blocks draw perfectly, except no controls or text drawn on screen.

d = new depthstencilstate(); //class level d.depthbufferenable = true; d.depthbufferwriteenable = true;             graphicsdevice.depthstencilstate = d; rs = rasterizerstate.cullnone; graphicsdevice.rasterizerstate = rs;  protected override void draw(gametime gametime) {     graphicsdevice.clear(color.cyan);      // need on reach devices allow non 2^n textures     graphicsdevice.samplerstates[0] = samplerstate.linearclamp;      //spritebatch.begin(spritesortmode.immediate, null, null, d, rs);      if (gamestate == state.breakout)     {         wallblock.draw(camera);          if (firstblocks.count < 49)         {             foreach (block block in secondblocks)             {                block.draw(camera);             }         }          foreach (block block in firstblocks)         {             block.draw(camera);         }          ball.draw(graphicsdevice, camera.view, camera.projection, spritebatch);          spritebatch.begin(spritesortmode.immediate, null, null, d, rs);          controls.draw(spritebatch);         spritebatch.end();         spritebatch.begin();         if (ball.scoremultiplier <= 1)         {             spritebatch.drawstring(                        scorefont,                         "score: " +                         scorediff +                         "\n lives:" +                         ball.lives,                         new vector2(100, 10),                         color.black);         }         else         {             spritebatch.drawstring(                        scorefont,                         "score: " +                         scorediff +                         "x" +                         ball.scoremultiplier +                         " multiplier!" +                         "\n lives:"                         + ball.lives,                         new vector2(100, 10),                         color.black);         }         spritebatch.end();     } } 

it appears winding order of faces of boxes backwards. calling default spritebatch.begin() method resets device's cull mode cullcounterclockwiseface.

when change call this:

spritebatch.begin(spritesortmode.immediate, null, null, d, rs);  

...it's overriding default , setting device cullnone. don't need use spritesortmode.immediate, if boxes have wrong winding order need specify non-default rasterizerstate.

as why works on platforms not others, can't say. you've run fact all abstractions leaky. monogame implemented on top of opengl on platforms, what's going on under covers fundamentally different.

in general, when you're trying cross-platform, it's better specific you're doing—in case, manually specifying device states in spritebatch.begin()—because gives implementation more information you're trying accomplish.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -