OSDN Git Service

Added temporary controls for light testing.
authorLatif Khalifa <latifer@streamgrid.net>
Mon, 4 Jul 2011 02:57:16 +0000 (02:57 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Mon, 4 Jul 2011 02:57:16 +0000 (02:57 +0000)
Cleanup color setting.
Made unified section for HUD drawing,

git-svn-id: https://radegast.googlecode.com/svn/trunk@940 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/GUI/Rendering/Rendering.Designer.cs
Radegast/GUI/Rendering/Rendering.cs

index 68f036c..878976e 100644 (file)
@@ -60,13 +60,14 @@ namespace Radegast.Rendering
         {\r
             this.components = new System.ComponentModel.Container();\r
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SceneWindow));\r
-            this.scrollZoom = new System.Windows.Forms.HScrollBar();\r
             this.gbZoom = new System.Windows.Forms.GroupBox();\r
+            this.hsSpecular = new System.Windows.Forms.HScrollBar();\r
+            this.hsDiffuse = new System.Windows.Forms.HScrollBar();\r
+            this.hsAmbient = new System.Windows.Forms.HScrollBar();\r
             this.label2 = new System.Windows.Forms.Label();\r
             this.btnResetView = new System.Windows.Forms.Button();\r
             this.cbAA = new System.Windows.Forms.CheckBox();\r
             this.chkWireFrame = new System.Windows.Forms.CheckBox();\r
-            this.label1 = new System.Windows.Forms.Label();\r
             this.ctxObjects = new System.Windows.Forms.ContextMenuStrip(this.components);\r
             this.touchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
             this.sitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
@@ -78,32 +79,49 @@ namespace Radegast.Rendering
             this.ctxObjects.SuspendLayout();\r
             this.SuspendLayout();\r
             // \r
-            // scrollZoom\r
-            // \r
-            this.scrollZoom.LargeChange = 1;\r
-            this.scrollZoom.Location = new System.Drawing.Point(428, 8);\r
-            this.scrollZoom.Maximum = 0;\r
-            this.scrollZoom.Minimum = -300;\r
-            this.scrollZoom.Name = "scrollZoom";\r
-            this.scrollZoom.Size = new System.Drawing.Size(200, 16);\r
-            this.scrollZoom.TabIndex = 19;\r
-            this.scrollZoom.ValueChanged += new System.EventHandler(this.scrollZoom_ValueChanged);\r
-            // \r
             // gbZoom\r
             // \r
+            this.gbZoom.Controls.Add(this.hsSpecular);\r
+            this.gbZoom.Controls.Add(this.hsDiffuse);\r
+            this.gbZoom.Controls.Add(this.hsAmbient);\r
             this.gbZoom.Controls.Add(this.label2);\r
             this.gbZoom.Controls.Add(this.btnResetView);\r
             this.gbZoom.Controls.Add(this.cbAA);\r
             this.gbZoom.Controls.Add(this.chkWireFrame);\r
-            this.gbZoom.Controls.Add(this.label1);\r
-            this.gbZoom.Controls.Add(this.scrollZoom);\r
             this.gbZoom.Dock = System.Windows.Forms.DockStyle.Bottom;\r
-            this.gbZoom.Location = new System.Drawing.Point(0, 546);\r
+            this.gbZoom.Location = new System.Drawing.Point(0, 516);\r
             this.gbZoom.Name = "gbZoom";\r
-            this.gbZoom.Size = new System.Drawing.Size(644, 59);\r
+            this.gbZoom.Size = new System.Drawing.Size(644, 89);\r
             this.gbZoom.TabIndex = 8;\r
             this.gbZoom.TabStop = false;\r
             // \r
+            // hsSpecular\r
+            // \r
+            this.hsSpecular.Location = new System.Drawing.Point(343, 50);\r
+            this.hsSpecular.Name = "hsSpecular";\r
+            this.hsSpecular.Size = new System.Drawing.Size(292, 17);\r
+            this.hsSpecular.TabIndex = 24;\r
+            this.hsSpecular.Value = 30;\r
+            this.hsSpecular.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsSpecular_Scroll);\r
+            // \r
+            // hsDiffuse\r
+            // \r
+            this.hsDiffuse.Location = new System.Drawing.Point(343, 33);\r
+            this.hsDiffuse.Name = "hsDiffuse";\r
+            this.hsDiffuse.Size = new System.Drawing.Size(292, 17);\r
+            this.hsDiffuse.TabIndex = 24;\r
+            this.hsDiffuse.Value = 25;\r
+            this.hsDiffuse.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsDiffuse_Scroll);\r
+            // \r
+            // hsAmbient\r
+            // \r
+            this.hsAmbient.Location = new System.Drawing.Point(343, 16);\r
+            this.hsAmbient.Name = "hsAmbient";\r
+            this.hsAmbient.Size = new System.Drawing.Size(292, 17);\r
+            this.hsAmbient.TabIndex = 24;\r
+            this.hsAmbient.Value = 20;\r
+            this.hsAmbient.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hsAmbient_Scroll);\r
+            // \r
             // label2\r
             // \r
             this.label2.AutoSize = true;\r
