91 lines
1.9 KiB
C#
91 lines
1.9 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 float Right {
|
|
get { return this.Left + this.Width; }
|
|
set { this.Left = value - this.Width; }
|
|
}
|
|
|
|
public float Bottom {
|
|
get { return this.Top + this.Height; }
|
|
set { this.Top = value - this.Height; }
|
|
}
|
|
|
|
public bool Visible { get; set; }
|
|
|
|
public Vector3 BackgroundColor { get; set; } = new Vector3(0.3f,0.3f,0.3f);
|
|
|
|
public Viewport()
|
|
{
|
|
sceneOrientation = new GLSceneOrientation();
|
|
Left = 0.0f;
|
|
Top = 0.0f;
|
|
Width = 1.0f;
|
|
Height = 1.0f;
|
|
Visible = true;
|
|
}
|
|
|
|
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(){
|
|
if (!Visible)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Parent != null){
|
|
Rectangle cr = Parent.ClientRectangle;
|
|
Rectangle vpr = new Rectangle(
|
|
(int)(cr.Left + (cr.Width * Left)),
|
|
(int)(cr.Top + (cr.Height * (1.0f - Top - Height))),
|
|
(int)(cr.Width * Width),
|
|
(int)(cr.Height * Height)
|
|
);
|
|
|
|
Console.WriteLine(String.Format("viewPort: {0} {1}",cr,vpr));
|
|
|
|
GL.Viewport( vpr );
|
|
GL.Scissor( vpr.X, vpr.Y, vpr.Width, vpr.Height );
|
|
sceneOrientation.setViewport( vpr.Width, vpr.Height );
|
|
|
|
GL.ClearColor( BackgroundColor.X, BackgroundColor.Y, BackgroundColor.Z, 0.1f);
|
|
GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
|
|
|
|
if (Scene != null){
|
|
Scene.draw(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|