Well i managed to get through chapter 5 on XNA 4.0 on my own without to much trouble. The hardest part was setting the cull mode to none (which dosnt really affect things just lets you see your squares from all angles). if anyone is having trouble i might be able to share some insite.
the cull mode secret is to set the graphics device Rasterizer State in the "Draw" section before you do anything else. here is my draw section at the end of chapter 5
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
DrawScene(gameTime, camera);
base.Draw(gameTime);
}
No problems
Only issue I had was very slow mouse view movement when verticle sync was disabled in the FPS component. With vsync on though, the mouse view moved normally.
The cull mode setting is an important optimization, setting it to none for all objects to be rendered will end up in drawing almost twice the number of pixels needed to represent a scene, why is this? cull mode off means that you can see objects inside out, which in almost all cases is not true, for solid objects this would result in the back of the object (from the camera's perspective) being rendered only to then be overwritten by the front part, which is a waste.
Cull mode off is useful to render translucent objects, when rendering a glass, you can see the back of the object through the front, the front doesn't fully overwrite the back and is not a waste of resources, it is also useful for billboard objects or paper thin objects such as the leaf of a tree, for almost any other case, cull mode should be set to either clock or counterclockwise.
Cull mode off is useful to render translucent objects, when rendering a glass, you can see the back of the object through the front, the front doesn't fully overwrite the back and is not a waste of resources, it is also useful for billboard objects or paper thin objects such as the leaf of a tree, for almost any other case, cull mode should be set to either clock or counterclockwise.
I understand the idea of culling, although in the book it asks us to set it to none as we have drawn so few squares in our world its important we see them. all our hard work and such.
Also i believe this is the only thing that has changed with XNA 4.0 in this chapter. People may want to know how to set the cull mode in future (changing it from anti Clockwise to Clockwise and such) this is why i posted my code as It took me a touch of time to find out how to set cull mode without getting a "NullReferance Error" from the debugger as is what happens when you follow it from the book.
Also i believe this is the only thing that has changed with XNA 4.0 in this chapter. People may want to know how to set the cull mode in future (changing it from anti Clockwise to Clockwise and such) this is why i posted my code as It took me a touch of time to find out how to set cull mode without getting a "NullReferance Error" from the debugger as is what happens when you follow it from the book.
Took a bit of screwing round with cullmode for me too. My code is:
Yours seems like a more elegant way of doing it though. Although i only set the cullmode once at the start because i thought there may have been a slight performance impact setting it every draw call.
protected override void Initialize()
{
RasterizerState temp = new RasterizerState();
temp.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = temp;
base.Initialize();
}
Yours seems like a more elegant way of doing it though. Although i only set the cullmode once at the start because i thought there may have been a slight performance impact setting it every draw call.
Ahh the Initialize method, i never thought to set the RasterizerState there. I kept trying to set the raster state just after creating the graphics manager in the constructor, kept getting Null Referance errors then. never occurred to me to change the state in the initialize method. Thanks
Guys. Please, use the base.metod() FIRST in the new method.
That is, first initialize the base, and only then do your code. Otherwise you might end up with a lot of errors (especially NullReference Exception).
So, in Dace's code, it should be:
That is, first initialize the base, and only then do your code. Otherwise you might end up with a lot of errors (especially NullReference Exception).
So, in Dace's code, it should be:
protected override void Initialize()
{
base.Initialize();
RasterizerState temp = new RasterizerState();
temp.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = temp;
}
Guys. Please, use the base.metod() FIRST in the new method.
That is, first initialize the base, and only then do your code. Otherwise you might end up with a lot of errors (especially NullReference Exception).
So, in Dace's code, it should be:
protected override void Initialize()
{
base.Initialize();
RasterizerState temp = new RasterizerState();
temp.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = temp;
}
Where you call base.Initialize() depends on whether you need your content loaded or not before you initialize your game. base.Initialize() is what ultimately calls your LoadContent function. So if you try and initialize your game by setting textures, etc... before calling base.Initialize() then indeed, you'll end up with null reference exceptions. However, it's perfectly acceptable to put the call to base.Initialize() after other initialization code if it does not depend on loaded assets.
Regarding the discussion on CullMode....
The CullMode is used to determine whether or not you want to render back facing triangles. In most 3D games, in most instances, you do not want CullMode set to None, as this would result in potentially twice as many triangles being drawn when all the "internal" triangles are being drawn. Think about a box for a moment. Each surface is made up of two triangles, but those triangles exist on both the inside and outside of the box. There's no reason to draw the ones that are on the "inside" as they will ultimately be covered up by the exterior surface of the other side of the object.
However, in this project there is no "other side". Because all of the 3D "objects" are primitives, without any depth, if you do not set CullMode to none, then when you walk around the back side of the little doorway thingies they'll disappear.
The CullMode is used to determine whether or not you want to render back facing triangles. In most 3D games, in most instances, you do not want CullMode set to None, as this would result in potentially twice as many triangles being drawn when all the "internal" triangles are being drawn. Think about a box for a moment. Each surface is made up of two triangles, but those triangles exist on both the inside and outside of the box. There's no reason to draw the ones that are on the "inside" as they will ultimately be covered up by the exterior surface of the other side of the object.
However, in this project there is no "other side". Because all of the 3D "objects" are primitives, without any depth, if you do not set CullMode to none, then when you walk around the back side of the little doorway thingies they'll disappear.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement