budnhead/org.budnhead/graphics/Viewport.cs

68 lines
1.4 KiB
C#

using System;
using System.Drawing;
using org.budnhead.core;
using org.budnhead.tools;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace org.budnhead.graphics
{
public class Viewport
{
GLSceneOrientation sceneOrientation;
Scene scene;
ShaderProgram shader;
public float Left { get; set; }
public float Top { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public Viewport()
{
sceneOrientation = new GLSceneOrientation();
Left = 0.0f;
Top = 0.0f;
Width = 1.0f;
Height = 1.0f;
}
internal SceneWindow Parent { get; set; }
public Scene Scene {
get { return this.scene; }
set { this.scene = value; }
}
public GLSceneOrientation SceneOrientation {
get { return this.sceneOrientation; }
set { this.sceneOrientation = value; }
}
public void paint(){
Console.WriteLine("Viewport.paint()");
if (Parent != null){
Rectangle cr = Parent.ClientRectangle;
Rectangle vpr = new Rectangle(
(int)(cr.Left + (cr.Width * Left)),
(int)(cr.Top + (cr.Height * Top)),
(int)(cr.Width * Width),
(int)(cr.Height * Height)
);
Console.WriteLine(String.Format("Viewport: {0}",vpr));
GL.Viewport( vpr );
sceneOrientation.setViewport( cr.Width, cr.Height );
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Scene.draw(this);
}
}
}
}