Jump to content

  • Log In with Google      Sign In   
  • Create Account

broady

Member Since 23 Aug 2007
Offline Last Active Private

Topics I've Started

Generally in a phone interview....

10 August 2011 - 11:26 AM

what are they going to ask? Technical stuff too? This is my first interview. I applyed for programming/testing (an informal mail) so have no idea even about topics we are going to speak.

Thanks

XNA draw order and z-buffer

04 August 2011 - 06:44 AM

hi,
i am working on 3d pong and i am facing lots of issues about drawning order when you have alpha models (with model i mean even something drawned with drawuserprimitive), lets's say even objects.

1) After testing a lot i realized this: if you draw first the most far model and last the most near model you are ok. Always. (z-buffer must be enabled and blendstate must be blendstate for transparency)

2) If your obects are ALL opaque the drawning order doesn't matter. Probably it's better to draw first the most near models for performance. (z-buffer must be enabled)


Today i was reading hargreaves article at http://blogs.msdn.com/b/shawnhar/archive/2009/02/18/depth-sorting-alpha-blended-objects.aspx .
In 2 words he tells: if you don't want to care about the drawning order there are the steps

a) Set DepthBufferEnable and DepthBufferWriteEnable to true
b) Draw all opaque geometry
c) Leave DepthBufferEnable set to true, but change DepthBufferWriteEnable to false
d) Sort alpha blended objects by distance from the camera, then draw them in order from back to front

Consideration C1: in a) he doesnt speak about order and he is right.
Consideration C2: Don't shoot at me but i think in point d) he is wrong when he says you have to order-depth alpha blended objects.

Suppose you have from left to right
camera A1 A2 O1
where A are alpha blended objects and O1 is an opaque one. I draw O1. Now i set DepthBufferWriteEnable to false. At this point if i draw A1 then A2 or A2 then A1 the result doesnt change because in every cass they pass the depth test.

Is this right?
Thanks GD!

Blendstate

29 July 2011 - 10:27 AM

Hi,

i wanna draw a quad and apply a texture. The texture is a tga file black on the sides and transparent in the middle. Namely it's a frame.

When the quad is drawn it results all black.

The texture mapping i am sure it's coded correctly since if i apply a painted texture the quad is drawn properly.

So it must be a blend issue. I khnow there is the blendstate object but from the books it is always used with spritebeatch objects. In my case the quad id drown via userPrimitive functions.

The quad class

class Quad
    {
        public Vector3 Origin;
        public Vector3 UpperLeft;
        public Vector3 LowerLeft;
        public Vector3 UpperRight;
        public Vector3 LowerRight;
        public Vector3 Normal;
        public Vector3 Up;
        public Vector3 Left;

        public VertexPositionNormalTexture[] Vertices;
        public int[] Indices;

        public Quad(Vector3 origin, Vector3 normal, Vector3 up, float width, float height)
        {
            Vertices = new VertexPositionNormalTexture[4];
            Indices = new int[6];
            Origin = origin;
            Normal = normal;
            Up = up;

            // Calculate the quad corners
            Left = Vector3.Cross(normal, Up);
            Vector3 uppercenter = (Up * height / 2) + origin;
            UpperLeft = uppercenter + (Left * width / 2);
            UpperRight = uppercenter - (Left * width / 2);
            LowerLeft = UpperLeft - (Up * height);
            LowerRight = UpperRight - (Up * height);

            FillVertices();
        }

        private void FillVertices()
        {
            // Fill in texture coordinates to display full texture
            // on quad
            Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f);
            Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
            Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f);
            Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);

            // Provide a normal for each vertex
            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i].Normal = Normal;
            }

            // Set the position and texture coordinate for each
            // vertex
            Vertices[0].Position = LowerLeft;
            Vertices[0].TextureCoordinate = textureLowerLeft;
            Vertices[1].Position = UpperLeft;
            Vertices[1].TextureCoordinate = textureUpperLeft;
            Vertices[2].Position = LowerRight;
            Vertices[2].TextureCoordinate = textureLowerRight;
            Vertices[3].Position = UpperRight;
            Vertices[3].TextureCoordinate = textureUpperRight;

            // Set the index buffer for each vertex, using
            // clockwise winding
            Indices[0] = 0;
            Indices[1] = 1;
            Indices[2] = 2;
            Indices[3] = 2;
            Indices[4] = 1;
            Indices[5] = 3;
            
        }