@@ -144,15 +162,6 @@ namespace Radegast.Rendering
             this.chkWireFrame.UseVisualStyleBackColor = true;\r
             this.chkWireFrame.CheckedChanged += new System.EventHandler(this.chkWireFrame_CheckedChanged);\r
             // \r
-            // label1\r
-            // \r
-            this.label1.AutoSize = true;\r
-            this.label1.Location = new System.Drawing.Point(385, 8);\r
-            this.label1.Name = "label1";\r
-            this.label1.Size = new System.Drawing.Size(34, 13);\r
-            this.label1.TabIndex = 20;\r
-            this.label1.Text = "Zoom";\r
-            // \r
             // ctxObjects\r
             // \r
             this.ctxObjects.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {\r
@@ -225,12 +234,10 @@ namespace Radegast.Rendering
 \r
         #endregion\r
 \r
-        public System.Windows.Forms.HScrollBar scrollZoom;\r
         public System.Windows.Forms.GroupBox gbZoom;\r
         public System.Windows.Forms.ContextMenuStrip ctxObjects;\r
         public System.Windows.Forms.CheckBox cbAA;\r
         public System.Windows.Forms.CheckBox chkWireFrame;\r
-        public System.Windows.Forms.Label label1;\r
         public System.Windows.Forms.Button btnResetView;\r
         public System.Windows.Forms.Label label2;\r
         public System.Windows.Forms.ToolStripMenuItem touchToolStripMenuItem;\r
@@ -239,6 +246,9 @@ namespace Radegast.Rendering
         public System.Windows.Forms.ToolStripMenuItem takeToolStripMenuItem;\r
         public System.Windows.Forms.ToolStripMenuItem returnToolStripMenuItem;\r
         public System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;\r
+        private System.Windows.Forms.HScrollBar hsSpecular;\r
+        private System.Windows.Forms.HScrollBar hsDiffuse;\r
+        private System.Windows.Forms.HScrollBar hsAmbient;\r
 \r
     }\r
 }\r
index 4fbeca2..4b42663 100644 (file)
@@ -96,7 +96,7 @@ namespace Radegast.Rendering
         OpenTK.Graphics.GraphicsMode GLMode = null;\r
         AutoResetEvent TextureThreadContextReady = new AutoResetEvent(false);\r
         BlockingQueue<TextureLoadItem> PendingTextures = new BlockingQueue<TextureLoadItem>();\r
-        float[] lightPos = new float[] { 0f, 0f, 1f, 0f };\r
+\r
         bool hasMipmap;\r
         Font HoverTextFont = new Font(FontFamily.GenericSansSerif, 9f, FontStyle.Regular);\r
         Font AvatarTagFont = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);\r
@@ -109,6 +109,14 @@ namespace Radegast.Rendering
         double lastFrameTime = 0d;\r
         double advTimerTick = 0d;\r
 \r
+        float[] lightPos = new float[] { 128f, 128f, 5000f, 0f };\r
+        float ambient = 0.26f;\r
+        float difuse = 0.27f;\r
+        float specular = 0.20f;\r
+        OpenTK.Vector4 ambientColor;\r
+        OpenTK.Vector4 difuseColor;\r
+        OpenTK.Vector4 specularColor;\r
+\r
         #endregion Private fields\r
 \r
         #region Construction and disposal\r
@@ -377,27 +385,35 @@ namespace Radegast.Rendering
             glControl.Disposed -= glControl_Disposed;\r
         }\r
 \r
