Click here to Skip to main content
11,479,841 members (47,521 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# XNA Kinect
hello everyone, thx in advance for your help Smile | :) .

The problem that i have is about rendering in xna4 and kinect, when i got a colorframe from kinect, i copy it to a texture2D and then render it to a rendertarget, but my render target has more resolution. that's not a problem since I dont need to fill the whole screen, but i need the sorrounding parts to be transparent ...

I obviously make a
, but it renders purple ... testing and testing i got that if i render it slowly (i make a check for the colorframe ready), the render target transparency works fine "sometimes", since the purple parts appears like blinking.

any idea what is happening?,

my code for rendering:

GraphicsDevice.SetRenderTarget(Full);//junta las capas
            //renderiza todo lo que haya en la lista ...
            if (SystemElementList.OpenedFileList.Count > 0)
                GraphicsDevice.Clear(Color.White); //fondo blanco
                for (int i = SystemElementList.OpenedFileList[SystemElementList.actualFile].LayerList.Count - 1; i > -1; i--)
                    Layer Lay = SystemElementList.OpenedFileList[SystemElementList.actualFile].LayerList[i];
                    if (Lay.Update && Lay.Visible) //para que renderize solo si es necesario y además si esta visible -> cada vez que se ejecuta bahave hay que revisar si es necesario actualizar ...
                        if (Lay.renderedLayer == null) Lay.renderedLayer = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); //chequea que el rendertarget este creado 

                        GraphicsDevice.SetRenderTarget(Lay.renderedLayer); //se selecciona solo la capa como renderTarget
                        sprite.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                        if (Lay.HasBackground)//renderizar background del tamaño exacto de la vista, si es que lo tiene ...
                            sprite.Draw(Lay.Background, Vector2.Zero, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                        foreach (ObjetoRenderizable Obj in Lay.RenderList)
                              Obj.render2D(GraphicsDevice, ref sprite); //here i render the kinect layer with other objects of course ... the other objects works fine with the transparency ...
                        if (Lay.Cleanable)
                            //sprite.Draw(Lay.Eraser, Vector2.Zero, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                        Lay.Update = false;
                    if (Lay.Visible && Lay.renderedLayer != null)
                        GraphicsDevice.SetRenderTarget(Full);//renderiza la capa en el pass final ... solo si es visible, tiene elementos y ademas hay que actualizarla
                        sprite.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                        sprite.Draw(Lay.renderedLayer, Vector2.Zero, Color.White); //se renderiza
                    Lay = null;
                GraphicsDevice.Clear(Color.Gray); //color de fondo default 
            GraphicsDevice.SetRenderTarget(null); //vuelve al render target comun y renderiza el resultado final
            GraphicsDevice.Clear(Color.Gray); //color de fondo default
            sprite.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            sprite.Draw(Full, Vector2.Zero, Color.White);
Posted 16-Nov-12 4:23am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 260
1 Sergey Alexandrovich Kryukov 215
2 F-ES Sitecore 175
3 Richard MacCutchan 100
4 DamithSL 65
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100