and the tunnel class: the tunnel class is a sort of container of Quads objects and it serves to draw a "tunnel of quads"

    public class Tunnel : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Vector3 _origin, _normal, _up;
        float _width, _height;
        int _near, _far;
        GraphicsDeviceManager _graphics;
        ContentManager _content;
        Texture2D _texture;
        BasicEffect quadEffect;
        CameraComponent _camera;
        List<Quad> _quads;
        string _texname;
        public Tunnel(Game game, GraphicsDeviceManager gdm, CameraComponent camera, ContentManager cm, int near, int far, Vector3 origin, Vector3 normal, Vector3 up, float width, float height, string texture)
            : base(game)
        {
            // TODO: Construct any child components here
            _origin = origin;
            _normal = normal;
            _up = up;
            _width = width;
            _height = height;
            _graphics = gdm;
            _content = cm;
            _camera = camera;
            _texname = texture;
            _near = near;
            _far = far;
            
        }
        protected override void LoadContent()
        {
            BlendState bs = new BlendState();
            bs.AlphaSourceBlend = Blend.One;
            bs.AlphaDestinationBlend = Blend.Zero;
            _texture = _content.Load<Texture2D>(_texname);
            quadEffect = new BasicEffect(_graphics.GraphicsDevice);
            //quadEffect.EnableDefaultLighting();

            quadEffect.World = Matrix.Identity;
            quadEffect.View = _camera.View;
            quadEffect.Projection = _camera.Proj;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture = _texture;
            quadEffect.Alpha = 1;
            quadEffect.VertexColorEnabled = false;
            

            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            _quads = new List<Quad>();
            for (int i = _near; i < _far; i++)
            {
                _quads.Add(new Quad(new Vector3(0,0,(float)i*(-1)), _normal, _up, _width, _height));
            }
                base.Initialize();
        }


        private void DrawQuad(Quad quad)
        {
             

             
                 foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes)
                 {
                     pass.Apply();

                     _graphics.GraphicsDevice.DrawUserIndexedPrimitives
                         <VertexPositionNormalTexture>(
                         PrimitiveType.TriangleList,
                         quad.Vertices, 0, 4,
                         quad.Indices, 0, 2);
                 }
                     
        }

        public override void Draw(GameTime gameTime)
        {
            foreach (Quad quad in _quads)
            {
                DrawQuad(quad);
            }

            base.Draw(gameTime);
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
    }

i attach a file showing quads are full black
Thanks :D

2D space battle game

19 July 2011 - 07:42 AM

Hello GD,
i wanna code a simple 2d game. My doubts are not technical, i khnow c++, 3d math openGL so im not new to the world. My question is more about how generally 2D games are done in relation to external design tools (i.e. Maya, 3Dmax)

I have started studying XNA on this book.
Now in chapter 5 the author started to speak about imported Models (say a box) and models are new to me. I am speaking of the Model class, its meshes, meshes parts and so forth. In chapter 6 the author speaks about the BaseEffect class (i.e. to manage lights) always referred to a 3D model.

Question: Do i need this concepts for my 2d space battle game? I mean: does a 2D model (model intended as created in a 3rd party software and imported in XNA like the BOX) make sense? Should i just pickup TEXTURE2D stuff?

Hope have been clear.

Thanks

Performance with different compilers

06 July 2011 - 04:59 AM

Hello gd people,
i had my c++/opengl project running fine on CodeBlocks (with MINGW compiler). The debugger but was not so handly so i decided to move all the code in VS2010 Express edition.

The code is for the 99.9% the same. The 0.1% difference comes from stuff that compiles on CB and not in VS and i had to change.

My program is a win32 project. In the strarting it has to do lot of calcs because it has to build a mesh representing an image. The mesh is a complex object containing members like stl Vectors of pointers to vertices, edges, faces etc...

Why the hell when i run the program in VS it takes much longer respect to CB? Of course i run everything in release. Once the mesh is builded i cant notice any different in performance.
But at the start, before the first image appears in the drawning window, we speak of 1-2 seconds in CB versus 10-15 seconds in VS.
Might be express edition the problem?

Thanks fellows!
Riziero

PARTNERS