+        void SetSun()\r
+        {\r
+            ambientColor = new OpenTK.Vector4(ambient, ambient, ambient, difuse);\r
+            difuseColor = new OpenTK.Vector4(difuse, difuse, difuse, difuse);\r
+            specularColor = new OpenTK.Vector4(specular, specular, specular, specular);\r
+            GL.Light(LightName.Light0, LightParameter.Ambient, ambientColor);\r
+            GL.Light(LightName.Light0, LightParameter.Diffuse, difuseColor);\r
+            GL.Light(LightName.Light0, LightParameter.Specular, specularColor);\r
+            GL.Light(LightName.Light0, LightParameter.Position, lightPos);\r
+        }\r
+\r
         void glControl_Load(object sender, EventArgs e)\r
         {\r
             try\r
             {\r
                 GL.ShadeModel(ShadingModel.Smooth);\r
 \r
-                //GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 0.5f, 0.5f, 0.5f, 1.0f });\r
-\r
                 GL.Enable(EnableCap.Lighting);\r
                 GL.Enable(EnableCap.Light0);\r
-                GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0.5f, 0.5f, 0.5f, 1f });\r
-                GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 0.3f, 0.3f, 0.3f, 1f });\r
-                GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 0.8f, 0.8f, 0.8f, 1.0f });\r
-                GL.Light(LightName.Light0, LightParameter.Position, lightPos);\r
+                SetSun();\r
 \r
                 GL.ClearDepth(1.0d);\r
                 GL.Enable(EnableCap.DepthTest);\r
                 GL.Enable(EnableCap.CullFace);\r
                 GL.CullFace(CullFaceMode.Back);\r
+\r
+                // GL.Color() tracks objects ambient and diffuse color\r
+                GL.Enable(EnableCap.ColorMaterial);\r
                 GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.AmbientAndDiffuse);\r
-                GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.Specular);\r
 \r
                 GL.DepthMask(true);\r
                 GL.DepthFunc(DepthFunction.Lequal);\r
@@ -505,14 +521,6 @@ namespace Radegast.Rendering
 \r
         private void glControl_MouseWheel(object sender, MouseEventArgs e)\r
         {\r
-            int newVal = Utils.Clamp(scrollZoom.Value + e.Delta / 10, scrollZoom.Minimum, scrollZoom.Maximum);\r
-\r
-            if (scrollZoom.Value != newVal)\r
-            {\r
-                Camera.Zoom = 1f - (float)newVal / (float)scrollZoom.Minimum;\r
-                scrollZoom.Value = newVal;\r
-                glControl_Resize(null, null);\r
-            }\r
         }\r
 \r
         FacetedMesh RightclickedPrim;\r
@@ -730,7 +738,7 @@ namespace Radegast.Rendering
                 {\r
                     item.Data.TextureInfo = TexturesPtrMap[item.TeFace.TextureID];\r
                     GL.BindTexture(TextureTarget.Texture2D, item.Data.TextureInfo.TexturePointer);\r
-                    \r
+\r
                     continue;\r
                 }\r
 \r
@@ -830,7 +838,7 @@ namespace Radegast.Rendering
                 else if (Avatars.TryGetValue(prim.ParentID, out parentav))\r
                 {\r
                     var avPos = PrimPos(parentav.avatar);\r
-                    \r
+\r
                     return avPos + prim.Position * Matrix4.CreateFromQuaternion(parentav.avatar.Rotation);\r
                 }\r
                 else\r
@@ -859,9 +867,8 @@ namespace Radegast.Rendering
             // This is a FIR filter known as a MMA or Modified Mean Average, using a 20 point sampling width\r
             advTimerTick = ((19 * advTimerTick) + lastFrameTime) / 20;\r
 \r
-            GL.Color4(0f, 0f, 0f, 0.6f);\r
             Printer.Begin();\r
-            Printer.Print(String.Format("FPS {0:000.00}",1d/advTimerTick), AvatarTagFont, Color.Orange,\r
+            Printer.Print(String.Format("FPS {0:000.00}", 1d / advTimerTick), AvatarTagFont, Color.Orange,\r
                 new RectangleF(posX, posY, 100, 50),\r
                 OpenTK.Graphics.TextPrinterOptions.Default, OpenTK.Graphics.TextAlignment.Center);\r
             Printer.End();\r
@@ -869,8 +876,6 @@ namespace Radegast.Rendering
 \r
         private void RenderText()\r
         {\r
-            GLHUDBegin();\r
-\r
             lock (Avatars)\r
             {\r
 \r
@@ -916,7 +921,6 @@ namespace Radegast.Rendering
                         Printer.End();\r
                     }\r
                 }\r
-                GL.Color3(1, 1, 1);\r
             }\r
 \r
             lock (Prims)\r
