From b0760b28807b31cc1403584265c07feb87ac4887 Mon Sep 17 00:00:00 2001 From: Treeki Date: Fri, 18 Feb 2011 03:28:31 +0100 Subject: some collada work, and an unfinished OGL renderer using OpenTK. huge commit --- TestApp/Main.cs | 16 ++++++++-- TestApp/RenderWindow.cs | 57 ++++++++++++++++++++++++++++++++++++ TestApp/TestApp.csproj | 5 ++++ TestApp/TestApp.pidb | Bin 2991 -> 3039 bytes TestApp/bin/Debug/NW4RTools.dll | Bin 166400 -> 173568 bytes TestApp/bin/Debug/NW4RTools.dll.mdb | Bin 90788 -> 93825 bytes TestApp/bin/Debug/OpenTK.dll | Bin 0 -> 2719744 bytes TestApp/bin/Debug/OpenTK.dll.config | 12 ++++++++ TestApp/bin/Debug/TestApp.exe | Bin 4608 -> 5632 bytes TestApp/bin/Debug/TestApp.exe.mdb | Bin 548 -> 992 bytes 10 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 TestApp/RenderWindow.cs create mode 100644 TestApp/bin/Debug/OpenTK.dll create mode 100644 TestApp/bin/Debug/OpenTK.dll.config (limited to 'TestApp') diff --git a/TestApp/Main.cs b/TestApp/Main.cs index 3eb49a4..447f556 100644 --- a/TestApp/Main.cs +++ b/TestApp/Main.cs @@ -2,6 +2,9 @@ using System; using System.IO; using System.Collections.Generic; using NW4RTools; +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; namespace TestApp { class MainClass { @@ -10,13 +13,22 @@ namespace TestApp { string mdlName = "CS_W1"; //string mdlName = "bgB_4502"; + //string mdlName = "cobKoopaCastle"; string whatever = (mdlName == "CS_W2" || mdlName == "CS_W3" || mdlName == "CS_W6") ? "a" : ""; byte[] file = File.ReadAllBytes(mdlPath + mdlName + ".brres"); ResFile rf = BrresReader.LoadFile(file); - var texs = rf.GetGroup("Textures(NW4R)"); + using (var gw = new RenderWindow()) { + gw.Title = mdlName; + gw.SetModel(rf, mdlName); + gw.Run(1, 1); + } + + + + /*var texs = rf.GetGroup("Textures(NW4R)"); // wtf C#?! foreach (var kv in (IEnumerable>)texs) { kv.Value.BaseImage.Save(mdlPath + "images/" + kv.Key + ".png"); @@ -27,7 +39,7 @@ namespace TestApp { //var sw = new StreamWriter(objFile); //ObjWriter.WriteModel(sw, rf, mdlName); ColladaWriter.WriteModel(objFile, rf, mdlName + whatever); - objFile.Close(); + objFile.Close();*/ } } } 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(); + } + + + } +} + diff --git a/TestApp/TestApp.csproj b/TestApp/TestApp.csproj index 5c96e3b..e979782 100644 --- a/TestApp/TestApp.csproj +++ b/TestApp/TestApp.csproj @@ -31,10 +31,15 @@ + + False + ..\..\CSharp\opentk\Binaries\OpenTK\Release\OpenTK.dll + + diff --git a/TestApp/TestApp.pidb b/TestApp/TestApp.pidb index bf2fb29..4b3557d 100644 Binary files a/TestApp/TestApp.pidb and b/TestApp/TestApp.pidb differ diff --git a/TestApp/bin/Debug/NW4RTools.dll b/TestApp/bin/Debug/NW4RTools.dll index 91a4b75..dbcb459 100755 Binary files a/TestApp/bin/Debug/NW4RTools.dll and b/TestApp/bin/Debug/NW4RTools.dll differ diff --git a/TestApp/bin/Debug/NW4RTools.dll.mdb b/TestApp/bin/Debug/NW4RTools.dll.mdb index 127ef0f..b67ce24 100644 Binary files a/TestApp/bin/Debug/NW4RTools.dll.mdb and b/TestApp/bin/Debug/NW4RTools.dll.mdb differ diff --git a/TestApp/bin/Debug/OpenTK.dll b/TestApp/bin/Debug/OpenTK.dll new file mode 100644 index 0000000..afff0dd Binary files /dev/null and b/TestApp/bin/Debug/OpenTK.dll differ diff --git a/TestApp/bin/Debug/OpenTK.dll.config b/TestApp/bin/Debug/OpenTK.dll.config new file mode 100644 index 0000000..99aef86 --- /dev/null +++ b/TestApp/bin/Debug/OpenTK.dll.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/TestApp/bin/Debug/TestApp.exe b/TestApp/bin/Debug/TestApp.exe index 1bce1bb..bafaf4c 100755 Binary files a/TestApp/bin/Debug/TestApp.exe and b/TestApp/bin/Debug/TestApp.exe differ diff --git a/TestApp/bin/Debug/TestApp.exe.mdb b/TestApp/bin/Debug/TestApp.exe.mdb index 00eab08..3f3b216 100644 Binary files a/TestApp/bin/Debug/TestApp.exe.mdb and b/TestApp/bin/Debug/TestApp.exe.mdb differ -- cgit v1.2.3