public class Renderer {
private Control renderWindow;
private Device device;
public Renderer(Control renderWindow, bool Windowed) {
this.renderWindow = renderWindow;
// Initialize a Direct3D 'device' that we can use to render our scene
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.BackBufferHeight = this.renderWindow.ClientSize.Height;
presentParams.BackBufferWidth = this.renderWindow.ClientSize.Width;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
device = new Device(new Direct3D(), 0, DeviceType.Hardware, renderWindow.Handle, CreateFlags.HardwareVertexProcessing, presentParams);
}
/// <summary>
/// Get the renderer device
/// </summary>
public Device Device {
get {
return device;
}
}
public void Render(bool gameShown, bool menuShown, Level currentLevel, WTDLib.Global.Menu.Menu activeMenu, ImageDictionary imagedict, ViewCamera viewcam) {
// Clear drawing area
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, BackColor, 1.0f, 0);
device.BeginScene();
Sprite sprite = new Sprite(device);
if (gameShown) {
sprite.Begin(SpriteFlags.AlphaBlend);
foreach (GameObject go in currentLevel) {
// fix positio,:
int y = go.Y;
// manually flip the imagelocations (translatetransform is no longer present)
int half = renderWindow.Height / 2;
half -= 30;
if (y < half) {
int difference = half - y;
y = half + difference;
}
else {
int difference = y - half;
y = half - difference;
}
if (go is WTDLib.Global.Surface) {
y -= 34;
}
// set position and transformations and such
// get the texture out of the gameobject:
sprite.Draw(imagedict[go.Id.ToString()], go.SrcRect, null, new Vector3(go.X + viewcam.XOffset, y, 0), Color.White);
}
sprite.End();
}
else if (menuShown) {
SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font(FontFamily.GenericSansSerif, 20));
sprite.Begin(SpriteFlags.AlphaBlend);
foreach(MenuElement element in activeMenu) {
if (element is MenuButton) {
MenuButton button = (MenuButton)element;
//font.DrawString(sprite, button.Text, new Rectangle(button.X, button.Y, button.Width, button.Height), DrawTextFormat.Left, new Color4(1f, 0, 0, 0));
font.DrawString(sprite, button.Text, button.X, button.Y, button.Brush.Color);
}
else if (element is MenuText) {
MenuText text = (MenuText)element;
font = new SlimDX.Direct3D9.Font(device, text.Font);
font.DrawString(sprite, text.Text, text.X, text.Y, text.Brush.Color);
}
}
sprite.End();
font.Dispose();
}
device.EndScene(); // end drawing 3D)scene
device.Present(); // flip back- & frontbuffer --> show 3D scene
// now dispose the sprites
sprite.Dispose();
}
}
Every texture shows up fine, but none of them have the width or height that I want. In GDI+ you could specify a bitmap to have certain values for that but it doesn't seem like this is possible with sprites? Am I gonna have to resize the actual files I'm loading? I've spent all day on this and can't find anything on the internet on how to solve this so some help would be very appreciated.
edit: Oh forgot to mention, I have tried out the Matrix.Scaling methods but that one doesn't quite give me what I want.. It's hard to explain :/ It looks like it doesn't just make the sprite bigger, but also the distance between sprites and such.