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);
}
}
}