summaryrefslogtreecommitdiff
path: root/ConsoleApp/RenderWindow.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-05-07 03:50:42 +0200
committerTreeki <treeki@gmail.com>2011-05-07 03:50:42 +0200
commitb726fbe95fa850f1e51dbc6a4a76f701dbb1db6b (patch)
treedbeda734bb92f8e062bb44a1dc04763537a49c99 /ConsoleApp/RenderWindow.cs
parent30a400a14b2cda40bd87234b284d692dbe540736 (diff)
downloadnw4rtools-b726fbe95fa850f1e51dbc6a4a76f701dbb1db6b.tar.gz
nw4rtools-b726fbe95fa850f1e51dbc6a4a76f701dbb1db6b.zip
added render-model command to ConsoleApp
Diffstat (limited to '')
-rw-r--r--ConsoleApp/RenderWindow.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/ConsoleApp/RenderWindow.cs b/ConsoleApp/RenderWindow.cs
new file mode 100644
index 0000000..f6f5951
--- /dev/null
+++ b/ConsoleApp/RenderWindow.cs
@@ -0,0 +1,77 @@
+using System;
+using NW4RTools;
+using OpenTK;
+using OpenTK.Graphics;
+using OpenTK.Graphics.OpenGL;
+using OpenTK.Input;
+
+namespace ConsoleApp {
+ 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);
+
+ GL.Enable(EnableCap.Blend);
+ GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
+
+ GL.Disable(EnableCap.CullFace);
+
+ GL.Enable(EnableCap.Lighting);
+
+ GL.ShadeModel(ShadingModel.Smooth);
+
+ GL.Light(LightName.Light0, LightParameter.Position, new Vector4(0, 500, 1000, 0));
+ GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, new Color4(1, 1, 1, 1));
+ GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 50);
+ GL.Enable(EnableCap.Light0);
+
+ GL.Light(LightName.Light1, LightParameter.Position, new Vector4(1000, 500, 0, 0));
+ GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, new Color4(1, 1, 1, 1));
+ GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 50);
+ GL.Enable(EnableCap.Light1);
+
+ 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, 400, 1000), new Vector3(0, 0, 0), Vector3.UnitY);
+ //Matrix4 modelview = Matrix4.LookAt(new Vector3(-50, 20, 50), new Vector3(0, 0, 0), Vector3.UnitY);
+ GL.MatrixMode(MatrixMode.Modelview);
+ GL.LoadMatrix(ref modelview);
+
+ m_glModel.Render(Context);
+
+ SwapBuffers();
+ }
+
+
+ }
+}
+