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