Example #1
0
        public void DrawContents(RenderDevice graphics)
        {
            // set pixels of texture
            // convert from pixelcolor to uint
            fixed(PixelColor *pixels = this.pixels)
            {
                uint *uintpixels   = (uint *)pixels;
                uint *targetpixels = (uint *)graphics.MapPBO(Texture);

                for (int i = 0; i < this.pixels.Length; i++)
                {
                    *targetpixels++ = *uintpixels++;
                }
                graphics.UnmapPBO(Texture);
            }
        }
		// This renders the quad
		public void Render(RenderDevice device)
		{
			// Render the quad
			device.Draw(type, 0, 2, vertices);
		}
Example #3
0
 public Mesh(RenderDevice graphics, WorldVertex[] vertexData, int[] indexData)
 {
     graphics.SetBufferData(Vertices, vertexData);
     graphics.SetBufferData(Indices, indexData);
     PrimitivesCount = indexData.Length / 3;
 }
Example #4
0
        // This updates the text if needed
        public void Update(RenderDevice graphics, float translatex, float translatey, float scalex, float scaley)
        {
            // Check if transformation changed and needs to be updated
            if (transformcoords && (translatex != lasttranslatex || translatey != lasttranslatey ||
                                    scalex != lastscalex || scaley != lastscaley))
            {
                lasttranslatex = translatex;         //mxd
                lasttranslatey = translatey;         //mxd
                lastscalex     = scalex;             //mxd
                lastscaley     = scaley;             //mxd
                updateneeded   = true;
            }

            // Update if needed
            if (updateneeded || textureupdateneeded)
            {
                // Only build when there are any vertices
                if (text.Length > 0)
                {
                    // Transform?
                    Vector2D abspos = (transformcoords ? location.GetTransformed(translatex, translatey, scalex, scaley) : location);

                    // Update text and texture sizes
                    if (textsize.IsEmpty || texturesize.IsEmpty)
                    {
                        textorigin      = new PointF(4, 3);
                        textrect        = new RectangleF(textorigin, General.Interface.MeasureString(text, font));
                        textrect.Width  = (float)Math.Round(textrect.Width);
                        textrect.Height = (float)Math.Round(textrect.Height);
                        bgrect          = new RectangleF(0, 0, textrect.Width + textorigin.X * 2, textrect.Height + textorigin.Y * 2);

                        // Store calculated text size...
                        textsize = new SizeF(textrect.Width + textorigin.X * 2, textrect.Height + textorigin.Y * 2);

                        // Make PO2 image, for speed and giggles...
                        texturesize = new Size(General.NextPowerOf2((int)textsize.Width), General.NextPowerOf2((int)textsize.Height));

                        switch (alignx)
                        {
                        case TextAlignmentX.Center: bgrect.X = (texturesize.Width - bgrect.Width) / 2; break;

                        case TextAlignmentX.Right: bgrect.X = texturesize.Width - bgrect.Width; break;
                        }

                        switch (aligny)
                        {
                        case TextAlignmentY.Middle: bgrect.Y = (texturesize.Height - bgrect.Height) / 2; break;

                        case TextAlignmentY.Bottom: bgrect.Y = texturesize.Height - bgrect.Height; break;
                        }

                        textrect.X += bgrect.X;
                        textrect.Y += bgrect.Y;
                    }

                    // Align the text horizontally
                    double beginx = 0;
                    switch (alignx)
                    {
                    case TextAlignmentX.Left: beginx = abspos.x; break;

                    case TextAlignmentX.Center: beginx = abspos.x - texturesize.Width * 0.5f; break;

                    case TextAlignmentX.Right: beginx = abspos.x - texturesize.Width; break;
                    }

                    // Align the text vertically
                    double beginy = 0;
                    switch (aligny)
                    {
                    case TextAlignmentY.Top: beginy = abspos.y; break;

                    case TextAlignmentY.Middle: beginy = abspos.y - texturesize.Height * 0.5f; break;

                    case TextAlignmentY.Bottom: beginy = abspos.y - texturesize.Height; break;
                    }

                    //mxd. Skip when not on screen...
                    RectangleF abssize    = new RectangleF((float)beginx, (float)beginy, texturesize.Width, texturesize.Height);
                    Size       windowsize = General.Map.Graphics.RenderTarget.ClientSize;
                    skiprendering = (abssize.Right < 0.1f) || (abssize.Left > windowsize.Width) || (abssize.Bottom < 0.1f) || (abssize.Top > windowsize.Height);
                    if (skiprendering)
                    {
                        return;
                    }

                    //mxd. Update texture if needed
                    if (textureupdateneeded)
                    {
                        // Get rid of old texture
                        if (texture != null)
                        {
                            texture.Dispose();
                            texture = null;
                        }

                        // Create label image
                        using (Bitmap img = CreateLabelImage(text, font, color, backcolor, drawbg, textrect, bgrect, texturesize, textorigin))
                        {
                            texture = new Texture(graphics, img);
                        }
                    }

                    //mxd. Create the buffer
                    if (textbuffer == null || textbuffer.Disposed)
                    {
                        textbuffer = new VertexBuffer();
                    }

                    FlatQuad quad = new FlatQuad(PrimitiveType.TriangleStrip, (float)beginx, (float)beginy, (float)(beginx + texturesize.Width), (float)(beginy + texturesize.Height));
                    graphics.SetBufferData(textbuffer, quad.Vertices);
                }
                else
                {
                    // No faces in polygon
                    textsize      = SizeF.Empty;              //mxd
                    texturesize   = Size.Empty;               //mxd
                    skiprendering = true;                     //mxd
                }

                // Text updated
                updateneeded        = false;
                textureupdateneeded = false;                 //mxd
            }
        }
 public CubeTexture(RenderDevice device, int size)
 {
     Texture_SetCubeImage(Handle, size, TextureFormat.Bgra8);
 }
Example #6
0
 public void Update(RenderDevice graphics, float translatex, float translatey, float scalex, float scaley)
 {
     label.Update(graphics, translatex, translatey, scalex, scaley);
 }