Click here to Skip to main content
15,884,537 members

Odd transparent rendering in xna

SkynetKernel asked:

Open original thread
hello everyone, thx in advance for your help :).

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
C#
graphicsdevice.clear(color.transparent)
, 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:

C#
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
                        GraphicsDevice.Clear(Color.Transparent);

                        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);
                        }
                        sprite.End();
                        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
                        sprite.End();
                    }
                    Lay = null;
                }
            }
            else
            {
                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);
            sprite.End();
Tags: C#, Kinect, XNA

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900