@@ -967,7 +971,6 @@ namespace Radegast.Rendering
                     }\r
                 }\r
             }\r
-            GLHUDEnd();\r
         }\r
 \r
         #region avatars\r
@@ -1055,7 +1058,7 @@ namespace Radegast.Rendering
                             GL.MultMatrix(Math3D.CreateTranslationMatrix(av.avatar.Position));\r
                             GL.MultMatrix(Math3D.CreateRotationMatrix(av.avatar.Rotation));\r
 \r
-                            \r
+\r
                             // Special case for eyeballs we need to offset the mesh to the correct position\r
                             // We have manually added the eyeball offset based on the headbone when we\r
                             // constructed the meshes, but why are the position offsets we got when loading\r
@@ -1125,7 +1128,6 @@ namespace Radegast.Rendering
                         }\r
                     }\r
                 }\r
-                GL.Color3(1f, 1f, 1f);\r
                 GL.DisableClientState(ArrayCap.VertexArray);\r
                 GL.DisableClientState(ArrayCap.TextureCoordArray);\r
             }\r
@@ -1184,6 +1186,7 @@ namespace Radegast.Rendering
 \r
         private void UpdateTerrain()\r
         {\r
+            if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Terrain == null) return;\r
             int step = 1;\r
 \r
             for (int x = 0; x < 255; x += step)\r
@@ -1192,8 +1195,7 @@ namespace Radegast.Rendering
                 {\r
                     float z = 0;\r
                     int patchNr = ((int)x / 16) * 16 + (int)y / 16;\r
-                    if (Client.Network.CurrentSim.Terrain != null\r
-                        && Client.Network.CurrentSim.Terrain[patchNr] != null\r
+                    if (Client.Network.CurrentSim.Terrain[patchNr] != null\r
                         && Client.Network.CurrentSim.Terrain[patchNr].Data != null)\r
                     {\r
                         float[] data = Client.Network.CurrentSim.Terrain[patchNr].Data;\r
@@ -1231,6 +1233,7 @@ namespace Radegast.Rendering
 \r
         private void RenderTerrain()\r
         {\r
+            GL.Color3(1f, 1f, 1f);\r
             GL.EnableClientState(ArrayCap.VertexArray);\r
             GL.EnableClientState(ArrayCap.TextureCoordArray);\r
             GL.EnableClientState(ArrayCap.NormalArray);\r
@@ -1335,7 +1338,6 @@ namespace Radegast.Rendering
                 GL.EnableClientState(ArrayCap.TextureCoordArray);\r
                 GL.EnableClientState(ArrayCap.NormalArray);\r
 \r
-                GL.Enable(EnableCap.ColorMaterial);\r
                 int primNr = 0;\r
                 foreach (FacetedMesh mesh in Prims.Values)\r
                 {\r
@@ -1372,7 +1374,7 @@ namespace Radegast.Rendering
                             }\r
 \r
                             attachment_point apoint = GLAvatar.attachment_points[attachment_index];\r
-                            \r
+\r
                             Vector3 point = Bone.getOffset(apoint.joint);\r
                             Vector3 rot = Bone.getRotation(apoint.joint);\r
                             //Todo Quaternion should be retured from getRotation()\r
@@ -1417,15 +1419,15 @@ namespace Radegast.Rendering
                             switch (teFace.Shiny)\r
                             {\r
                                 case Shininess.High:\r
-                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 94f);\r
+                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 0.94f);\r
                                     break;\r
 \r
                                 case Shininess.Medium:\r
-                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 64f);\r
+                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 0.64f);\r
                                     break;\r
 \r
                                 case Shininess.Low:\r
-                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 24f);\r
+                                    GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 0.24f);\r
                                     break;\r
 \r
 \r
@@ -1436,10 +1438,9 @@ namespace Radegast.Rendering
                             }\r
 \r
                             var faceColor = new float[] { teFace.RGBA.R, teFace.RGBA.G, teFace.RGBA.B, teFace.RGBA.A };\r
-\r
                             GL.Color4(faceColor);\r
