diff options
author | Treeki <treeki@gmail.com> | 2011-02-18 03:28:31 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-02-18 03:28:31 +0100 |
commit | b0760b28807b31cc1403584265c07feb87ac4887 (patch) | |
tree | dc97346a0c0d0cdcdc066d77df3905a614a858e8 /TestApp/RenderWindow.cs | |
parent | 7d7491feb41bc9724bf63bef545b996226406889 (diff) | |
download | nw4rtools-b0760b28807b31cc1403584265c07feb87ac4887.tar.gz nw4rtools-b0760b28807b31cc1403584265c07feb87ac4887.zip |
some collada work, and an unfinished OGL renderer using OpenTK. huge commit
Diffstat (limited to '')
-rw-r--r-- | TestApp/RenderWindow.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/TestApp/RenderWindow.cs b/TestApp/RenderWindow.cs new file mode 100644 index 0000000..2dfe1ec --- /dev/null +++ b/TestApp/RenderWindow.cs @@ -0,0 +1,57 @@ +using System; +using NW4RTools; +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +namespace TestApp { + public class RenderWindow : GameWindow { + public RenderWindow() : base(800, 600, GraphicsMode.Default, "Test Model") { + + } + + private NW4RTools.Models.OpenGL.GLModel m_glModel; + + public void SetModel(ResFile rf, string modelName) { + m_glModel = new NW4RTools.Models.OpenGL.GLModel(rf, modelName); + } + + + protected override void OnLoad(EventArgs e) { + base.OnLoad(e); + + GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f); + GL.Enable(EnableCap.DepthTest); + + m_glModel.Prepare(Context); + } + + protected override void OnResize(EventArgs e) { + base.OnResize(e); + + GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height); + + Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 2000.0f); + GL.MatrixMode(MatrixMode.Projection); + GL.LoadMatrix(ref projection); + } + + protected override void OnUpdateFrame(FrameEventArgs e) { + base.OnUpdateFrame(e); + + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + + Matrix4 modelview = Matrix4.LookAt(new Vector3(0, 1200, 500), Vector3.UnitZ, Vector3.UnitY); + GL.MatrixMode(MatrixMode.Modelview); + GL.LoadMatrix(ref modelview); + + m_glModel.Render(Context); + + SwapBuffers(); + } + + + } +} + |