示例#1
0
        public static void renderBackground(Texture texture)
        {
            // To store the converted video
            // no longer required - textures now saved out and sent to a memory stream.
            //convertedVideo[frameCounter++] = texture;

            // Prevent anything from being rendered until ready
            if (globalSettings.videoPortal_eRenderReady == false)
            {
                return;
            }


            // Origionaly split out but more stable as part of this method
            if (device == null || device.Disposed)
            {
                return;
            }


            device.BeginScene();


            // Renders to a flat plane - i.e. the screen
            CustomVertex.TransformedTextured[] screenVert = new CustomVertex.TransformedTextured[4];
            screenVert[0] = new CustomVertex.TransformedTextured(0, 0, 0, 1, 0, 0);
            screenVert[1] = new CustomVertex.TransformedTextured(clientForm.Width, 0, 0, 1, 1, 0);
            screenVert[2] = new CustomVertex.TransformedTextured(clientForm.Width, clientForm.Height, 0, 1, 1, 1);
            screenVert[3] = new CustomVertex.TransformedTextured(0, clientForm.Height, 0, 1, 0, 1);
            // To tile textures, use the wrap texture type - It's used by default...
            // device.SamplerState[1].AddressU = TextureAddress.Wrap; device.SamplerState[1].AddressV = TextureAddress.Wrap;
            // Then set the U&V co-ordinates to the number of times you want the texture replicated
            // i.e. if you change both the U&V co-ords to 2 then you will see the texture tiled 4 times, 2 across and 2 down



            // Turn off while drawing the background
            //device.RenderState.ZBufferEnable = false;

            // Test with vertex buffer
            // buffer.SetData(screenVert, 0, LockFlags.None);


            // -----------Stuffn with --------------------------------
            //SamplerStateManager sam = new SamplerStateManager();
            //sam = TextureAddress.Border;
            //device.SetSamplerState(0,SamplerStageStates.SrgbTexture, true);

            //TextureAddress tex = new TextureAddress();
            //tex = TextureAddress.Border;

            // -----------Stuffn with --------------------------------


            //// These would probably work if the textures were first copied to a newly created texture in this
            //// transactions scope
            //fUtil.addFrame(device.GetTexture(0));
            //fUtil.addFrame(texture);


            //// This works to save the rendered frame to a BMP
            //Bitmap bmp = SaveToBitmap(device);
            //fUtil.addBmpFrame(bmp);


            // Attemptng to save the frame as a memory stream in the DDS format
            //SaveToDDSFile(device);
            //fUtil.addDDSFrame("TempDDSConv.dds");

            //fUtil.addMSFrame(aMS);



            // Set the texture to render to the background
            device.SetTexture(0, texture);


            if (lastFrame != null)
            {
                // For Vertex Buffer
                //device.SetStreamSource(0, buffer, 0,0);



                device.SetTexture(1, lastFrame);

                // Sets the U&V co-ordinates for the '1' (i.e. second) texture stage to the same as the first!
                // I wish ths was better f*****g documented, seriosuly
                device.TextureState[1].TextureCoordinateIndex = 0;

                // For Vertex Buffer
                //device.SetStreamSource(1, buffer, 0,0);


                //-------------- more stuffn
                //device.SamplerState[0].AddressU = TextureAddress.Border;
                //device.SamplerState[0].AddressV = TextureAddress.Border;

                // wrap is the default mode
                device.SamplerState[1].AddressU = TextureAddress.Wrap;
                device.SamplerState[1].AddressV = TextureAddress.Wrap;
                //-------------



                //// Blend and mix - around 50% transperancy
                device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Add);


                // Lighter blend
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.MultiplyAdd);

                // Subtract the darker colour from the lighter colour
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Subtract);

                // Add with a darker tinge
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSigned);

                // Add with highted highlights and darkened shadows
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSigned2X);

                // Add with a lighter mix
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSmooth);

                // Use colour to tint image mix
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate);

                // Add image and inverse white parts of the image being added
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Lerp);


                // Black and white image add.
                //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.DotProduct3);



                //if (secondLastFrame != null)
                //{

                //    device.TextureState[2].TextureCoordinateIndex = 0;
                //    device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1);

                //    device.SetTexture(2, secondLastFrame);

                //    device.SetTextureStageState(2, TextureStageStates.ColorArgument1, (int)TextureArgument.Current);
                //    device.SetTextureStageState(2, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor);
                //    device.SetTextureStageState(2, TextureStageStates.ColorOperation, (int)TextureOperation.Add);
                //}
            }
            //secondLastFrame = lastFrame;
            lastFrame = texture;


            //device.VertexFormat = CustomVertex.TransformedTextured.Format;
            device.VertexFormat = vertexFormat;

            device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, screenVert);

            // Turn it back on
            // device.RenderState.ZBufferEnable = true;



            // Origionaly split out but more stable in the same method
            device.EndScene();
            device.Present();
        }