No problems
#1 Members - Reputation: 100
Posted 13 February 2011 - 06:56 PM
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);
}
#3 Members - Reputation: 293
Posted 14 February 2011 - 07:11 AM
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.
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
#4 Members - Reputation: 100
Posted 14 February 2011 - 08:10 AM
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.
#5 Members - Reputation: 293
Posted 14 February 2011 - 08:22 AM
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
#6 Members - Reputation: 100
Posted 15 February 2011 - 01:10 AM
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.
#7 Members - Reputation: 100
Posted 15 February 2011 - 06:57 AM
#8 Members - Reputation: 100
Posted 15 February 2011 - 08:31 AM
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;
}
#9 Moderators - Reputation: 422
Posted 23 February 2011 - 07:22 PM
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.
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
#10 Moderators - Reputation: 422
Posted 23 February 2011 - 07:26 PM
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.
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints






