Exemplo n.º 1
0
        public static void init()
        {
            if (shaderUniversal == null){
                shaderUniversal = new ShaderProgram("/Application/shaders/Universal.cgx");

                shaderUniversal.SetAttributeBinding(0, "a_Position");
                shaderUniversal.SetAttributeBinding(1, "a_VertexColor");
                shaderUniversal.SetAttributeBinding(2, "a_TexCoord");

                shaderUniversal.SetUniformBinding(0, "u_SceneMatrix");
                shaderUniversal.SetUniformBinding(1, "u_ScreenMatrix");
                shaderUniversal.SetUniformBinding(2, "u_Alpha");

                texture = new Texture2D("/Application/assets/texturepack/rymdkapsel-hd.png", false);
                texture.SetFilter(TextureFilterMode.Disabled);
                texture.SetWrap(TextureWrapMode.ClampToEdge);
                texture.SetMaxAnisotropy(0);
            }

            if (shaderColored == null){
                shaderColored = new ShaderProgram("/Application/shaders/Colored.cgx");

                shaderColored.SetAttributeBinding(0, "a_Position");
                shaderColored.SetAttributeBinding(1, "a_VertexColor");

                shaderColored.SetUniformBinding(0, "u_SceneMatrix");
                shaderColored.SetUniformBinding(1, "u_ScreenMatrix");
                shaderColored.SetUniformBinding(2, "u_Alpha");
            }
        }
Exemplo n.º 2
0
        public RendererStartup(Sprite sprite)
            : base(sprite)
        {
            float[] verts = new float[8];
            float[] uvs = new float[8];

            texture = new Texture2D("/Application/assets/bootscreen/Vita.png", false);
            texture.SetFilter(TextureFilterMode.Disabled);
            texture.SetWrap(TextureWrapMode.ClampToEdge);
            texture.SetMaxAnisotropy(0);

            int offsetX = (Settings.STAGE_W - texture.Width) / 2;
            int offsetY = (Settings.STAGE_H - texture.Height) / 2;

            verts[0] = (float) offsetX;
            verts[1] = (float) offsetY;

            verts[2] = (float) offsetX;
            verts[3] = (float) offsetY + texture.Height;

            verts[6] = (float) offsetX + texture.Width;
            verts[7] = (float) offsetY;

            verts[4] = (float) offsetX + texture.Width;
            verts[5] = (float) offsetY + texture.Height;

            uvs[0] = 0;
            uvs[1] = 0;

            uvs[2] = 0;
            uvs[3] = 1;

            uvs[6] = 1;
            uvs[7] = 0;

            uvs[4] = 1;
            uvs[5] = 1;

            vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
            vertexBuffer.SetVertices(0, verts);
            vertexBuffer.SetVertices(1, uvs);
        }
Exemplo n.º 3
0
        public override void validateBuffer()
        {
            if (texture != null){
                texture.Dispose();
                texture = null;
            }

            if (vertexBuffer != null){
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }

            if (textfield.text == null || textfield.text.Length == 0){
                dirtyBuffer = false;
                return;
            }

            updateSize();

            float[] verts = new float[8];
            float[] uvs = new float[8];

            int maxWidth = (int) textWidth;
            if (textfield.defaultTextFormat.align == "right"){
                maxWidth = textfield.width;
            }

            verts[0] = (float) OFFSET_X;
            verts[1] = (float) OFFSET_Y;

            verts[2] = (float) OFFSET_X;
            verts[3] = (float) OFFSET_Y + textHeight;

            verts[6] = (float) OFFSET_X + maxWidth;
            verts[7] = (float) OFFSET_Y;

            verts[4] = (float) OFFSET_X + maxWidth;
            verts[5] = (float) OFFSET_Y + textHeight;

            uvs[0] = 0;
            uvs[1] = 0;

            uvs[2] = 0;
            uvs[3] = 1;

            uvs[6] = 1;
            uvs[7] = 0;

            uvs[4] = 1;
            uvs[5] = 1;

            vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
            vertexBuffer.SetVertices(0, verts);
            vertexBuffer.SetVertices(1, uvs);

            int argb = textfield.defaultTextFormat.color;

            var image = new Image(	ImageMode.Rgba,
                                    new ImageSize((int)maxWidth, (int)textHeight),
                                    new ImageColor(0, 0, 0, 0));

            ImagePosition pos = new ImagePosition(0, 0);
            for (int i = 0; i < textLines.Length; i++){
                pos.X = 0;
                pos.Y = i * font.Metrics.Height;

                if (textfield.defaultTextFormat.align == "right"){
                    pos.X = (int) maxWidth - font.GetTextWidth(textLines[i]);
                }

                image.DrawText(
                    textLines[i],
                    new ImageColor((int)((argb >> 16) & 0xff),
                    (int)((argb >> 8) & 0xff),
                    (int)((argb >> 0) & 0xff),
                    255),
                    font,
                    pos
                );
            }

            texture = new Texture2D((int)maxWidth, (int)textHeight, false, PixelFormat.Rgba);
            texture.SetPixels(0, image.ToBuffer());
            texture.SetFilter(TextureFilterMode.Disabled);
            texture.SetWrap(TextureWrapMode.ClampToEdge);
            texture.SetMaxAnisotropy(0);
            image.Dispose();

            dirtyBuffer = false;

            //Console.WriteLine("buffer validated: " + renderable.commands.length);
        }