-                            GL.Material(MaterialFace.Front, MaterialParameter.AmbientAndDiffuse, faceColor);\r
-                            GL.Material(MaterialFace.Front, MaterialParameter.Specular, faceColor);\r
+\r
+                            GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[] { 0.5f, 0.5f, 0.5f, 1f });\r
 \r
                             if (data.TextureInfo.TexturePointer != 0)\r
                             {\r
@@ -1457,7 +1458,6 @@ namespace Radegast.Rendering
                             data.PickingID = primNr;\r
                             var primNrBytes = Utils.Int16ToBytes((short)primNr);\r
                             var faceColor = new byte[] { primNrBytes[0], primNrBytes[1], (byte)j, 255 };\r
-\r
                             GL.Color4(faceColor);\r
                         }\r
 \r
@@ -1495,13 +1495,11 @@ namespace Radegast.Rendering
                     }\r
 \r
                     GL.BindTexture(TextureTarget.Texture2D, 0);\r
-                    GL.Color4(new byte[] { 255, 255, 255, 255 });\r
                     ResetMaterial();\r
 \r
                     // Pop the prim matrix\r
                     GL.PopMatrix();\r
                 }\r
-                GL.Disable(EnableCap.ColorMaterial);\r
                 GL.DisableClientState(ArrayCap.VertexArray);\r
                 GL.DisableClientState(ArrayCap.TextureCoordArray);\r
                 GL.DisableClientState(ArrayCap.NormalArray);\r
@@ -1521,7 +1519,7 @@ namespace Radegast.Rendering
             float z = Client.Network.CurrentSim.WaterHeight;\r
 \r
             GL.Disable(EnableCap.Lighting);\r
-            GL.Enable(EnableCap.ColorMaterial);\r
+\r
             GL.Color4(0.09f, 0.28f, 0.63f, 0.84f);\r
 \r
             GL.Begin(BeginMode.Quads);\r
@@ -1530,9 +1528,7 @@ namespace Radegast.Rendering
                     DrawWaterQuad(x, y, z);\r
             GL.End();\r
 \r
-            GL.Color3(1f, 1f, 1f);\r
             GL.Enable(EnableCap.Lighting);\r
-            GL.Disable(EnableCap.ColorMaterial);\r
         }\r
 \r
         private void Render(bool picking)\r
@@ -1565,7 +1561,7 @@ namespace Radegast.Rendering
                     0d, 0d, 1d);\r
             GL.MultMatrix(ref mLookAt);\r
 \r
-            //GL.Light(LightName.Light0, LightParameter.Position, lightPos);\r
+            GL.Light(LightName.Light0, LightParameter.Position, lightPos);\r
 \r
             // Push the world matrix\r
             GL.PushMatrix();\r
@@ -1593,8 +1589,11 @@ namespace Radegast.Rendering
 \r
                 RenderWater();\r
                 RenderObjects(RenderPass.Alpha);\r
+\r
+                GLHUDBegin();\r
                 RenderText();\r
                 RenderStats();\r
+                GLHUDEnd();\r
             }\r
 \r
             // Pop the world matrix\r
@@ -1910,12 +1909,6 @@ namespace Radegast.Rendering
         #endregion Private methods (the meat)\r
 \r
         #region Form controls handlers\r
-        private void scrollZoom_ValueChanged(object sender, EventArgs e)\r
-        {\r
-            Camera.Zoom = 1f - (float)scrollZoom.Value / (float)scrollZoom.Minimum;\r
-            glControl_Resize(null, null);\r
-        }\r
-\r
         private void chkWireFrame_CheckedChanged(object sender, EventArgs e)\r
         {\r
             Wireframe = chkWireFrame.Checked;\r
@@ -1924,7 +1917,6 @@ namespace Radegast.Rendering
         private void btnReset_Click(object sender, EventArgs e)\r
         {\r
             InitCamera();\r
-            scrollZoom.Value = 0;\r
         }\r
 \r
         private void cbAA_CheckedChanged(object sender, EventArgs e)\r
@@ -2009,5 +2001,23 @@ namespace Radegast.Rendering
             Close();\r
         }\r
         #endregion Context menu\r
+\r
+        private void hsAmbient_Scroll(object sender, ScrollEventArgs e)\r
+        {\r
+            ambient = (float)hsAmbient.Value / 100f;\r
+            SetSun();\r
+        }\r
+\r
+        private void hsDiffuse_Scroll(object sender, ScrollEventArgs e)\r
+        {\r
+            difuse = (float)hsDiffuse.Value / 100f;\r
+            SetSun();\r
+        }\r
+\r
+        private void hsSpecular_Scroll(object sender, ScrollEventArgs e)\r
+        {\r
+            specular = (float)hsSpecular.Value / 100f;\r
+            SetSun();\r
+        }\r
     }\r
 }\r