ItsMods

Full Version: [xna 4]Rendering problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

i'm making a small game and i have a problem when i want to render a ground made with multiple cubes. see the images:
[Image: 2pjn.jpg]

and

[Image: cod6.jpg]

The 2 images are taken with different yaw.

When i render only one cube, all the faces are correctly rendered...
Someone has an idea about this problem?

Thank you for your help
You have problems with CullFace. (You see another object through other)
Google it.
Hello SailorMoon!

Thanks a lot for you help!
I'll check on google about CullFace!

thx a lot
hello,

I have found that i need to set

CSHARP Code
  1. RasterizerState stat = new RasterizerState();
  2. stat.CullMode = CullMode.CullCounterClockwiseFace;
  3. GraphicsDevice.RasterizerState = stat;


I tried to put it in maybe every functions in Game1.cs as Initialize, load, update, draw... nothing changed.

I also tried with 'CullMode.CullClockwiseFace' and 'CullMode.None' but i got the same result.

Maybe i'm wrong in an other part of the code...

I'll copy the only used things into a new empty project and i'll post the source code, maybe it will be simpler for you to see the error in my code than with my bad explenations.

Thx in advance for the time you take to read my posts.
Hi,

The new project is in attachment.
Thank you
(07-02-2013, 18:48)narkos Wrote: [ -> ]Hi,

The new project is in attachment.
Thank you

I think it's easier if you would post a screenshot.
I will post some code from my old XNA project there. Wait.

It won't work because you need to end cullface rendering.

I mean something like this

cullmode state set to show

your code ----

cull mode state set to hidden


The problem could be in SpriteBatch also.


EDIT:
Found it at old my old HDD Big Grin


First:
Code:
public static RasterizerState gRasterizerState;
        public static BlendState gBlendState;
        public static DepthStencilState gDepthStencilState;

Then initialize it:
Code:
gRasterizerState = new RasterizerState();
            gBlendState = new BlendState();
            gDepthStencilState = new DepthStencilState();

Render:
Code:
public static void RenderLevel(Vector3 cameraPosition, Matrix viewMatrix, Matrix projMatrix, uint gameTime, GraphicsDevice graphics)
        {
            // -------------
            // reset and set the rasterizer states
            gRasterizerState = new RasterizerState();
            gRasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
            gRasterizerState.FillMode = FillMode.Solid;

            Renderer.Device.RasterizerState = gRasterizerState;

            // reset the blend and depth states
            Renderer.Device.BlendState = BlendState.Opaque;

            // reset and set the depthstencil states
            gDepthStencilState = new DepthStencilState();
            gDepthStencilState.DepthBufferEnable = true;
            Renderer.Device.DepthStencilState = gDepthStencilState;
            // -------------
            YOUR CODE THERE


            // -------------
            gRasterizerState = new RasterizerState();
            gRasterizerState.FillMode = FillMode.Solid;
            Renderer.Device.RasterizerState = gRasterizerState;
            // -------------
        }


Also if it won't work, check it - there's good blog with useful stuff.
http://blogs.msdn.com/b/shawnhar/archive...o-4-0.aspx

Edit 3:

Oh yeah, as i see, in your code spritebatch.begin is before scene render... it can f*ck up your scene. Do something like this:

Code:
renderscene();

spritebatch.begin();
drawtext;
spritebatch.end();
Hello,

@surtek i posted screenshots in my first post.
@SailorMoon thx a lot for your help and the code!

You help me a lot! Thank you so much man!
I'll play with it tonight!
Again thx!
Awesome!
It works just great!!!!!!

Thx a lot!
(07-03-2013, 18:51)narkos Wrote: [ -> ]Awesome!
It works just great!!!!!!

Thx a lot!

Thanks for the answer.