[added in 1.5] Render to texture

You can help us to improve Brume ! Post your contribs here and we will try to integrate them in next release for other users !

Moderator: Brume Dev Team

[added in 1.5] Render to texture

Postby Bartman on Thu Oct 12, 2006 10:21 am

Hi

I needed the ability to render to a texture using GDI. I could not find it in a 'Brume' supported way so I made the class as below. It has a Graphics property that can be used to obtain a drawing context. The changes appear immediately on the mesh that has the texture assigned.

Maybe there is someway to include rendering-to-texture in Brume?

Thanks!


Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Brume;
using System.Drawing;
using System.Diagnostics;

namespace Brume.Helpers
{
    class GdiTexture : Brume.BrumeTexture, IDisposable
    {
        private Surface _surface = null;

        public GdiTexture(Brume.Brume brume, string name, int w, int h)
            : base(brume, name)
        {
            Debug.Assert(brume.GraphicApi as DirectX9GraphicApi != null);

            texture = new Texture(
                ((DirectX9GraphicApi)brume.GraphicApi).GetDevice(),
                w,
                h,
                1,
                0,
                Format.X8R8G8B8,
                Pool.Managed);
        }

        public Graphics Graphics
        {
            get
            {
                if(_surface != null)
                    _surface.Dispose();
                _surface = texture.GetSurfaceLevel(0);
                Graphics gp = _surface.GetGraphics();
                return gp;
            }
        }

        public void Dispose()
        {
            if(texture != null)
                texture.Dispose();
            if (_surface != null)
                _surface.Dispose();

            GC.SuppressFinalize(this);
        }

    }
}
User avatar
Bartman
Brume user
 
Posts: 23
Joined: Wed Oct 11, 2006 7:01 am
Location: The Netherlands

Postby Silmaryls on Fri Oct 13, 2006 8:33 pm

Hi Bartman !

It's a really good idea. I'm going to integrate that cause I have to refactor the BrumeTexture class (It's still linked to DirectX implementation).
I wil try to integrate your source code for the next release.

Thanks.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Contribs

Who is online

Users browsing this forum: No registered users and 2 guests

cron