diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs index f4864d91..34a220a8 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs @@ -60,9 +60,7 @@ this.comboParent = new System.Windows.Forms.ComboBox(); this.buttonEXPORT = new System.Windows.Forms.Button(); this.buttonIMPORT = new System.Windows.Forms.Button(); - this.uvPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); this.buttonImportModel = new System.Windows.Forms.Button(); - this.displayBox = new System.Windows.Forms.PictureBox(); this.buttonExportModel = new System.Windows.Forms.Button(); this.OpenJSONButton = new System.Windows.Forms.Button(); this.buttonTemplate = new MetroFramework.Controls.MetroButton(); @@ -87,6 +85,8 @@ this.U = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.V = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.listViewBoxes = new System.Windows.Forms.ListView(); + this.renderer3D1 = new PckStudio.Rendering.Renderer3D(); + this.uvPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); label6 = new System.Windows.Forms.Label(); label5 = new System.Windows.Forms.Label(); label3 = new System.Windows.Forms.Label(); @@ -97,8 +97,6 @@ this.tabBody.SuspendLayout(); this.tabPage1.SuspendLayout(); this.myTablePanel2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.displayBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeXUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeYUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeZUpDown)).BeginInit(); @@ -107,6 +105,7 @@ ((System.ComponentModel.ISupportInitialize)(this.PosZUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PosYUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PosXUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); this.SuspendLayout(); // // label6 @@ -325,14 +324,6 @@ this.buttonIMPORT.UseVisualStyleBackColor = true; this.buttonIMPORT.Click += new System.EventHandler(this.buttonIMPORT_Click); // - // uvPictureBox - // - this.uvPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - resources.ApplyResources(this.uvPictureBox, "uvPictureBox"); - this.uvPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.uvPictureBox.Name = "uvPictureBox"; - this.uvPictureBox.TabStop = false; - // // buttonImportModel // resources.ApplyResources(this.buttonImportModel, "buttonImportModel"); @@ -341,14 +332,6 @@ this.buttonImportModel.UseVisualStyleBackColor = true; this.buttonImportModel.Click += new System.EventHandler(this.buttonImportModel_Click); // - // displayBox - // - this.displayBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(50)))), ((int)(((byte)(50))))); - this.displayBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - resources.ApplyResources(this.displayBox, "displayBox"); - this.displayBox.Name = "displayBox"; - this.displayBox.TabStop = false; - // // buttonExportModel // resources.ApplyResources(this.buttonExportModel, "buttonExportModel"); @@ -555,10 +538,44 @@ this.listViewBoxes.DoubleClick += new System.EventHandler(this.listView1_DoubleClick); this.listViewBoxes.KeyDown += new System.Windows.Forms.KeyEventHandler(this.delStuffUsingDelKey); // + // renderer3D1 + // + resources.ApplyResources(this.renderer3D1, "renderer3D1"); + this.renderer3D1.BackColor = System.Drawing.Color.DarkGray; + this.renderer3D1.CameraDistance = 72F; + this.renderer3D1.LookAngle = ((OpenTK.Vector2)(resources.GetObject("renderer3D1.LookAngle"))); + this.renderer3D1.Model = PckStudio.Rendering.Renderer3D.Models.Steve; + this.renderer3D1.Name = "renderer3D1"; + this.renderer3D1.Rotation = ((OpenTK.Vector2)(resources.GetObject("renderer3D1.Rotation"))); + this.renderer3D1.ShowBody = true; + this.renderer3D1.ShowBodyOverlay = true; + this.renderer3D1.ShowHead = true; + this.renderer3D1.ShowHeadOverlay = true; + this.renderer3D1.ShowLeftArm = true; + this.renderer3D1.ShowLeftArmOverlay = true; + this.renderer3D1.ShowLeftLeg = true; + this.renderer3D1.ShowLeftLegOverlay = true; + this.renderer3D1.ShowRightArm = true; + this.renderer3D1.ShowRightArmOverlay = true; + this.renderer3D1.ShowRightLeg = true; + this.renderer3D1.ShowRightLegOverlay = true; + this.renderer3D1.Texture = null; + this.renderer3D1.VSync = true; + this.renderer3D1.FieldOfView = 1D; + // + // uvPictureBox + // + this.uvPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + resources.ApplyResources(this.uvPictureBox, "uvPictureBox"); + this.uvPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + this.uvPictureBox.Name = "uvPictureBox"; + this.uvPictureBox.TabStop = false; + // // generateModel // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.renderer3D1); this.Controls.Add(this.PosZUpDown); this.Controls.Add(this.PosYUpDown); this.Controls.Add(this.PosXUpDown); @@ -571,7 +588,6 @@ this.Controls.Add(this.checkGuide); this.Controls.Add(this.generateTextureCheckBox); this.Controls.Add(this.buttonTemplate); - this.Controls.Add(this.displayBox); this.Controls.Add(this.listViewBoxes); this.Controls.Add(this.OpenJSONButton); this.Controls.Add(this.buttonExportModel); @@ -603,8 +619,6 @@ this.tabPage1.ResumeLayout(false); this.myTablePanel2.ResumeLayout(false); this.myTablePanel2.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.displayBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeXUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeYUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeZUpDown)).EndInit(); @@ -613,6 +627,7 @@ ((System.ComponentModel.ISupportInitialize)(this.PosZUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PosYUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PosXUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -627,7 +642,6 @@ private System.Windows.Forms.Button buttonDone; private System.Windows.Forms.Button OpenJSONButton; private System.Windows.Forms.Button buttonExportModel; - private System.Windows.Forms.PictureBox displayBox; private System.Windows.Forms.Button buttonImportModel; private PckStudio.ToolboxItems.InterpolationPictureBox uvPictureBox; private System.Windows.Forms.Button buttonIMPORT; @@ -671,5 +685,6 @@ private System.Windows.Forms.ColumnHeader U; private System.Windows.Forms.ColumnHeader V; private System.Windows.Forms.ListView listViewBoxes; + private Rendering.Renderer3D renderer3D1; } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index 64e7dadb..f3b04435 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -134,10 +134,7 @@ namespace PckStudio.Forms _file = file; if (file.Size > 0) { - using (var ms = new MemoryStream(file.Data)) - { - uvPictureBox.Image = Image.FromStream(ms); - } + uvPictureBox.Image = renderer3D1.Texture = file.GetTexture() as Bitmap; } comboParent.Items.Clear(); comboParent.Items.AddRange(ValidModelBoxTypes); @@ -195,352 +192,350 @@ namespace PckStudio.Forms GenerateUVTextureMap(); } - // Graphic Rendering - // Builds an image based on the view private void Render(object sender, EventArgs e) { - buttonTemplate.Enabled = listViewBoxes.Items.Count == 0; - OrganizesZLayer(); - Bitmap bitmapModelPreview = new Bitmap(displayBox.Width, displayBox.Height); // Creates Model Display layer - using (Graphics graphics = Graphics.FromImage(bitmapModelPreview)) - { - graphics.ApplyConfig(_graphicsConfig); - graphics.Clear(_backgroundColor); + //buttonTemplate.Enabled = listViewBoxes.Items.Count == 0; + //OrganizesZLayer(); + //Bitmap bitmapModelPreview = new Bitmap(displayBox.Width, displayBox.Height); // Creates Model Display layer + //using (Graphics graphics = Graphics.FromImage(bitmapModelPreview)) + //{ + // graphics.ApplyConfig(_graphicsConfig); + // graphics.Clear(_backgroundColor); - float headbodyY = (displayBox.Height / 2) + 25; // 25 - float armY = (displayBox.Height / 2) + 35; // -60; - float legY = (displayBox.Height / 2) + 85; // -80; - float groundLevel = (displayBox.Height / 2) + 145; - graphics.DrawLine(Pens.White, 0, groundLevel, displayBox.Width, groundLevel); - float renderScale = uvPictureBox.Image.Width / 64; // used for displaying larger graphics properly; 64 is the base skin width for all models + // float headbodyY = (displayBox.Height / 2) + 25; // 25 + // float armY = (displayBox.Height / 2) + 35; // -60; + // float legY = (displayBox.Height / 2) + 85; // -80; + // float groundLevel = (displayBox.Height / 2) + 145; + // graphics.DrawLine(Pens.White, 0, groundLevel, displayBox.Width, groundLevel); + // float renderScale = uvPictureBox.Image.Width / 64; // used for displaying larger graphics properly; 64 is the base skin width for all models - // Chooses Render settings based on current direction - foreach (ListViewItem listViewItem in listViewBoxes.Items) - { - if (!(listViewItem.Tag is SkinBOX part)) - continue; - float x = displayBox.Width / 2; - float y = 0; + // // Chooses Render settings based on current direction + // foreach (ListViewItem listViewItem in listViewBoxes.Items) + // { + // if (!(listViewItem.Tag is SkinBOX part)) + // continue; + // float x = displayBox.Width / 2; + // float y = 0; - switch (direction) - { - case ViewDirection.front: - { - //Sets X & Y based on model part class - // listViewItem.Text -> part.Type - // listViewItem.SubItems[1] -> part.Pos.X - // listViewItem.SubItems[2] -> part.Pos.Y - // listViewItem.SubItems[3] -> part.Pos.Z - // listViewItem.SubItems[4] -> part.Size.X - // listViewItem.SubItems[5] -> part.Size.Y - // listViewItem.SubItems[6] -> part.Size.Z - // listViewItem.SubItems[7] -> part.U - // listViewItem.SubItems[8] -> part.V - switch (part.Type) - { - case "HEAD": - case "HEADWEAR": - case "HELMET": - y = headbodyY + int.Parse(offsetHead.Text) * 5; - break; - case "BODY": - case "JACKET": - case "CHEST": - case "BODYARMOR": - case "BELT": - case "WAIST": - y = headbodyY + int.Parse(offsetBody.Text) * 5; - break; + // switch (direction) + // { + // case ViewDirection.front: + // { + // //Sets X & Y based on model part class + // // listViewItem.Text -> part.Type + // // listViewItem.SubItems[1] -> part.Pos.X + // // listViewItem.SubItems[2] -> part.Pos.Y + // // listViewItem.SubItems[3] -> part.Pos.Z + // // listViewItem.SubItems[4] -> part.Size.X + // // listViewItem.SubItems[5] -> part.Size.Y + // // listViewItem.SubItems[6] -> part.Size.Z + // // listViewItem.SubItems[7] -> part.U + // // listViewItem.SubItems[8] -> part.V + // switch (part.Type) + // { + // case "HEAD": + // case "HEADWEAR": + // case "HELMET": + // y = headbodyY + int.Parse(offsetHead.Text) * 5; + // break; + // case "BODY": + // case "JACKET": + // case "CHEST": + // case "BODYARMOR": + // case "BELT": + // case "WAIST": + // y = headbodyY + int.Parse(offsetBody.Text) * 5; + // break; - case "ARM0": - case "ARMARMOR0": - case "SLEEVE0": - case "SHOULDER0": - x -= 25; - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM0": + // case "ARMARMOR0": + // case "SLEEVE0": + // case "SHOULDER0": + // x -= 25; + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "ARM1": - case "ARMARMOR1": - case "SLEEVE1": - case "SHOULDER1": - x += 25; - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM1": + // case "ARMARMOR1": + // case "SLEEVE1": + // case "SHOULDER1": + // x += 25; + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "LEG0": - case "PANTS0": - case "SOCK0": - case "LEGGING0": - case "BOOT0": - x -= 10; - y = legY + int.Parse(offsetLegs.Text) * 5; - break; + // case "LEG0": + // case "PANTS0": + // case "SOCK0": + // case "LEGGING0": + // case "BOOT0": + // x -= 10; + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; - case "LEG1": - case "PANTS1": - case "SOCK1": - case "LEGGING1": - case "BOOT1": - x += 10; - y = legY + int.Parse(offsetLegs.Text) * 5; - break; - } + // case "LEG1": + // case "PANTS1": + // case "SOCK1": + // case "LEGGING1": + // case "BOOT1": + // x += 10; + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; + // } - // Maps imported Texture if texture generation is disabled - if (!generateTextureCheckBox.Checked) - { - RectangleF destRect = new RectangleF( - x + part.Pos.X * 5, - y + part.Pos.Y * 5, - part.Size.X * 5, - part.Size.Y * 5); - RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z) * renderScale, - (part.UV.Y + part.Size.Z) * renderScale, - part.Size.X * renderScale, - part.Size.Y * renderScale); - graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); - } - else - { - graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.X * 5, y + part.Pos.Y * 5, part.Size.X * 5, part.Size.Y * 5); - } + // // Maps imported Texture if texture generation is disabled + // if (!generateTextureCheckBox.Checked) + // { + // RectangleF destRect = new RectangleF( + // x + part.Pos.X * 5, + // y + part.Pos.Y * 5, + // part.Size.X * 5, + // part.Size.Y * 5); + // RectangleF srcRect = new RectangleF( + // (part.UV.X + part.Size.Z) * renderScale, + // (part.UV.Y + part.Size.Z) * renderScale, + // part.Size.X * renderScale, + // part.Size.Y * renderScale); + // graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); + // } + // else + // { + // graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.X * 5, y + part.Pos.Y * 5, part.Size.X * 5, part.Size.Y * 5); + // } - break; - } + // break; + // } - case ViewDirection.left: - { - //Sets X & Y based on model part class - switch (part.Type) - { - case "HEAD": - case "HEADWEAR": - case "HELMET": - y = headbodyY + int.Parse(offsetHead.Text) * 5; - break; - case "BODY": - case "JACKET": - case "CHEST": - case "BODYARMOR": - case "BELT": - case "WAIST": - y = headbodyY + int.Parse(offsetBody.Text) * 5; - break; + // case ViewDirection.left: + // { + // //Sets X & Y based on model part class + // switch (part.Type) + // { + // case "HEAD": + // case "HEADWEAR": + // case "HELMET": + // y = headbodyY + int.Parse(offsetHead.Text) * 5; + // break; + // case "BODY": + // case "JACKET": + // case "CHEST": + // case "BODYARMOR": + // case "BELT": + // case "WAIST": + // y = headbodyY + int.Parse(offsetBody.Text) * 5; + // break; - case "ARM0": - case "ARMARMOR0": - case "SLEEVE0": - case "SHOULDER0": - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM0": + // case "ARMARMOR0": + // case "SLEEVE0": + // case "SHOULDER0": + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "ARM1": - case "ARMARMOR1": - case "SLEEVE1": - case "SHOULDER1": - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM1": + // case "ARMARMOR1": + // case "SLEEVE1": + // case "SHOULDER1": + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "LEG0": - case "PANTS0": - case "SOCK0": - case "LEGGING0": - case "BOOT0": - y = legY + int.Parse(offsetLegs.Text) * 5; - break; + // case "LEG0": + // case "PANTS0": + // case "SOCK0": + // case "LEGGING0": + // case "BOOT0": + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; - case "LEG1": - case "PANTS1": - case "SOCK1": - case "LEGGING1": - case "BOOT1": - y = legY + int.Parse(offsetLegs.Text) * 5; - break; - } + // case "LEG1": + // case "PANTS1": + // case "SOCK1": + // case "LEGGING1": + // case "BOOT1": + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; + // } - // Maps imported Texture if auto texture is disabled - if (!generateTextureCheckBox.Checked) - { - RectangleF destRect = new RectangleF( - x + part.Pos.Z * 5, - y + part.Pos.Y * 5, - part.Size.Z * 5, - part.Size.Y * 5); - RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z + part.Size.X) * renderScale, - (part.UV.Y + part.Size.Z) * renderScale, - part.Size.Z * renderScale, - part.Size.Y * renderScale); - graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); - } - else - { - //Draws Part - graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.Z * 5, y + part.Pos.Y * 5, part.Size.Z * 5, part.Size.Y * 5); - } - bitmapModelPreview.RotateFlip(RotateFlipType.RotateNoneFlipX); - break; - } + // // Maps imported Texture if auto texture is disabled + // if (!generateTextureCheckBox.Checked) + // { + // RectangleF destRect = new RectangleF( + // x + part.Pos.Z * 5, + // y + part.Pos.Y * 5, + // part.Size.Z * 5, + // part.Size.Y * 5); + // RectangleF srcRect = new RectangleF( + // (part.UV.X + part.Size.Z + part.Size.X) * renderScale, + // (part.UV.Y + part.Size.Z) * renderScale, + // part.Size.Z * renderScale, + // part.Size.Y * renderScale); + // graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); + // } + // else + // { + // //Draws Part + // graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.Z * 5, y + part.Pos.Y * 5, part.Size.Z * 5, part.Size.Y * 5); + // } + // bitmapModelPreview.RotateFlip(RotateFlipType.RotateNoneFlipX); + // break; + // } - case ViewDirection.back: - { - //Sets X & Y based on model part class - switch (part.Type) - { - case "HEAD": - case "HEADWEAR": - case "HELMET": - y = headbodyY + int.Parse(offsetHead.Text) * 5; - break; - case "BODY": - case "JACKET": - case "CHEST": - case "BODYARMOR": - case "BELT": - case "WAIST": - y = headbodyY + int.Parse(offsetBody.Text) * 5; - break; + // case ViewDirection.back: + // { + // //Sets X & Y based on model part class + // switch (part.Type) + // { + // case "HEAD": + // case "HEADWEAR": + // case "HELMET": + // y = headbodyY + int.Parse(offsetHead.Text) * 5; + // break; + // case "BODY": + // case "JACKET": + // case "CHEST": + // case "BODYARMOR": + // case "BELT": + // case "WAIST": + // y = headbodyY + int.Parse(offsetBody.Text) * 5; + // break; - case "ARM0": - case "ARMARMOR0": - case "SLEEVE0": - case "SHOULDER0": - x -= 25; - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM0": + // case "ARMARMOR0": + // case "SLEEVE0": + // case "SHOULDER0": + // x -= 25; + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "ARM1": - case "ARMARMOR1": - case "SLEEVE1": - case "SHOULDER1": - x += 25; - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM1": + // case "ARMARMOR1": + // case "SLEEVE1": + // case "SHOULDER1": + // x += 25; + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "LEG0": - case "PANTS0": - case "SOCK0": - case "LEGGING0": - case "BOOT0": - x -= 10; - y = legY + int.Parse(offsetLegs.Text) * 5; - break; + // case "LEG0": + // case "PANTS0": + // case "SOCK0": + // case "LEGGING0": + // case "BOOT0": + // x -= 10; + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; - case "LEG1": - case "PANTS1": - case "SOCK1": - case "LEGGING1": - case "BOOT1": - x += 10; - y = legY + int.Parse(offsetLegs.Text) * 5; - break; - } + // case "LEG1": + // case "PANTS1": + // case "SOCK1": + // case "LEGGING1": + // case "BOOT1": + // x += 10; + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; + // } - //Maps imported Texture if auto texture is disabled - if (!generateTextureCheckBox.Checked) - { - RectangleF destRect = new RectangleF( - x + part.Pos.X * 5, - y + part.Pos.Y * 5, - part.Size.X * 5, - part.Size.Y * 5); - RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z * 2 + part.Size.X) * renderScale, - (part.UV.Y + part.Size.Z) * renderScale, - part.Size.X * renderScale, - part.Size.Y * renderScale); - graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); - } - else - { - //Draws Part - graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.X * 5, y + part.Pos.Y * 5, part.Size.X * 5, part.Size.Y * 5); - } - bitmapModelPreview.RotateFlip(RotateFlipType.RotateNoneFlipX); - break; - } + // //Maps imported Texture if auto texture is disabled + // if (!generateTextureCheckBox.Checked) + // { + // RectangleF destRect = new RectangleF( + // x + part.Pos.X * 5, + // y + part.Pos.Y * 5, + // part.Size.X * 5, + // part.Size.Y * 5); + // RectangleF srcRect = new RectangleF( + // (part.UV.X + part.Size.Z * 2 + part.Size.X) * renderScale, + // (part.UV.Y + part.Size.Z) * renderScale, + // part.Size.X * renderScale, + // part.Size.Y * renderScale); + // graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); + // } + // else + // { + // //Draws Part + // graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.X * 5, y + part.Pos.Y * 5, part.Size.X * 5, part.Size.Y * 5); + // } + // bitmapModelPreview.RotateFlip(RotateFlipType.RotateNoneFlipX); + // break; + // } - case ViewDirection.right: - //Sets X & Y based on model part class - switch (part.Type) - { - case "HEAD": - case "HEADWEAR": - case "HELMET": - y = headbodyY + int.Parse(offsetHead.Text) * 5; - break; - case "BODY": - case "JACKET": - case "CHEST": - case "BODYARMOR": - case "BELT": - case "WAIST": - y = headbodyY + int.Parse(offsetBody.Text) * 5; - break; + // case ViewDirection.right: + // //Sets X & Y based on model part class + // switch (part.Type) + // { + // case "HEAD": + // case "HEADWEAR": + // case "HELMET": + // y = headbodyY + int.Parse(offsetHead.Text) * 5; + // break; + // case "BODY": + // case "JACKET": + // case "CHEST": + // case "BODYARMOR": + // case "BELT": + // case "WAIST": + // y = headbodyY + int.Parse(offsetBody.Text) * 5; + // break; - case "ARM0": - case "ARMARMOR0": - case "SLEEVE0": - case "SHOULDER0": - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM0": + // case "ARMARMOR0": + // case "SLEEVE0": + // case "SHOULDER0": + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "ARM1": - case "ARMARMOR1": - case "SLEEVE1": - case "SHOULDER1": - y = armY + int.Parse(offsetArms.Text) * 5; - break; + // case "ARM1": + // case "ARMARMOR1": + // case "SLEEVE1": + // case "SHOULDER1": + // y = armY + int.Parse(offsetArms.Text) * 5; + // break; - case "LEG0": - case "PANTS0": - case "SOCK0": - case "LEGGING0": - case "BOOT0": - y = legY + int.Parse(offsetLegs.Text) * 5; - break; + // case "LEG0": + // case "PANTS0": + // case "SOCK0": + // case "LEGGING0": + // case "BOOT0": + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; - case "LEG1": - case "PANTS1": - case "SOCK1": - case "LEGGING1": - case "BOOT1": - y = legY + int.Parse(offsetLegs.Text) * 5; - break; - } - //Maps imported Texture if auto texture is disabled - if (!generateTextureCheckBox.Checked) - { - RectangleF destRect = new RectangleF( - x + part.Pos.Z * 5, - y + part.Pos.Y * 5, - part.Size.Z * 5, - part.Size.Y * 5); - RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z + part.Size.X) * renderScale, - (part.UV.Y + part.Size.Z) * renderScale, - part.Size.Z * renderScale, - part.Size.Y * renderScale); - graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); - } - else - { - //Draws Part - graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.Z * 5, y + part.Pos.Y * 5, part.Size.Z * 5, part.Size.Y * 5); - } - break; - } - } + // case "LEG1": + // case "PANTS1": + // case "SOCK1": + // case "LEGGING1": + // case "BOOT1": + // y = legY + int.Parse(offsetLegs.Text) * 5; + // break; + // } + // //Maps imported Texture if auto texture is disabled + // if (!generateTextureCheckBox.Checked) + // { + // RectangleF destRect = new RectangleF( + // x + part.Pos.Z * 5, + // y + part.Pos.Y * 5, + // part.Size.Z * 5, + // part.Size.Y * 5); + // RectangleF srcRect = new RectangleF( + // (part.UV.X + part.Size.Z + part.Size.X) * renderScale, + // (part.UV.Y + part.Size.Z) * renderScale, + // part.Size.Z * renderScale, + // part.Size.Y * renderScale); + // graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); + // } + // else + // { + // //Draws Part + // graphics.FillRectangle(new SolidBrush(listViewItem.ForeColor), x + part.Pos.Z * 5, y + part.Pos.Y * 5, part.Size.Z * 5, part.Size.Y * 5); + // } + // break; + // } + // } - if (checkBoxArmor.Checked) - DrawArmorOffsets(graphics); - // draw last to be on top - if (checkGuide.Checked) - DrawGuideLines(graphics); - } - displayBox.Image = bitmapModelPreview; + // if (checkBoxArmor.Checked) + // DrawArmorOffsets(graphics); + // // draw last to be on top + // if (checkGuide.Checked) + // DrawGuideLines(graphics); + //} + //displayBox.Image = bitmapModelPreview; } private void GenerateUVTextureMap() @@ -573,302 +568,305 @@ namespace PckStudio.Forms // Checks and sets Z layering private void OrganizesZLayer() { - foreach (ListViewItem listViewItem in listViewBoxes.Items) - listViewItem.SubItems.Add("unchecked"); + throw new NotImplementedException(); + //foreach (ListViewItem listViewItem in listViewBoxes.Items) + // listViewItem.SubItems.Add("unchecked"); - float surfaceCenter = displayBox.Width / 2; + //float surfaceCenter = displayBox.Width / 2; - switch (direction) - { - case ViewDirection.front: - { - foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) - { - if (listViewItemCurrent.SubItems[9].Text == "unchecked") - { - float x = 0; - if (listViewItemCurrent.Text == "HEAD") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "BODY") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "ARM0") - x = 178; - else if (listViewItemCurrent.Text == "ARM1") - x = 228; - else if (listViewItemCurrent.Text == "LEG0") - x = 193; - else if (listViewItemCurrent.Text == "LEG1") - x = 213; + //switch (direction) + //{ + // case ViewDirection.front: + // { + // foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) + // { + // if (listViewItemCurrent.SubItems[9].Text == "unchecked") + // { + // float x = 0; + // if (listViewItemCurrent.Text == "HEAD") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "BODY") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "ARM0") + // x = 178; + // else if (listViewItemCurrent.Text == "ARM1") + // x = 228; + // else if (listViewItemCurrent.Text == "LEG0") + // x = 193; + // else if (listViewItemCurrent.Text == "LEG1") + // x = 213; - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) - { - var val1 = double.Parse(listViewItemCurrent.SubItems[3].Text) + double.Parse(listViewItemCurrent.SubItems[6].Text); - var val2 = double.Parse(listViewItemComparing.SubItems[3].Text) + double.Parse(listViewItemComparing.SubItems[6].Text); - if (listViewItemComparing.SubItems[9].Text == "unchecked" && - val1 < val2) - { - if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) - { - index = listViewItemComparing.Index + 1; - flag = true; - } - } - } - listViewItemCurrent.SubItems[9].Text = "checked"; - if (flag) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - listViewItemCurrent.Remove(); - } - } - } - } - break; - case ViewDirection.right: - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) - { - if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") - { - float x = 0; - if (listViewItemCurrent.Text == "HEAD") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "BODY") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "ARM0") - x = 178; - else if (listViewItemCurrent.Text == "ARM1") - x = 228; - else if (listViewItemCurrent.Text == "LEG0") - x = 193; - else if (listViewItemCurrent.Text == "LEG1") - x = 213; - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItem2 in listViewBoxes.Items) - { - if (listViewItem2.SubItems[9].Text == "unchecked") - { - int y = 0; - if (listViewItem2.Text == "HEAD") - y = (int)surfaceCenter; - else if (listViewItem2.Text == "BODY") - y = (int)surfaceCenter; - else if (listViewItem2.Text == "ARM0") - y = 178; - else if (listViewItem2.Text == "ARM1") - y = 228; - else if (listViewItem2.Text == "LEG0") - y = 193; - else if (listViewItem2.Text == "LEG1") - y = 213; - if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) - x > (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) - { - index = listViewItem2.Index + 1; - flag = true; - } - } - } - listViewItemCurrent.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) - { - //if (selected.Index == listViewItem1.Index) - //{ - // selected = listViewItem2; - //} - } - listViewItemCurrent.Remove(); - } - } - else - { - checkedItems += 1; - } - } - } while (checkedItems < listViewBoxes.Items.Count); - } - break; - case ViewDirection.back: - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) - { - if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") - { - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) - { - if (listViewItemComparing.SubItems[9].Text == "unchecked" && (int)double.Parse(listViewItemCurrent.SubItems[3].Text) + (int)double.Parse(listViewItemCurrent.SubItems[6].Text) > (int)double.Parse(listViewItemComparing.SubItems[3].Text) + (int)double.Parse(listViewItemComparing.SubItems[6].Text)) - { - if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) - { - index = listViewItemComparing.Index + 1; - flag = true; - } - } - } - listViewItemCurrent.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) - { - //if (selected.Index == listViewItemCurrent.Index) - //{ - // selected = listViewItem2; - //} - } - listViewItemCurrent.Remove(); - } - } - else - { - checkedItems += 1; - } - } - } while (checkedItems < listViewBoxes.Items.Count); - } - break; - case ViewDirection.left: - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) - { - if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") - { - float x = 0; - if (listViewItemCurrent.Text == "HEAD") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "BODY") - x = surfaceCenter; - else if (listViewItemCurrent.Text == "ARM0") - x = 178; - else if (listViewItemCurrent.Text == "ARM1") - x = 228; - else if (listViewItemCurrent.Text == "LEG0") - x = 193; - else if (listViewItemCurrent.Text == "LEG1") - x = 213; - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItem2 in listViewBoxes.Items) - { - if (listViewItem2.SubItems[9].Text == "unchecked") - { - int y = 0; - if (listViewItem2.Text == "HEAD") - y = (int)surfaceCenter; - else if (listViewItem2.Text == "BODY") - y = (int)surfaceCenter; - else if (listViewItem2.Text == "ARM0") - y = 178; - else if (listViewItem2.Text == "ARM1") - y = 228; - else if (listViewItem2.Text == "LEG0") - y = 193; - else if (listViewItem2.Text == "LEG1") - y = 213; - if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) + x < (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) - { - index = listViewItem2.Index + 1; - flag = true; - } - } - } - listViewItemCurrent.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag == true) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) - { - //if (selected.Index == listViewItem1.Index) - //{ - // selected = listViewItem2; - //} - } - listViewItemCurrent.Remove(); - } - } - else - { - checkedItems += 1; - } - } - } while (checkedItems < listViewBoxes.Items.Count); - } - break; - default: - break; - } + // bool flag = false; + // int index = listViewItemCurrent.Index; + // foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) + // { + // var val1 = double.Parse(listViewItemCurrent.SubItems[3].Text) + double.Parse(listViewItemCurrent.SubItems[6].Text); + // var val2 = double.Parse(listViewItemComparing.SubItems[3].Text) + double.Parse(listViewItemComparing.SubItems[6].Text); + // if (listViewItemComparing.SubItems[9].Text == "unchecked" && + // val1 < val2) + // { + // if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) + // { + // index = listViewItemComparing.Index + 1; + // flag = true; + // } + // } + // } + // listViewItemCurrent.SubItems[9].Text = "checked"; + // if (flag) + // { + // ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + // listViewBoxes.Items.Insert(index, listViewItem2); + // listViewItemCurrent.Remove(); + // } + // } + // } + // } + // break; + // case ViewDirection.right: + // { + // int checkedItems = 0; + // do + // { + // foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) + // { + // if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") + // { + // float x = 0; + // if (listViewItemCurrent.Text == "HEAD") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "BODY") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "ARM0") + // x = 178; + // else if (listViewItemCurrent.Text == "ARM1") + // x = 228; + // else if (listViewItemCurrent.Text == "LEG0") + // x = 193; + // else if (listViewItemCurrent.Text == "LEG1") + // x = 213; + // bool flag = false; + // int index = listViewItemCurrent.Index; + // foreach (ListViewItem listViewItem2 in listViewBoxes.Items) + // { + // if (listViewItem2.SubItems[9].Text == "unchecked") + // { + // int y = 0; + // if (listViewItem2.Text == "HEAD") + // y = (int)surfaceCenter; + // else if (listViewItem2.Text == "BODY") + // y = (int)surfaceCenter; + // else if (listViewItem2.Text == "ARM0") + // y = 178; + // else if (listViewItem2.Text == "ARM1") + // y = 228; + // else if (listViewItem2.Text == "LEG0") + // y = 193; + // else if (listViewItem2.Text == "LEG1") + // y = 213; + // if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) - x > (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + // { + // index = listViewItem2.Index + 1; + // flag = true; + // } + // } + // } + // listViewItemCurrent.SubItems[9].Text = "checked"; + // checkedItems += 1; + // if (flag) + // { + // ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + // listViewBoxes.Items.Insert(index, listViewItem2); + // if (listViewBoxes.SelectedItems.Count != 0) + // { + // //if (selected.Index == listViewItem1.Index) + // //{ + // // selected = listViewItem2; + // //} + // } + // listViewItemCurrent.Remove(); + // } + // } + // else + // { + // checkedItems += 1; + // } + // } + // } while (checkedItems < listViewBoxes.Items.Count); + // } + // break; + // case ViewDirection.back: + // { + // int checkedItems = 0; + // do + // { + // foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) + // { + // if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") + // { + // bool flag = false; + // int index = listViewItemCurrent.Index; + // foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) + // { + // if (listViewItemComparing.SubItems[9].Text == "unchecked" && (int)double.Parse(listViewItemCurrent.SubItems[3].Text) + (int)double.Parse(listViewItemCurrent.SubItems[6].Text) > (int)double.Parse(listViewItemComparing.SubItems[3].Text) + (int)double.Parse(listViewItemComparing.SubItems[6].Text)) + // { + // if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) + // { + // index = listViewItemComparing.Index + 1; + // flag = true; + // } + // } + // } + // listViewItemCurrent.SubItems[9].Text = "checked"; + // checkedItems += 1; + // if (flag) + // { + // ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + // listViewBoxes.Items.Insert(index, listViewItem2); + // if (listViewBoxes.SelectedItems.Count != 0) + // { + // //if (selected.Index == listViewItemCurrent.Index) + // //{ + // // selected = listViewItem2; + // //} + // } + // listViewItemCurrent.Remove(); + // } + // } + // else + // { + // checkedItems += 1; + // } + // } + // } while (checkedItems < listViewBoxes.Items.Count); + // } + // break; + // case ViewDirection.left: + // { + // int checkedItems = 0; + // do + // { + // foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) + // { + // if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") + // { + // float x = 0; + // if (listViewItemCurrent.Text == "HEAD") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "BODY") + // x = surfaceCenter; + // else if (listViewItemCurrent.Text == "ARM0") + // x = 178; + // else if (listViewItemCurrent.Text == "ARM1") + // x = 228; + // else if (listViewItemCurrent.Text == "LEG0") + // x = 193; + // else if (listViewItemCurrent.Text == "LEG1") + // x = 213; + // bool flag = false; + // int index = listViewItemCurrent.Index; + // foreach (ListViewItem listViewItem2 in listViewBoxes.Items) + // { + // if (listViewItem2.SubItems[9].Text == "unchecked") + // { + // int y = 0; + // if (listViewItem2.Text == "HEAD") + // y = (int)surfaceCenter; + // else if (listViewItem2.Text == "BODY") + // y = (int)surfaceCenter; + // else if (listViewItem2.Text == "ARM0") + // y = 178; + // else if (listViewItem2.Text == "ARM1") + // y = 228; + // else if (listViewItem2.Text == "LEG0") + // y = 193; + // else if (listViewItem2.Text == "LEG1") + // y = 213; + // if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) + x < (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + // { + // index = listViewItem2.Index + 1; + // flag = true; + // } + // } + // } + // listViewItemCurrent.SubItems[9].Text = "checked"; + // checkedItems += 1; + // if (flag == true) + // { + // ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + // listViewBoxes.Items.Insert(index, listViewItem2); + // if (listViewBoxes.SelectedItems.Count != 0) + // { + // //if (selected.Index == listViewItem1.Index) + // //{ + // // selected = listViewItem2; + // //} + // } + // listViewItemCurrent.Remove(); + // } + // } + // else + // { + // checkedItems += 1; + // } + // } + // } while (checkedItems < listViewBoxes.Items.Count); + // } + // break; + // default: + // break; + //} } private void DrawGuideLines(Graphics g) { - Point center = new Point(displayBox.Height / 2, displayBox.Width / 2); - int headbodyY = center.Y + 25; //25 - int legY = center.Y + 85; // - 80; - bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; - if (!isSide) - { - g.DrawLine(Pens.Red, 0, headbodyY + float.Parse(offsetHead.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetHead.Text) * 5); - g.DrawLine(Pens.Green, 0, headbodyY + float.Parse(offsetBody.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetBody.Text) * 5); - g.DrawLine(Pens.Blue, 0, headbodyY + float.Parse(offsetArms.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetArms.Text) * 5); - g.DrawLine(Pens.Purple, 0, legY + float.Parse(offsetLegs.Text) * 5, displayBox.Width, legY + float.Parse(offsetLegs.Text) * 5); - } - g.DrawLine(Pens.Red, center.X, 0, center.X, displayBox.Height); - g.DrawLine(Pens.Blue, center.X + 30, 0, center.X + 30, displayBox.Height); - g.DrawLine(Pens.Blue, center.X - 30, 0, center.X - 30, displayBox.Height); - g.DrawLine(Pens.Purple, center.X - 10, 0, center.X - 10, displayBox.Height); - g.DrawLine(Pens.Purple, center.X + 10, 0, center .X + 10, displayBox.Height); + throw new NotImplementedException(); + //Point center = new Point(displayBox.Height / 2, displayBox.Width / 2); + //int headbodyY = center.Y + 25; //25 + //int legY = center.Y + 85; // - 80; + //bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; + //if (!isSide) + //{ + // g.DrawLine(Pens.Red, 0, headbodyY + float.Parse(offsetHead.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetHead.Text) * 5); + // g.DrawLine(Pens.Green, 0, headbodyY + float.Parse(offsetBody.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetBody.Text) * 5); + // g.DrawLine(Pens.Blue, 0, headbodyY + float.Parse(offsetArms.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetArms.Text) * 5); + // g.DrawLine(Pens.Purple, 0, legY + float.Parse(offsetLegs.Text) * 5, displayBox.Width, legY + float.Parse(offsetLegs.Text) * 5); + //} + //g.DrawLine(Pens.Red, center.X, 0, center.X, displayBox.Height); + //g.DrawLine(Pens.Blue, center.X + 30, 0, center.X + 30, displayBox.Height); + //g.DrawLine(Pens.Blue, center.X - 30, 0, center.X - 30, displayBox.Height); + //g.DrawLine(Pens.Purple, center.X - 10, 0, center.X - 10, displayBox.Height); + //g.DrawLine(Pens.Purple, center.X + 10, 0, center .X + 10, displayBox.Height); } private void DrawArmorOffsets(Graphics g) { - int centerPointHeight = displayBox.Height / 2; - int centerPointWidth = displayBox.Width / 2; - int headbodyY = centerPointHeight + 25; //25 - int armY = centerPointHeight + 35; // - 60; - int legY = centerPointHeight + 85; // - 80; - SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(80, 50, 50, 75)); - g.FillRectangle(semiTransBrush, centerPointWidth, (float)(headbodyY - 40 /*+ offsetHelmet.Value * 5*/), 40, 40); // Helmet - bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; - if (isSide) - { - g.FillRectangle(semiTransBrush, centerPointWidth - 10, headbodyY, 20, 60); // Chest - g.FillRectangle(semiTransBrush, centerPointWidth - 10, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boots - g.FillRectangle(semiTransBrush, centerPointWidth - 10, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants - g.FillRectangle(semiTransBrush, centerPointWidth - 5, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tools - } - else - { - g.FillRectangle(semiTransBrush, centerPointWidth - 20, headbodyY, 40, 60); // Chest - g.FillRectangle(semiTransBrush, centerPointWidth - 35, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tool0 - g.FillRectangle(semiTransBrush, centerPointWidth + 25, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tool1 - g.FillRectangle(semiTransBrush, centerPointWidth - 20, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants0 - g.FillRectangle(semiTransBrush, centerPointWidth, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants1 - g.FillRectangle(semiTransBrush, centerPointWidth - 20, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boot0 - g.FillRectangle(semiTransBrush, centerPointWidth, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boot1 - } + throw new NotImplementedException(); + //int centerPointHeight = displayBox.Height / 2; + //int centerPointWidth = displayBox.Width / 2; + //int headbodyY = centerPointHeight + 25; //25 + //int armY = centerPointHeight + 35; // - 60; + //int legY = centerPointHeight + 85; // - 80; + //SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(80, 50, 50, 75)); + //g.FillRectangle(semiTransBrush, centerPointWidth, (float)(headbodyY - 40 /*+ offsetHelmet.Value * 5*/), 40, 40); // Helmet + //bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; + //if (isSide) + //{ + // g.FillRectangle(semiTransBrush, centerPointWidth - 10, headbodyY, 20, 60); // Chest + // g.FillRectangle(semiTransBrush, centerPointWidth - 10, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boots + // g.FillRectangle(semiTransBrush, centerPointWidth - 10, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants + // g.FillRectangle(semiTransBrush, centerPointWidth - 5, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tools + //} + //else + //{ + // g.FillRectangle(semiTransBrush, centerPointWidth - 20, headbodyY, 40, 60); // Chest + // g.FillRectangle(semiTransBrush, centerPointWidth - 35, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tool0 + // g.FillRectangle(semiTransBrush, centerPointWidth + 25, (float)(armY + 45 /*+ offsetTool.Value * 5*/), 10, 10); // Tool1 + // g.FillRectangle(semiTransBrush, centerPointWidth - 20, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants0 + // g.FillRectangle(semiTransBrush, centerPointWidth, (float)(legY /*+ offsetPants.Value * 5*/), 20, 40); // Pants1 + // g.FillRectangle(semiTransBrush, centerPointWidth - 20, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boot0 + // g.FillRectangle(semiTransBrush, centerPointWidth, (float)(legY + 40 /*+ offsetBoots.Value * 5*/), 20, 20); // Boot1 + //} } @@ -1103,7 +1101,6 @@ namespace PckStudio.Forms // graphics.ApplyConfig(_graphicsConfig); // graphics.DrawImage(uvPictureBox.Image, 0, 0, 64, 64); //} - _previewImage = new Bitmap(displayBox.Width, displayBox.Height); Close(); } diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx b/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx index 1fa4fc59..6db730f5 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx @@ -960,33 +960,6 @@ 23 - - NoControl - - - 655, 72 - - - 128, 128 - - - Zoom - - - 112 - - - uvPictureBox - - - PckStudio.PictureBoxWithInterpolationMode, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 20 - Flat @@ -1017,33 +990,6 @@ 17 - - NoControl - - - 194, 56 - - - 449, 580 - - - StretchImage - - - 98 - - - displayBox - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 13 - Flat @@ -1126,7 +1072,7 @@ $this - 12 + 13 True @@ -1153,7 +1099,7 @@ $this - 11 + 12 True @@ -1180,7 +1126,7 @@ $this - 10 + 11 True @@ -1207,7 +1153,7 @@ $this - 9 + 10 658, 275 @@ -1231,7 +1177,7 @@ $this - 8 + 9 658, 301 @@ -1255,7 +1201,7 @@ $this - 7 + 8 658, 327 @@ -1279,7 +1225,7 @@ $this - 6 + 7 682, 233 @@ -1300,7 +1246,7 @@ $this - 5 + 6 731, 234 @@ -1321,7 +1267,7 @@ $this - 4 + 5 657, 425 @@ -1345,7 +1291,7 @@ $this - 1 + 2 658, 399 @@ -1369,7 +1315,7 @@ $this - 2 + 3 658, 373 @@ -1393,7 +1339,7 @@ $this - 3 + 4 Part @@ -1485,6 +1431,71 @@ 14 + + Top, Bottom, Left, Right + + + 194, 59 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAElPcGVuVEssIFZlcnNpb249My4zLjMuMCwgQ3VsdHVyZT1uZXV0 + cmFsLCBQdWJsaWNLZXlUb2tlbj1iYWQxOTlmZTg0ZWIzZGY0BQEAAAAOT3BlblRLLlZlY3RvcjICAAAA + AVgBWQAACwsCAAAAAAAAAAAAAAAL + + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAElPcGVuVEssIFZlcnNpb249My4zLjMuMCwgQ3VsdHVyZT1uZXV0 + cmFsLCBQdWJsaWNLZXlUb2tlbj1iYWQxOTlmZTg0ZWIzZGY0BQEAAAAOT3BlblRLLlZlY3RvcjICAAAA + AVgBWQAACwsCAAAAAAAAAAAAAAAL + + + + 449, 574 + + + 0 + + + renderer3D1 + + + PckStudio.Rendering.Renderer3D, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 1 + + + NoControl + + + 655, 72 + + + 128, 128 + + + Zoom + + + 112 + + + uvPictureBox + + + PckStudio.ToolboxItems.InterpolationPictureBox, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 20 + True @@ -4003,6 +4014,9 @@ AP//AAA= + + NoControl + 1114, 1000 diff --git a/PCK-Studio/Forms/TestGL.Designer.cs b/PCK-Studio/Forms/TestGL.Designer.cs index aa1d958d..984b4022 100644 --- a/PCK-Studio/Forms/TestGL.Designer.cs +++ b/PCK-Studio/Forms/TestGL.Designer.cs @@ -38,8 +38,6 @@ this.renderer3D1.Location = new System.Drawing.Point(0, 0); this.renderer3D1.Model = PckStudio.Rendering.Renderer3D.Models.Steve; this.renderer3D1.Name = "renderer3D1"; - this.renderer3D1.RotationX = 0; - this.renderer3D1.RotationY = 0; this.renderer3D1.ShowBodyOverlay = true; this.renderer3D1.ShowHeadOverlay = true; this.renderer3D1.ShowLeftArmOverlay = true; @@ -55,7 +53,7 @@ this.renderer3D1.Size = new System.Drawing.Size(426, 428); this.renderer3D1.Texture = global::PckStudio.Properties.Resources.classic_template; this.renderer3D1.TabIndex = 8; - this.renderer3D1.Zoom = 1D; + this.renderer3D1.FieldOfView = 1D; // // TestGL // diff --git a/PCK-Studio/Forms/TestGL.cs b/PCK-Studio/Forms/TestGL.cs index 15d89aa6..c2538bc8 100644 --- a/PCK-Studio/Forms/TestGL.cs +++ b/PCK-Studio/Forms/TestGL.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; @@ -13,33 +14,23 @@ namespace PckStudio.Forms { public partial class TestGL : Form { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new TestGL()); + } + public TestGL() { InitializeComponent(); } - internal Bitmap Skin = Resources.classic_template; - internal void UpdateImage() - { - var Image = new Bitmap(Skin.Width, Skin.Height); // Create the skin preview bitmao - if (!(Skin.Width == 64 && Skin.Height == 64)) // Check the skin resolution - { - MessageBox.Show("Skin isn't valid.", "Error"); - return; - } - // ****************Writing pixels to the preview**************** - for (byte Y = 0, loopTo = (byte)(Skin.Height - 1); Y <= loopTo; Y++) - { - for (byte X = 0, loopTo1 = (byte)(Skin.Width - 1); X <= loopTo1; X++) - Image.SetPixel(X, Y, Skin.GetPixel(X / 2, Y / 2)); - } - // ************************************************************* - renderer3D1.Texture = Skin; - renderer3D1.Refresh(); // Render - } private void TestGL_Load(object sender, EventArgs e) { - UpdateImage(); // Load preview + renderer3D1.Refresh(); } } } diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 8ad52caa..2fd819fc 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -86,7 +86,7 @@ - PckStudio.Program + PckStudio.Forms.TestGL @@ -151,6 +151,13 @@ True Resources.resx + + + + + + + Component @@ -621,7 +628,7 @@ - + @@ -674,6 +681,7 @@ + diff --git a/PCK-Studio/Properties/Resources.Designer.cs b/PCK-Studio/Properties/Resources.Designer.cs index 8e2785f6..1ebfa5ea 100644 --- a/PCK-Studio/Properties/Resources.Designer.cs +++ b/PCK-Studio/Properties/Resources.Designer.cs @@ -334,6 +334,22 @@ namespace PckStudio.Properties { } } + /// + /// Looks up a localized string similar to #version 330 core + /// + ///layout(location = 0) out vec4 color; + /// + ///void main() + ///{ + /// color = vec4(1.0, 0.0, 0.0, 1.0); + ///};. + /// + public static string fragmentShader { + get { + return ResourceManager.GetString("fragmentShader", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -584,16 +600,6 @@ namespace PckStudio.Properties { } } - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - public static System.Drawing.Bitmap steve { - get { - object obj = ResourceManager.GetObject("steve", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -775,6 +781,22 @@ namespace PckStudio.Properties { } } + /// + /// Looks up a localized string similar to #version 330 core + /// + ///layout(location = 0) in vec2 position; + /// + ///void main() + ///{ + /// gl_Position = vec4(position.xy, 0.0, 0.0); + ///};. + /// + public static string vertexShader { + get { + return ResourceManager.GetString("vertexShader", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/PCK-Studio/Properties/Resources.resx b/PCK-Studio/Properties/Resources.resx index 759088af..59fcd348 100644 --- a/PCK-Studio/Properties/Resources.resx +++ b/PCK-Studio/Properties/Resources.resx @@ -328,7 +328,10 @@ ..\..\ProjectLogo.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\steve.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\vertexShader.glsl;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\fragment.glsl;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 \ No newline at end of file diff --git a/PCK-Studio/Rendering/IndexBuffer.cs b/PCK-Studio/Rendering/IndexBuffer.cs new file mode 100644 index 00000000..a9ce629a --- /dev/null +++ b/PCK-Studio/Rendering/IndexBuffer.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal class IndexBuffer : IDisposable + { + private int _id; + private int _count; + + public IndexBuffer(params uint[] indecies) + { + _id = GL.GenBuffer(); + Bind(); + _count = indecies.Length; + GL.BufferData(BufferTarget.ElementArrayBuffer, indecies.Length * sizeof(uint), indecies, BufferUsageHint.StaticDraw); + } + + public int GetCount() => _count; + + public void Bind() + { + GL.BindBuffer(BufferTarget.ElementArrayBuffer, _id); + } + + [Conditional("DEBUG")] + public void Unbind() + { + GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); + } + + public void Dispose() + { + GL.DeleteBuffer(_id); + } + } +} diff --git a/PCK-Studio/Rendering/Renderer.cs b/PCK-Studio/Rendering/Renderer.cs new file mode 100644 index 00000000..f38f81c0 --- /dev/null +++ b/PCK-Studio/Rendering/Renderer.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal static class Renderer + { + public static void Draw(VertexArray va, IndexBuffer ib, Shader shader) + { + shader.Bind(); + va.Bind(); + ib.Bind(); + GL.DrawElements(PrimitiveType.Triangles, ib.GetCount(), DrawElementsType.UnsignedInt, 0); + } + + public static void Draw(VertexArray va, Shader shader) + { + shader.Bind(); + va.Bind(); + GL.DrawArrays(PrimitiveType.Triangles, 0, 6); + } + } +} diff --git a/PCK-Studio/Rendering/Renderer3D.Designer.cs b/PCK-Studio/Rendering/Renderer3D.Designer.cs index cabaf3c7..ddd4450b 100644 --- a/PCK-Studio/Rendering/Renderer3D.Designer.cs +++ b/PCK-Studio/Rendering/Renderer3D.Designer.cs @@ -1,7 +1,5 @@ using System; using System.Diagnostics; -using System.Drawing; -using System.Windows.Forms; namespace PckStudio.Rendering { @@ -33,43 +31,43 @@ namespace PckStudio.Rendering private void InitializeComponent() { components = new System.ComponentModel.Container(); - timMove = new Timer(components); - timMove.Tick += new EventHandler(Move_Tick); + moveTimer = new System.Windows.Forms.Timer(components); + moveTimer.Tick += new EventHandler(Move_Tick); SuspendLayout(); // // timMove // - timMove.Enabled = true; - timMove.Interval = 20; + moveTimer.Enabled = true; + moveTimer.Interval = 20; #if DEBUG // // debugLabel // debugLabel = new System.Windows.Forms.Label(); debugLabel.Enabled = true; - debugLabel.Visible = true; + debugLabel.Visible = false; debugLabel.AutoSize = true; - debugLabel.Location = new Point(0, 0); - debugLabel.BackColor = Color.Transparent; - Controls.Add(debugLabel); + debugLabel.Location = new System.Drawing.Point(0, 0); + debugLabel.BackColor = System.Drawing.Color.Transparent; + Controls.Add(debugLabel);; #endif // // Renderer3D // - Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - BackColor = Color.Transparent; - Location = new Point(0, 0); - Size = new Size(150, 150); + Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + BackColor = System.Drawing.Color.LightGray; + Location = new System.Drawing.Point(0, 0); + Size = new System.Drawing.Size(150, 150); TabIndex = 0; VSync = true; - AutoScaleDimensions = new SizeF(6.0f, 13.0f); - AutoScaleMode = AutoScaleMode.Font; + AutoScaleDimensions = new System.Drawing.SizeF(6.0f, 13.0f); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; Name = "Renderer3D"; ResumeLayout(false); } - private Timer timMove; + private System.Windows.Forms.Timer moveTimer; #if DEBUG private System.Windows.Forms.Label debugLabel; #endif diff --git a/PCK-Studio/Rendering/Renderer3D.cs b/PCK-Studio/Rendering/Renderer3D.cs index 1223611f..43300c81 100644 --- a/PCK-Studio/Rendering/Renderer3D.cs +++ b/PCK-Studio/Rendering/Renderer3D.cs @@ -39,19 +39,35 @@ using OpenTK; using OpenTK.Graphics.OpenGL; using System.Diagnostics; using PckStudio.Properties; +using System.Runtime.InteropServices; namespace PckStudio.Rendering { public partial class Renderer3D : GLControl { - //private Bitmap _Skin; + private Bitmap _texture; /// - /// The visible skin on the renderer + /// The visible Texture on the renderer /// - /// The visible skin - [Description("The current skin")] + /// The visible Texture + [Description("The current Texture")] [Category("Appearance")] - public Bitmap Texture { get; set; } + public Bitmap Texture + { + get => _texture; + set + { + if (shader is not null) + { + var texture = new Texture2D(value); + texture.Bind(1); + shader.SetUniform1("u_Texture", 1); + Refresh(); + } + TextureScaleValue = new Vector2d(1d / value.Width, 1d / value.Height); + _texture = value; + } + } private bool _showhead = true; /// @@ -282,7 +298,6 @@ namespace PckStudio.Rendering } } - public enum Models { Steve, @@ -315,16 +330,16 @@ namespace PckStudio.Rendering } } - private double _zoom = MinZoomLevel; - private const double MinZoomLevel = 1d; - private const double MaxZoomLevel = 10d; + private double _fieldOfView = MinFOV; + private const double MinFOV = 30d; + private const double MaxFOV = 90d; [Description("The zoom value")] [Category("Appearance")] - public double Zoom + public double FieldOfView { - get => _zoom; - set => _zoom = MathHelper.Clamp(value, MinZoomLevel, MaxZoomLevel); + get => _fieldOfView; + set => _fieldOfView = MathHelper.Clamp(value, MinFOV, MaxFOV); } private Vector2 _lookAngle = Vector2.Zero; @@ -343,41 +358,118 @@ namespace PckStudio.Rendering public float CameraDistance { get; set; } = 36f; - private Matrix4 perspective; // Perspective - private Matrix4 camera; // Camera + private Matrix4 projection; - private const double TexVal = 1d / 64d; + private Matrix4 view; + + private Vector2d TextureScaleValue = new Vector2d(1d / 64d); + + private void GLDebugMessage(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam) + { + string msg = Marshal.PtrToStringAnsi(message, length); + Debug.WriteLine(source); + Debug.WriteLine(type); + Debug.WriteLine(severity); + Debug.WriteLine(id); + Debug.WriteLine(msg); + } + + private Shader shader; + + private VertexArray vertexArray; + private IndexBuffer indexBuffer; + private Matrix4 mvp; + + private bool IsMouseDown; + private bool IsRightMouseDown; + private bool IsMouseHidden; + private Point PreviousMouseLocation; + private Point MouseLoc; + + private Ray LastRay; + private Vector3 GlobalCameraPos; public Renderer3D() { InitializeComponent(); - UpdateCamera(); - UpdatePerspective(); - //MakeCurrent(); - //int program = CreateShader(Resources.vertexShader, Resources.fragment); } - private void UpdateCamera() + protected override void OnLoad(EventArgs e) { - camera = Matrix4.LookAt(LookAngle.X, LookAngle.Y, CameraDistance, LookAngle.X, LookAngle.Y, 0f, 0f, 1f, 1f); + base.OnLoad(e); + if (DesignMode) + return; + + MakeCurrent(); + + GL.DebugMessageCallback(GLDebugMessage, IntPtr.Zero); + + Trace.TraceInformation(GL.GetString(StringName.Version)); + + shader = Shader.Create(Resources.vertexShader, Resources.fragmentShader); + shader.Bind(); + + Texture = Resources.slim_template; + + shader.SetUniform4("u_Color", Color.Blue); + + var data = new float[] + { + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 10.0f, 0.0f, 0.0f, 1.0f, 1.0f, + 10.0f, 10.0f, 10.0f, 1.0f, 0.0f, + 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, + }; + + vertexArray = new VertexArray(); + + var buffer = new VertexBuffer(data, data.Length * sizeof(float)); + var layout = new VertexBufferLayout(); + layout.Add(3); + layout.Add(2); + + vertexArray.AddBuffer(buffer, layout); + + indexBuffer = new IndexBuffer( + 0, 1, 2, + 2, 3, 0 + ); + + + var error = GL.GetError(); + while (error != ErrorCode.NoError) + { + Debug.WriteLine(error); + error = GL.GetError(); + } } - private void UpdatePerspective() + private void UpdateView() { - perspective = Matrix4.CreatePerspectiveFieldOfView((float)Math.Pow(Zoom, -1), (float)(Width / (double)Height), 0.1f, 1000f); + var camera = new Vector3(LookAngle) { Z = CameraDistance }; + + var target = new Vector3(LookAngle); + + var up = Vector3.UnitY + Vector3.UnitZ; + + view = Matrix4.LookAt(camera, target, up); } - // Only call when a context is present - private static void DrawBox(Image texture, Vector3 size, float X, float Y, float Z, float uvX, float uvY) + private void UpdateProjection() { - float[] Corner1 = { X, Y, Z }; - float[] Corner2 = { X + size.X, Y, Z }; - float[] Corner3 = { X, Y + size.Y, Z }; - float[] Corner4 = { X, Y, Z + size.Z }; - float[] Corner5 = { X + size.X, Y + size.Y, Z }; - float[] Corner6 = { X, Y + size.Y, Z + size.Z }; - float[] Corner7 = { X + size.X, Y, Z + size.Z }; - float[] Corner8 = { X + size.X, Y + size.Y, Z + size.Z }; + projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.Pow(FieldOfView, -1), Width / (float)Height, 0.1f, 1000f); + } + + private void DrawBox(Vector3 scale, Vector3 position, Vector2 uv) + { + float[] Corner1 = { position.X, position.Y, position.Z }; + float[] Corner2 = { position.X + scale.X, position.Y, position.Z }; + float[] Corner3 = { position.X, position.Y + scale.Y, position.Z }; + float[] Corner4 = { position.X, position.Y, position.Z + scale.Z }; + float[] Corner5 = { position.X + scale.X, position.Y + scale.Y, position.Z }; + float[] Corner6 = { position.X, position.Y + scale.Y, position.Z + scale.Z }; + float[] Corner7 = { position.X + scale.X, position.Y, position.Z + scale.Z }; + float[] Corner8 = { position.X + scale.X, position.Y + scale.Y, position.Z + scale.Z }; GL.Color3(Color.Red); // Face 1 @@ -396,13 +488,13 @@ namespace PckStudio.Rendering GL.Vertex3(Corner6); GL.Vertex3(Corner3); // Face 4 - GL.TexCoord2(uvX, TexVal * 8d); + GL.TexCoord2(uv.X, TextureScaleValue.Y * 8d); GL.Vertex3(Corner4); - GL.TexCoord2(TexVal * 16d, TexVal * 8d); + GL.TexCoord2(TextureScaleValue.X * 16d, TextureScaleValue.Y * 8d); GL.Vertex3(Corner7); - GL.TexCoord2(TexVal * 16d, TexVal * 16d); + GL.TexCoord2(TextureScaleValue.X * 16d, TextureScaleValue.Y * 16d); GL.Vertex3(Corner8); - GL.TexCoord2(TexVal * 8d, TexVal * 16d); + GL.TexCoord2(TextureScaleValue.X * 8d, TextureScaleValue.Y * 16d); GL.Vertex3(Corner6); // Face 5 GL.Vertex3(Corner8); @@ -416,1096 +508,96 @@ namespace PckStudio.Rendering GL.Vertex3(Corner5); } - - private static int CompileShader(ShaderType type, string shaderSource) - { - int shaderId = GL.CreateShader(type); - GL.ShaderSource(shaderId, shaderSource); - GL.CompileShader(shaderId); - - GL.GetShader(shaderId, ShaderParameter.CompileStatus, out int status); - - if (status == 0) - { - GL.GetShader(shaderId, ShaderParameter.InfoLogLength, out int length); - GL.GetShaderInfoLog(shaderId, length, out length, out string infoLog); - Trace.TraceError(infoLog); - GL.DeleteShader(shaderId); - return 0; - } - return shaderId; - } - - private static int CreateShader(string vertexSource, string fragmentSource) - { - int programId = GL.CreateProgram(); - - int vertexShader = CompileShader(ShaderType.VertexShader, vertexSource); - int fragmentShader = CompileShader(ShaderType.FragmentShader, fragmentSource); - - GL.AttachShader(programId, vertexShader); - GL.AttachShader(programId, fragmentShader); - - GL.LinkProgram(programId); - GL.ValidateProgram(programId); - - GL.DeleteShader(vertexShader); - GL.DeleteShader(fragmentShader); - return programId; - } - protected override void OnPaint(PaintEventArgs e) { if (DesignMode) + { + base.OnPaint(e); return; - //base.OnPaint(e); + } + + UpdateProjection(); + UpdateView(); MakeCurrent(); + + GL.Viewport(Size); + + var rot = Matrix4.CreateFromAxisAngle(new Vector3(-0.5f, 0f, 0f), Rotation.X) + + Matrix4.CreateFromAxisAngle(new Vector3(0f, 0.5f, 0f), Rotation.Y); + + mvp = view * projection * rot; + #if DEBUG - debugLabel.Text = $"Rotation: {Rotation}\nZoom: {_zoom}\nLookAt:\n{camera}\nPerspective:\n{perspective}"; + debugLabel.Text = $"Rotation: {Rotation}\nZoom: {_fieldOfView}\nLookAt:\n{view}\nProjection:\n{projection}\nMVP:\n{mvp}"; #endif + shader.SetUniformMat4("u_MVP", ref mvp); + + GL.ClearColor(BackColor); + GL.Clear(ClearBufferMask.ColorBufferBit); + + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + + Renderer.Draw(vertexArray, indexBuffer, shader); + + SwapBuffers(); + return; + GL.PushMatrix(); GL.ClearColor(BackColor); // First Clear Buffers GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.DepthBufferBit); - + // Basic Setup for viewing - UpdatePerspective(); - UpdateCamera(); + UpdateProjection(); + UpdateView(); GL.MatrixMode(MatrixMode.Projection); // Load Perspective GL.LoadIdentity(); - GL.LoadMatrix(ref perspective); + GL.LoadMatrix(ref projection); GL.MatrixMode(MatrixMode.Modelview); // Load Camera GL.LoadIdentity(); - GL.LoadMatrix(ref camera); + GL.LoadMatrix(ref view); GL.Viewport(0, 0, Width, Height); // Size of window GL.Enable(EnableCap.DepthTest); // Enable correct Z Drawings GL.Enable(EnableCap.Texture2D); // Enable textures - GL.DepthFunc(DepthFunction.Less); // Enable correct Z Drawings + GL.DepthFunc(DepthFunction.Lequal); // Enable correct Z Drawings // GL.Disable(EnableCap.Blend) 'Disable transparent GL.Disable(EnableCap.AlphaTest); // Disable transparent - - // Load the textures - int texID = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, texID); - - GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); - var data = Texture.LockBits(new Rectangle(0, 0, 64, 64), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, 64, 64, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); - Texture.UnlockBits(data); - - // Rotating - GL.Rotate(Rotation.X, -1, 0f, 0f); - GL.Rotate(Rotation.Y, 0f, 1f, 0f); - - GL.BindTexture(TextureTarget.ProxyTexture2D, texID); - // Vertex goes (X,Y,Z) - GL.Begin(PrimitiveType.Quads); - // Body - if (ShowBody) - { - // Face 1 - GL.TexCoord2(TexVal * 20d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 20d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 32d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 20d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - // Face 2 - GL.TexCoord2(TexVal * 40d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 32d, TexVal * 20d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 32d, TexVal * 32d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 40d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - // Face 3 - GL.TexCoord2(TexVal * 20d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 16d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 16d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 20d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - // Face 4 - GL.TexCoord2(TexVal * 28d, TexVal * 20d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 32d, TexVal * 20d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 32d, TexVal * 32d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 28d, TexVal * 32d); - GL.Vertex3(4, -4, 2); - // Face 5 - GL.TexCoord2(TexVal * 20d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 20d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 16d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 20d, TexVal * 16d); - GL.Vertex3(-4, 8, -2); - // Face 6 - GL.TexCoord2(TexVal * 28d, TexVal * 16d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 16d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 20d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - } - - if (ShowHead) - { - // Head - // Face 1 - GL.TexCoord2(TexVal * 8d, TexVal * 8d); - GL.Vertex3(-4, 16, 4); - GL.TexCoord2(TexVal * 16d, TexVal * 8d); - GL.Vertex3(4, 16, 4); - GL.TexCoord2(TexVal * 16d, TexVal * 16d); - GL.Vertex3(4, 8, 4); - GL.TexCoord2(TexVal * 8d, TexVal * 16d); - GL.Vertex3(-4, 8, 4); - // Face 2 - GL.TexCoord2(TexVal * 32d, TexVal * 8d); - GL.Vertex3(-4, 16, -4); - GL.TexCoord2(TexVal * 24d, TexVal * 8d); - GL.Vertex3(4, 16, -4); - GL.TexCoord2(TexVal * 24d, TexVal * 16d); - GL.Vertex3(4, 8, -4); - GL.TexCoord2(TexVal * 32d, TexVal * 16d); - GL.Vertex3(-4, 8, -4); - // Face 3 - GL.TexCoord2(TexVal * 8d, TexVal * 8d); - GL.Vertex3(-4, 16, 4); - GL.TexCoord2(TexVal * 0d, TexVal * 8d); - GL.Vertex3(-4, 16, -4); - GL.TexCoord2(TexVal * 0d, TexVal * 16d); - GL.Vertex3(-4, 8, -4); - GL.TexCoord2(TexVal * 8d, TexVal * 16d); - GL.Vertex3(-4, 8, 4); - // Face 4 - GL.TexCoord2(TexVal * 16d, TexVal * 8d); - GL.Vertex3(4, 16, 4); - GL.TexCoord2(TexVal * 24d, TexVal * 8d); - GL.Vertex3(4, 16, -4); - GL.TexCoord2(TexVal * 24d, TexVal * 16d); - GL.Vertex3(4, 8, -4); - GL.TexCoord2(TexVal * 16d, TexVal * 16d); - GL.Vertex3(4, 8, 4); - // Face 5 - GL.TexCoord2(TexVal * 8d, TexVal * 8d); - GL.Vertex3(-4, 16, 4); - GL.TexCoord2(TexVal * 16d, TexVal * 8d); - GL.Vertex3(4, 16, 4); - GL.TexCoord2(TexVal * 16d, TexVal * 0d); - GL.Vertex3(4, 16, -4); - GL.TexCoord2(TexVal * 8d, TexVal * 0d); - GL.Vertex3(-4, 16, -4); - // Face 6 - GL.TexCoord2(TexVal * 16d, TexVal * 8d); - GL.Vertex3(-4, 8, 4); - GL.TexCoord2(TexVal * 24d, TexVal * 8d); - GL.Vertex3(4, 8, 4); - GL.TexCoord2(TexVal * 24d, TexVal * 0d); - GL.Vertex3(4, 8, -4); - GL.TexCoord2(TexVal * 16d, TexVal * 0d); - GL.Vertex3(-4, 8, -4); - } - - if (Model == Models.Steve) - { - - if (ShowLeftArm) - { - // LefttArm - // Face 1 - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 52d); - GL.Vertex3(8, 8, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 64d); - GL.Vertex3(8, -4, 2); - GL.TexCoord2(TexVal * 36d, TexVal * 64d); - GL.Vertex3(4, -4, 2); - // Face 2 - GL.TexCoord2(TexVal * 48d, TexVal * 52d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 52d); - GL.Vertex3(8, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 64d); - GL.Vertex3(8, -4, -2); - GL.TexCoord2(TexVal * 48d, TexVal * 64d); - GL.Vertex3(4, -4, -2); - // Face 3 - GL.TexCoord2(TexVal * 32d, TexVal * 52d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 36d, TexVal * 64d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 32d, TexVal * 64d); - GL.Vertex3(4, -4, -2); - // Face 4 - GL.TexCoord2(TexVal * 44d, TexVal * 52d); - GL.Vertex3(8, 8, -2); - GL.TexCoord2(TexVal * 40d, TexVal * 52d); - GL.Vertex3(8, 8, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 64d); - GL.Vertex3(8, -4, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 64d); - GL.Vertex3(8, -4, -2); - // Face 5 - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 52d); - GL.Vertex3(8, 8, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 48d); - GL.Vertex3(8, 8, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 48d); - GL.Vertex3(4, 8, -2); - // Face 6 - GL.TexCoord2(TexVal * 40d, TexVal * 52d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 52d); - GL.Vertex3(8, -4, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 48d); - GL.Vertex3(8, -4, -2); - GL.TexCoord2(TexVal * 40d, TexVal * 48d); - GL.Vertex3(4, -4, -2); - } - - if (ShowRightArm) - { - // RightArm - // Face 1 - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-8, 8, 2); - GL.TexCoord2(TexVal * 48d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 48d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-8, -4, 2); - // Face 2 - GL.TexCoord2(TexVal * 56d, TexVal * 20d); - GL.Vertex3(-8, 8, -2); - GL.TexCoord2(TexVal * 52d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 52d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 56d, TexVal * 32d); - GL.Vertex3(-8, -4, -2); - // Face 3 - GL.TexCoord2(TexVal * 40d, TexVal * 20d); - GL.Vertex3(-8, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-8, 8, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-8, -4, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 32d); - GL.Vertex3(-8, -4, -2); - // Face 4 - GL.TexCoord2(TexVal * 52d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 48d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 48d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 52d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - // Face 5 - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-8, 8, 2); - GL.TexCoord2(TexVal * 48d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 48d, TexVal * 16d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 16d); - GL.Vertex3(-8, 8, -2); - // Face 6 - GL.TexCoord2(TexVal * 48d, TexVal * 20d); - GL.Vertex3(-8, -4, 2); - GL.TexCoord2(TexVal * 52d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 52d, TexVal * 16d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 48d, TexVal * 16d); - GL.Vertex3(-8, -4, -2); - } - } - - else - { - - if (ShowLeftArm) - { - // LefttArm - // Face 1 - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 39d, TexVal * 52d); - GL.Vertex3(7, 8, 2); - GL.TexCoord2(TexVal * 39d, TexVal * 64d); - GL.Vertex3(7, -4, 2); - GL.TexCoord2(TexVal * 36d, TexVal * 64d); - GL.Vertex3(4, -4, 2); - // Face 2 - GL.TexCoord2(TexVal * 46d, TexVal * 52d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 43d, TexVal * 52d); - GL.Vertex3(7, 8, -2); - GL.TexCoord2(TexVal * 43d, TexVal * 64d); - GL.Vertex3(7, -4, -2); - GL.TexCoord2(TexVal * 46d, TexVal * 64d); - GL.Vertex3(4, -4, -2); - // Face 3 - GL.TexCoord2(TexVal * 32d, TexVal * 52d); - GL.Vertex3(4, 8, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 36d, TexVal * 64d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 32d, TexVal * 64d); - GL.Vertex3(4, -4, -2); - // Face 4 - GL.TexCoord2(TexVal * 43d, TexVal * 52d); - GL.Vertex3(7, 8, -2); - GL.TexCoord2(TexVal * 39d, TexVal * 52d); - GL.Vertex3(7, 8, 2); - GL.TexCoord2(TexVal * 39d, TexVal * 64d); - GL.Vertex3(7, -4, 2); - GL.TexCoord2(TexVal * 43d, TexVal * 64d); - GL.Vertex3(7, -4, -2); - // Face 5 - GL.TexCoord2(TexVal * 36d, TexVal * 52d); - GL.Vertex3(4, 8, 2); - GL.TexCoord2(TexVal * 39d, TexVal * 52d); - GL.Vertex3(7, 8, 2); - GL.TexCoord2(TexVal * 39d, TexVal * 48d); - GL.Vertex3(7, 8, -2); - GL.TexCoord2(TexVal * 36d, TexVal * 48d); - GL.Vertex3(4, 8, -2); - // Face 6 - GL.TexCoord2(TexVal * 39d, TexVal * 52d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 42d, TexVal * 52d); - GL.Vertex3(7, -4, 2); - GL.TexCoord2(TexVal * 42d, TexVal * 48d); - GL.Vertex3(7, -4, -2); - GL.TexCoord2(TexVal * 39d, TexVal * 48d); - GL.Vertex3(4, -4, -2); - } - - if (ShowRightArm) - { - // RightArm - // Face 1 - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-7, 8, 2); - GL.TexCoord2(TexVal * 47d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 47d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-7, -4, 2); - // Face 2 - GL.TexCoord2(TexVal * 54d, TexVal * 20d); - GL.Vertex3(-7, 8, -2); - GL.TexCoord2(TexVal * 51d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 51d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 54d, TexVal * 32d); - GL.Vertex3(-7, -4, -2); - // Face 3 - GL.TexCoord2(TexVal * 40d, TexVal * 20d); - GL.Vertex3(-7, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-7, 8, 2); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-7, -4, 2); - GL.TexCoord2(TexVal * 40d, TexVal * 32d); - GL.Vertex3(-7, -4, -2); - // Face 4 - GL.TexCoord2(TexVal * 51d, TexVal * 20d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 47d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 47d, TexVal * 32d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 51d, TexVal * 32d); - GL.Vertex3(-4, -4, -2); - // Face 5 - GL.TexCoord2(TexVal * 44d, TexVal * 20d); - GL.Vertex3(-7, 8, 2); - GL.TexCoord2(TexVal * 47d, TexVal * 20d); - GL.Vertex3(-4, 8, 2); - GL.TexCoord2(TexVal * 47d, TexVal * 16d); - GL.Vertex3(-4, 8, -2); - GL.TexCoord2(TexVal * 44d, TexVal * 16d); - GL.Vertex3(-7, 8, -2); - // Face 6 - GL.TexCoord2(TexVal * 47d, TexVal * 20d); - GL.Vertex3(-7, -4, 2); - GL.TexCoord2(TexVal * 50d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 50d, TexVal * 16d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 47d, TexVal * 16d); - GL.Vertex3(-7, -4, -2); - } - - } - - if (ShowRightLeg) - { - // RightLeg - // Face 1 - GL.TexCoord2(TexVal * 4d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 8d, TexVal * 20d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 8d, TexVal * 32d); - GL.Vertex3(0, -16, 2); - GL.TexCoord2(TexVal * 4d, TexVal * 32d); - GL.Vertex3(-4, -16, 2); - // Face 2 - GL.TexCoord2(TexVal * 16d, TexVal * 20d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 12d, TexVal * 20d); - GL.Vertex3(0, -4, -2); - GL.TexCoord2(TexVal * 12d, TexVal * 32d); - GL.Vertex3(0, -16, -2); - GL.TexCoord2(TexVal * 16d, TexVal * 32d); - GL.Vertex3(-4, -16, -2); - // Face 3 - GL.TexCoord2(TexVal * 4d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 0d, TexVal * 20d); - GL.Vertex3(-4, -4, -2); - GL.TexCoord2(TexVal * 0d, TexVal * 32d); - GL.Vertex3(-4, -16, -2); - GL.TexCoord2(TexVal * 4d, TexVal * 32d); - GL.Vertex3(-4, -16, 2); - // Face 4 - GL.TexCoord2(TexVal * 8d, TexVal * 20d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 12d, TexVal * 20d); - GL.Vertex3(0, -4, -2); - GL.TexCoord2(TexVal * 12d, TexVal * 32d); - GL.Vertex3(0, -16, -2); - GL.TexCoord2(TexVal * 8d, TexVal * 32d); - GL.Vertex3(0, -16, 2); - // Face 5 - GL.TexCoord2(TexVal * 4d, TexVal * 20d); - GL.Vertex3(-4, -4, 2); - GL.TexCoord2(TexVal * 8d, TexVal * 20d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 8d, TexVal * 16d); - GL.Vertex3(0, -4, -2); - GL.TexCoord2(TexVal * 4d, TexVal * 16d); - GL.Vertex3(-4, -4, -2); - // Face 6 - GL.TexCoord2(TexVal * 8d, TexVal * 20d); - GL.Vertex3(-4, -16, 2); - GL.TexCoord2(TexVal * 12d, TexVal * 20d); - GL.Vertex3(0, -16, 2); - GL.TexCoord2(TexVal * 12d, TexVal * 16d); - GL.Vertex3(0, -16, -2); - GL.TexCoord2(TexVal * 8d, TexVal * 16d); - GL.Vertex3(-4, -16, -2); - } - - if (ShowLeftLeg) - { - // LeftLeg - // Face 1 - GL.TexCoord2(TexVal * 20d, TexVal * 52d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 24d, TexVal * 52d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 24d, TexVal * 64d); - GL.Vertex3(4, -16, 2); - GL.TexCoord2(TexVal * 20d, TexVal * 64d); - GL.Vertex3(0, -16, 2); - // Face 2 - GL.TexCoord2(TexVal * 32d, TexVal * 52d); - GL.Vertex3(0, -4, -2); - GL.TexCoord2(TexVal * 28d, TexVal * 52d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 28d, TexVal * 64d); - GL.Vertex3(4, -16, -2); - GL.TexCoord2(TexVal * 32d, TexVal * 64d); - GL.Vertex3(0, -16, -2); - // Face 3 - GL.TexCoord2(TexVal * 20d, TexVal * 52d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 16d, TexVal * 52d); - GL.Vertex3(0, -4, -2); - GL.TexCoord2(TexVal * 16d, TexVal * 64d); - GL.Vertex3(0, -16, -2); - GL.TexCoord2(TexVal * 20d, TexVal * 64d); - GL.Vertex3(0, -16, 2); - // Face 4 - GL.TexCoord2(TexVal * 24d, TexVal * 52d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 52d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 28d, TexVal * 64d); - GL.Vertex3(4, -16, -2); - GL.TexCoord2(TexVal * 24d, TexVal * 64d); - GL.Vertex3(4, -16, 2); - // Face 5 - GL.TexCoord2(TexVal * 20d, TexVal * 52d); - GL.Vertex3(0, -4, 2); - GL.TexCoord2(TexVal * 24d, TexVal * 52d); - GL.Vertex3(4, -4, 2); - GL.TexCoord2(TexVal * 24d, TexVal * 48d); - GL.Vertex3(4, -4, -2); - GL.TexCoord2(TexVal * 20d, TexVal * 48d); - GL.Vertex3(0, -4, -2); - // Face 6 - GL.TexCoord2(TexVal * 24d, TexVal * 52d); - GL.Vertex3(0, -16, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 52d); - GL.Vertex3(4, -16, 2); - GL.TexCoord2(TexVal * 28d, TexVal * 48d); - GL.Vertex3(4, -16, -2); - GL.TexCoord2(TexVal * 24d, TexVal * 48d); - GL.Vertex3(0, -16, -2); - } - GL.End(); - - GL.Enable(EnableCap.AlphaTest); // Enable transparent - GL.AlphaFunc(AlphaFunction.Greater, 0.7f); - //GL.Enable(EnableCap.Blend); // Enable transparent - //GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.DstAlpha); - - GL.Begin(PrimitiveType.Quads); - - if (ShowBodyOverlay) - { - // Face 1 - GL.TexCoord2(TexVal * 20d, TexVal * 36d); - GL.Vertex3(-4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 36d); - GL.Vertex3(4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 48d); - GL.Vertex3(4.24d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 20d, TexVal * 48d); - GL.Vertex3(-4.24d, -4.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 40d, TexVal * 36d); - GL.Vertex3(-4.24d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 32d, TexVal * 36d); - GL.Vertex3(4.24d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 32d, TexVal * 48d); - GL.Vertex3(4.24d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 40d, TexVal * 48d); - GL.Vertex3(-4.24d, -4.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 16d, TexVal * 36d); - GL.Vertex3(-4.24d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 20d, TexVal * 36d); - GL.Vertex3(-4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 20d, TexVal * 48d); - GL.Vertex3(-4.24d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 16d, TexVal * 48d); - GL.Vertex3(-4.24d, -4.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 32d, TexVal * 36d); - GL.Vertex3(4.24d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 36d); - GL.Vertex3(4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 48d); - GL.Vertex3(4.24d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 32d, TexVal * 48d); - GL.Vertex3(4.24d, -4.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 20d, TexVal * 36d); - GL.Vertex3(-4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 36d); - GL.Vertex3(4.24d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 32d); - GL.Vertex3(4.24d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 20d, TexVal * 32d); - GL.Vertex3(-4.24d, 8.36d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 28d, TexVal * 36d); - GL.Vertex3(-4.24d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 36d, TexVal * 36d); - GL.Vertex3(4.24d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 36d, TexVal * 32d); - GL.Vertex3(4.24d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 28d, TexVal * 32d); - GL.Vertex3(-4.24d, -4.36d, -2.12d); - } - - if (ShowHeadOverlay) - { - // Head - // Face 1 - GL.TexCoord2(TexVal * 40d, TexVal * 8d); - GL.Vertex3(-4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 48d, TexVal * 8d); - GL.Vertex3(4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 48d, TexVal * 16d); - GL.Vertex3(4.24d, 7.76d, 4.24d); - GL.TexCoord2(TexVal * 40d, TexVal * 16d); - GL.Vertex3(-4.24d, 7.76d, 4.24d); - // Face 2 - GL.TexCoord2(TexVal * 64d, TexVal * 8d); - GL.Vertex3(-4.24d, 16.24d, -4.24d); - GL.TexCoord2(TexVal * 56d, TexVal * 8d); - GL.Vertex3(4.24d, 16.24d, -4.24d); - GL.TexCoord2(TexVal * 56d, TexVal * 16d); - GL.Vertex3(4.24d, 7.76d, -4.24d); - GL.TexCoord2(TexVal * 64d, TexVal * 16d); - GL.Vertex3(-4.24d, 7.76d, -4.24d); - // Face 3 - GL.TexCoord2(TexVal * 40d, TexVal * 8d); - GL.Vertex3(-4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 32d, TexVal * 8d); - GL.Vertex3(-4.24d, 16.24d, -4.24d); - GL.TexCoord2(TexVal * 32d, TexVal * 16d); - GL.Vertex3(-4.24d, 7.76d, -4.24d); - GL.TexCoord2(TexVal * 40d, TexVal * 16d); - GL.Vertex3(-4.24d, 7.76d, 4.24d); - // Face 4 - GL.TexCoord2(TexVal * 48d, TexVal * 8d); - GL.Vertex3(4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 56d, TexVal * 8d); - GL.Vertex3(4.24d, 16.24d, -4.24d); - GL.TexCoord2(TexVal * 56d, TexVal * 16d); - GL.Vertex3(4.24d, 7.76d, -4.24d); - GL.TexCoord2(TexVal * 48d, TexVal * 16d); - GL.Vertex3(4.24d, 7.76d, 4.24d); - // Face 5 - GL.TexCoord2(TexVal * 40d, TexVal * 8d); - GL.Vertex3(-4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 48d, TexVal * 8d); - GL.Vertex3(4.24d, 16.24d, 4.24d); - GL.TexCoord2(TexVal * 48d, 0d); - GL.Vertex3(4.24d, 16.24d, -4.24d); - GL.TexCoord2(TexVal * 40d, 0d); - GL.Vertex3(-4.24d, 16.24d, -4.24d); - // Face 6 - GL.TexCoord2(TexVal * 48d, TexVal * 8d); - GL.Vertex3(-4.24d, 7.76d, 4.24d); - GL.TexCoord2(TexVal * 56d, TexVal * 8d); - GL.Vertex3(4.24d, 7.76d, 4.24d); - GL.TexCoord2(TexVal * 56d, 0d); - GL.Vertex3(4.24d, 7.76d, -4.24d); - GL.TexCoord2(TexVal * 48d, 0d); - GL.Vertex3(-4.24d, 7.76d, -4.24d); - } - - if (Model == Models.Steve) - { - - if (ShowLeftArmOverlay) - { - // LeftArm - // Face 1 - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 52d); - GL.Vertex3(8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 64d); - GL.Vertex3(8.12d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 64d); - GL.Vertex3(3.88d, -4.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 64d, TexVal * 52d); - GL.Vertex3(3.88d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 60d, TexVal * 52d); - GL.Vertex3(8.12d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 60d, TexVal * 64d); - GL.Vertex3(8.12d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 64d, TexVal * 64d); - GL.Vertex3(3.88d, -4.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 48d, TexVal * 52d); - GL.Vertex3(3.88d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 64d); - GL.Vertex3(3.88d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 64d); - GL.Vertex3(3.88d, -4.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 60d, TexVal * 52d); - GL.Vertex3(8.12d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 52d); - GL.Vertex3(8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 64d); - GL.Vertex3(8.12d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 60d, TexVal * 64d); - GL.Vertex3(8.12d, -4.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 52d); - GL.Vertex3(8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 48d); - GL.Vertex3(8.12d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 48d); - GL.Vertex3(3.88d, 8.36d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 56d, TexVal * 52d); - GL.Vertex3(3.88d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 60d, TexVal * 52d); - GL.Vertex3(8.12d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 60d, TexVal * 48d); - GL.Vertex3(8.12d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 48d); - GL.Vertex3(3.88d, -4.36d, -2.12d); - } - - if (ShowRightArmOverlay) - { - // RightArm - // Face 1 - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 36d); - GL.Vertex3(-3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 48d); - GL.Vertex3(-3.88d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 48d); - GL.Vertex3(-8.12d, -4.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 56d, TexVal * 36d); - GL.Vertex3(-8.12d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 36d); - GL.Vertex3(-3.88d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 48d); - GL.Vertex3(-3.88d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 56d, TexVal * 48d); - GL.Vertex3(-8.12d, -4.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 40d, TexVal * 36d); - GL.Vertex3(-8.12d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 48d); - GL.Vertex3(-8.12d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 40d, TexVal * 48d); - GL.Vertex3(-8.12d, -4.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 52d, TexVal * 36d); - GL.Vertex3(-3.88d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 36d); - GL.Vertex3(-3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 48d); - GL.Vertex3(-3.88d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 48d); - GL.Vertex3(-3.88d, -4.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-8.12d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 36d); - GL.Vertex3(-3.88d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 32d); - GL.Vertex3(-3.88d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-8.12d, 8.36d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 48d, TexVal * 36d); - GL.Vertex3(-8.12d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 36d); - GL.Vertex3(-3.88d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 32d); - GL.Vertex3(-3.88d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 32d); - GL.Vertex3(-8.12d, -4.36d, -2.12d); - } - } - - else - { - - if (ShowLeftArmOverlay) - { - // LefttArm - // Face 1 - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 52d); - GL.Vertex3(7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 64d); - GL.Vertex3(7.09d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 64d); - GL.Vertex3(3.91d, -4.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 62d, TexVal * 52d); - GL.Vertex3(3.91d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 59d, TexVal * 52d); - GL.Vertex3(7.09d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 59d, TexVal * 64d); - GL.Vertex3(7.09d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 62d, TexVal * 64d); - GL.Vertex3(3.91d, -4.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 48d, TexVal * 52d); - GL.Vertex3(3.91d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 64d); - GL.Vertex3(3.91d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 48d, TexVal * 64d); - GL.Vertex3(3.91d, -4.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 59d, TexVal * 52d); - GL.Vertex3(7.09d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 52d); - GL.Vertex3(7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 64d); - GL.Vertex3(7.09d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 59d, TexVal * 64d); - GL.Vertex3(7.09d, -4.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 52d, TexVal * 52d); - GL.Vertex3(3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 52d); - GL.Vertex3(7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 48d); - GL.Vertex3(7.09d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 52d, TexVal * 48d); - GL.Vertex3(3.91d, 8.36d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 55d, TexVal * 52d); - GL.Vertex3(3.91d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 58d, TexVal * 52d); - GL.Vertex3(7.09d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 58d, TexVal * 48d); - GL.Vertex3(7.09d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 55d, TexVal * 48d); - GL.Vertex3(3.91d, -4.36d, -2.12d); - } - - if (ShowRightArmOverlay) - { - // RightArm - // Face 1 - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 36d); - GL.Vertex3(-3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 48d); - GL.Vertex3(-3.91d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 48d); - GL.Vertex3(-7.09d, -4.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 54d, TexVal * 36d); - GL.Vertex3(-7.09d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 51d, TexVal * 36d); - GL.Vertex3(-3.91d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 51d, TexVal * 48d); - GL.Vertex3(-3.91d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 54d, TexVal * 48d); - GL.Vertex3(-7.09d, -4.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 40d, TexVal * 36d); - GL.Vertex3(-7.09d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 48d); - GL.Vertex3(-7.09d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 40d, TexVal * 48d); - GL.Vertex3(-7.09d, -4.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 51d, TexVal * 36d); - GL.Vertex3(-3.91d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 36d); - GL.Vertex3(-3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 48d); - GL.Vertex3(-3.91d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 51d, TexVal * 48d); - GL.Vertex3(-3.91d, -4.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 44d, TexVal * 36d); - GL.Vertex3(-7.09d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 36d); - GL.Vertex3(-3.91d, 8.36d, 2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 32d); - GL.Vertex3(-3.91d, 8.36d, -2.12d); - GL.TexCoord2(TexVal * 44d, TexVal * 32d); - GL.Vertex3(-7.09d, 8.36d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 47d, TexVal * 36d); - GL.Vertex3(-7.09d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 50d, TexVal * 36d); - GL.Vertex3(-3.91d, -4.36d, 2.12d); - GL.TexCoord2(TexVal * 50d, TexVal * 32d); - GL.Vertex3(-3.91d, -4.36d, -2.12d); - GL.TexCoord2(TexVal * 47d, TexVal * 32d); - GL.Vertex3(-7.09d, -4.36d, -2.12d); - } - - } - - if (ShowRightLegOverlay) - { - // RightLeg - // Face 1 - GL.TexCoord2(TexVal * 4d, TexVal * 36d); - GL.Vertex3(-4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 36d); - GL.Vertex3(0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 48d); - GL.Vertex3(0.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 48d); - GL.Vertex3(-4.12d, -16.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 16d, TexVal * 36d); - GL.Vertex3(-4.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 36d); - GL.Vertex3(0.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 48d); - GL.Vertex3(0.12d, -16.36d, -2.12d); - GL.TexCoord2(TexVal * 16d, TexVal * 48d); - GL.Vertex3(-4.12d, -16.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 0d, TexVal * 36d); - GL.Vertex3(-4.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 36d); - GL.Vertex3(-4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 48d); - GL.Vertex3(-4.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 0d, TexVal * 48d); - GL.Vertex3(-4.12d, -16.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 12d, TexVal * 36d); - GL.Vertex3(0.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 36d); - GL.Vertex3(0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 48d); - GL.Vertex3(0.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 48d); - GL.Vertex3(0.12d, -16.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 4d, TexVal * 36d); - GL.Vertex3(-4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 36d); - GL.Vertex3(0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 32d); - GL.Vertex3(0.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 32d); - GL.Vertex3(-4.12d, -3.64d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 8d, TexVal * 36d); - GL.Vertex3(-4.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 36d); - GL.Vertex3(0.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 32d); - GL.Vertex3(0.12d, -16.36d, -2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 32d); - GL.Vertex3(-4.12d, -16.36d, -2.12d); - } - - if (ShowLeftLegOverlay) - { - // LeftLeg - // Face 1 - GL.TexCoord2(TexVal * 4d, TexVal * 52d); - GL.Vertex3(-0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 52d); - GL.Vertex3(4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 64d); - GL.Vertex3(4.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 64d); - GL.Vertex3(-0.12d, -16.36d, 2.12d); - // Face 2 - GL.TexCoord2(TexVal * 16d, TexVal * 52d); - GL.Vertex3(-0.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 52d); - GL.Vertex3(4.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 64d); - GL.Vertex3(4.12d, -16.36d, -2.12d); - GL.TexCoord2(TexVal * 16d, TexVal * 64d); - GL.Vertex3(-0.12d, -16.36d, -2.12d); - // Face 3 - GL.TexCoord2(TexVal * 0d, TexVal * 52d); - GL.Vertex3(-0.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 52d); - GL.Vertex3(-0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 64d); - GL.Vertex3(-0.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 0d, TexVal * 64d); - GL.Vertex3(-0.12d, -16.36d, -2.12d); - // Face 4 - GL.TexCoord2(TexVal * 12d, TexVal * 52d); - GL.Vertex3(4.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 52d); - GL.Vertex3(4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 64d); - GL.Vertex3(4.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 64d); - GL.Vertex3(4.12d, -16.36d, -2.12d); - // Face 5 - GL.TexCoord2(TexVal * 4d, TexVal * 52d); - GL.Vertex3(-0.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 52d); - GL.Vertex3(4.12d, -3.64d, 2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 48d); - GL.Vertex3(4.12d, -3.64d, -2.12d); - GL.TexCoord2(TexVal * 4d, TexVal * 48d); - GL.Vertex3(-0.12d, -3.64d, -2.12d); - // Face 6 - GL.TexCoord2(TexVal * 8d, TexVal * 52d); - GL.Vertex3(-0.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 52d); - GL.Vertex3(4.12d, -16.36d, 2.12d); - GL.TexCoord2(TexVal * 12d, TexVal * 48d); - GL.Vertex3(4.12d, -16.36d, -2.12d); - GL.TexCoord2(TexVal * 8d, TexVal * 48d); - GL.Vertex3(-0.12d, -16.36d, -2.12d); - } - - GL.DeleteTexture(texID); - - // Finish the begin mode with "end" - GL.End(); - GL.PopMatrix(); - // Finally... - SwapBuffers(); // Takes from the 'GL' and puts into control } - private bool IsMouseDown; - private bool IsRightMouseDown; - private bool IsMouseHidden; - private bool IsMouseHit; - private Point OldLoc; - private Point MouseLoc; - - public event BeginChangedEventHandler BeginChanged; - - public delegate void BeginChangedEventHandler(object sender, Bitmap LastSkin); - - private Ray GlobalMouseRay; // To use the var golbaly in the code - private Vector3 GlobalCameraPos; + protected override bool ProcessDialogKey(Keys keyData) + { +#if DEBUG + switch (keyData) + { + case Keys.Escape: + debugLabel.Visible = !debugLabel.Visible; + return true; + case Keys.F1: + var fileDialog = new OpenFileDialog() + { + Filter = "texture|*.png", + }; + if (fileDialog.ShowDialog() == DialogResult.OK) + { + Texture = Image.FromFile(fileDialog.FileName) as Bitmap; + } + return true; + } +#endif + return base.ProcessDialogKey(keyData); + } protected override void OnMouseDown(MouseEventArgs e) { - if (!IsMouseDown && e.Button == MouseButtons.Left) // Left mouse button + if (!IsMouseDown && e.Button == MouseButtons.Left) { // If the ray didn't hit the model then rotate the model - OldLoc = Cursor.Position; // Store the old mouse position to reset it when the action is over + PreviousMouseLocation = Cursor.Position; // Store the old mouse position to reset it when the action is over if (!IsMouseHidden) // Hide the mouse { Cursor.Hide(); @@ -1514,9 +606,9 @@ namespace PckStudio.Rendering MouseLoc = Cursor.Position; // Store the current mouse position to use it for the rotate action IsMouseDown = true; } - else if (!IsRightMouseDown && e.Button == MouseButtons.Right) // Right mouse button + else if (!IsRightMouseDown && e.Button == MouseButtons.Right) { - OldLoc = Cursor.Position; // Store the old mouse position to reset it when the action is over + PreviousMouseLocation = Cursor.Position; // Store the old mouse position to reset it when the action is over if (!IsMouseHidden) // Hide the mouse { Cursor.Hide(); @@ -1531,18 +623,16 @@ namespace PckStudio.Rendering { if (IsMouseHidden) { - Cursor.Show(); // Show the mouse - IsMouseHidden = false; - Cursor.Position = OldLoc; // Rest the mouse position - IsMouseDown = false; // Clear the booleans - IsRightMouseDown = false; + Cursor.Position = PreviousMouseLocation; + IsMouseDown = IsMouseHidden = IsRightMouseDown = false; + Cursor.Show(); } - IsMouseHit = false; } private void Move_Tick(object sender, EventArgs e) { - if (IsMouseDown) // Rotate the model + // Rotate the model + if (IsMouseDown) { float rotationYDelta = (float)Math.Round((Cursor.Position.X - MouseLoc.X) * 0.5f); float rotationXDelta = (float)Math.Round(-(Cursor.Position.Y - MouseLoc.Y) * 0.5f); @@ -1550,11 +640,13 @@ namespace PckStudio.Rendering Refresh(); Cursor.Position = new Point((int)Math.Round(Screen.PrimaryScreen.Bounds.Width / 2d), (int)Math.Round(Screen.PrimaryScreen.Bounds.Height / 2d)); MouseLoc = Cursor.Position; + return; } - else if (IsRightMouseDown) // Move the model + // Move the model + if (IsRightMouseDown) { - float deltaX = -(Cursor.Position.X - MouseLoc.X) * 0.5f / (float)Zoom; - float deltaY = (Cursor.Position.Y - MouseLoc.Y) * 0.5f / (float)Zoom; + float deltaX = -(Cursor.Position.X - MouseLoc.X) * 0.5f / (float)FieldOfView; + float deltaY = (Cursor.Position.Y - MouseLoc.Y) * 0.5f / (float)FieldOfView; LookAngle += new Vector2(deltaX, deltaY); Refresh(); Cursor.Position = new Point((int)Math.Round(Screen.PrimaryScreen.Bounds.Height / 2d), (int)Math.Round(Screen.PrimaryScreen.Bounds.Height / 2d)); @@ -1564,7 +656,7 @@ namespace PckStudio.Rendering protected override void OnMouseWheel(MouseEventArgs e) { - Zoom += e.Delta * 0.005d; + FieldOfView += e.Delta * 0.005d; Refresh(); base.OnMouseWheel(e); } @@ -1577,32 +669,9 @@ namespace PckStudio.Rendering private List MousePoints = new List(); private List tmpMousePoints = new List(); - public event SkinChangedEventHandler SkinChanged; + public event TextureChangedEventHandler TextureChanged; - public delegate void SkinChangedEventHandler(object sender, bool IsLeft); - private Random _PaintPixel_rNumber = new Random(); - - public void PaintPixel(Vector3 Vector, bool Second = false) - { - Bitmap tmpSkin = (Bitmap)Texture.Clone(); - Point Point; - var XUp = default(Vector3); - var YUp = default(Vector3); - var Left = default(bool); - if (Second) - { - Point = Get2nd2DFrom3D(Vector, ref XUp, ref YUp); - } - else - { - Point = Get2DFrom3D(Vector, ref XUp, ref YUp); - if (Point.Y > 31) - Left = true; - } - var Points = new List(); - tmpSkin.Dispose(); - SkinChanged?.Invoke(this, Left); - } + public delegate void TextureChangedEventHandler(object sender, bool IsLeft); public Point Get2DFrom3D(Vector3 Vector, ref Vector3 XUp, ref Vector3 YUp) { diff --git a/PCK-Studio/Rendering/Shader.cs b/PCK-Studio/Rendering/Shader.cs new file mode 100644 index 00000000..3e32aa43 --- /dev/null +++ b/PCK-Studio/Rendering/Shader.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal class Shader + { + private int _programId; + private Dictionary locationCache = new Dictionary(); + + private Shader(int programId) + { + _programId = programId; + } + + public void Bind() + { + GL.UseProgram(_programId); + } + + [Conditional("DEBUG")] + public void Unbind() + { + GL.UseProgram(0); + } + + public void SetUniform1(string name, int value) + { + int location = GetUniformLocation(name); + GL.Uniform1(location, value); + } + + public void SetUniform4(string name, Vector4 value) + { + int location = GetUniformLocation(name); + GL.Uniform4(location, value); + } + + public void SetUniform4(string name, Color color) + { + int location = GetUniformLocation(name); + GL.Uniform4(location, color); + } + + public void SetUniformMat4(string name, ref Matrix4 matrix) + { + int location = GetUniformLocation(name); + GL.UniformMatrix4(location, false, ref matrix); + } + + private int GetUniformLocation(string name) + { + if (locationCache.ContainsKey(name)) + return locationCache[name]; + int location = GL.GetUniformLocation(_programId, name); + locationCache.Add(name, location); + return location; + } + + private static int CompileShader(ShaderType type, string shaderSource) + { + int shaderId = GL.CreateShader(type); + GL.ShaderSource(shaderId, shaderSource); + GL.CompileShader(shaderId); + + GL.GetShader(shaderId, ShaderParameter.CompileStatus, out int status); + + if (status == 0) + { + GL.GetShader(shaderId, ShaderParameter.InfoLogLength, out int length); + GL.GetShaderInfoLog(shaderId, length, out _, out string infoLog); + Trace.TraceError(infoLog); + GL.DeleteShader(shaderId); + return 0; + } + return shaderId; + } + + public static Shader Create(string vertexSource, string fragmentSource) + { + int programId = GL.CreateProgram(); + + int vertexShader = CompileShader(ShaderType.VertexShader, vertexSource); + int fragmentShader = CompileShader(ShaderType.FragmentShader, fragmentSource); + + GL.AttachShader(programId, vertexShader); + GL.AttachShader(programId, fragmentShader); + + GL.LinkProgram(programId); + GL.ValidateProgram(programId); + + Trace.TraceInformation(GL.GetProgramInfoLog(programId)); + + GL.DeleteShader(vertexShader); + GL.DeleteShader(fragmentShader); + return new Shader(programId); + } + + } +} diff --git a/PCK-Studio/Rendering/Texture2D.cs b/PCK-Studio/Rendering/Texture2D.cs new file mode 100644 index 00000000..ffdfa784 --- /dev/null +++ b/PCK-Studio/Rendering/Texture2D.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal class Texture2D : IDisposable + { + private int _id; + + public Texture2D(string filepath) + : this(Image.FromFile(filepath)) + { + + } + + public Texture2D(Image image) + : this(new Bitmap(image)) + { + + } + + private Texture2D(Bitmap bitmap) + { + _id = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, _id); + + GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); + + var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); + bitmap.UnlockBits(data); + + GL.BindTexture(TextureTarget.Texture2D, 0); + } + + public void Bind(int slot) + { + GL.ActiveTexture(TextureUnit.Texture0 + slot); + GL.BindTexture(TextureTarget.Texture2D, _id); + } + + public void Bind() + { + Bind(0); + } + + [Conditional("DEBUG")] + public void Unbind() + { + GL.BindTexture(TextureTarget.Texture2D, 0); + } + + public void Dispose() + { + GL.DeleteTexture(_id); + } + + } +} diff --git a/PCK-Studio/Rendering/VertexArray.cs b/PCK-Studio/Rendering/VertexArray.cs new file mode 100644 index 00000000..9fc45a46 --- /dev/null +++ b/PCK-Studio/Rendering/VertexArray.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal class VertexArray : IDisposable + { + private int _id; + + public VertexArray() + { + _id = GL.GenVertexArray(); + } + + public void AddBuffer(VertexBuffer buffer, VertexBufferLayout layout) where T : struct + { + Bind(); + buffer.Bind(); + var elements = layout.GetElements(); + int offset = 0; + for (int i = 0; i < elements.Count; i++) + { + var element = elements[i]; + GL.EnableVertexAttribArray(i); + GL.VertexAttribPointer(i, element.Count, element.Type, element.Normalize, layout.GetStride(), offset); + offset += layout.GetStride(); + } + } + + public void Bind() + { + GL.BindVertexArray(_id); + } + + [Conditional("DEBUG")] + public void Unbind() + { + GL.BindVertexArray(0); + } + + public void Dispose() + { + GL.DeleteVertexArray(_id); + } + } +} diff --git a/PCK-Studio/Rendering/VertexBuffer.cs b/PCK-Studio/Rendering/VertexBuffer.cs new file mode 100644 index 00000000..38e4dd7d --- /dev/null +++ b/PCK-Studio/Rendering/VertexBuffer.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Markup; +using OpenTK; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + internal class VertexBuffer : IDisposable where T : struct + { + private int _id; + + public VertexBuffer(T[] data, int size) + { + _id = GL.GenBuffer(); + Bind(); + GL.BufferData(BufferTarget.ArrayBuffer, size, data, BufferUsageHint.StaticDraw); + } + + public void Bind() + { + GL.BindBuffer(BufferTarget.ArrayBuffer, _id); + } + + [Conditional("DEBUG")] + public void Unbind() + { + GL.BindBuffer(BufferTarget.ArrayBuffer, 0); + } + + public void Dispose() + { + GL.DeleteBuffer(_id); + } + } +} diff --git a/PCK-Studio/Rendering/VertexBufferLayout.cs b/PCK-Studio/Rendering/VertexBufferLayout.cs new file mode 100644 index 00000000..33fc0fb3 --- /dev/null +++ b/PCK-Studio/Rendering/VertexBufferLayout.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; + +namespace PckStudio.Rendering +{ + struct VertexBufferElement + { + public readonly VertexAttribPointerType Type; + public readonly int Count; + public readonly bool Normalize; + + public static int GetStrideSize(VertexAttribPointerType type) + { + return type switch + { + VertexAttribPointerType.Int => 4, + VertexAttribPointerType.UnsignedInt => 4, + VertexAttribPointerType.Float => 4, + _ => 0 + }; + } + + public VertexBufferElement(VertexAttribPointerType type, int count, bool normalize) + { + Type = type; + Count = count; + Normalize = normalize; + } + } + + internal class VertexBufferLayout + { + private List elements; + private int stride; + + + public VertexBufferLayout() + { + elements = new List(); + stride = 0; + } + + public ReadOnlyCollection GetElements() + { + return elements.AsReadOnly(); + } + + public void Add(int count) + { + if (typeof(T).Equals(typeof(float))) + { + elements.Add(new VertexBufferElement(VertexAttribPointerType.Float, count, false)); + stride += count * VertexBufferElement.GetStrideSize(VertexAttribPointerType.Float); + } + if (typeof(T).Equals(typeof(int))) + { + elements.Add(new VertexBufferElement(VertexAttribPointerType.Int, count, false)); + stride += count * VertexBufferElement.GetStrideSize(VertexAttribPointerType.Int); + } + if (typeof(T).Equals(typeof(uint))) + { + elements.Add(new VertexBufferElement(VertexAttribPointerType.UnsignedInt, count, false)); + stride += count * VertexBufferElement.GetStrideSize(VertexAttribPointerType.UnsignedInt); + } + } + + internal int GetStride() + { + return stride; + } + } +} diff --git a/PCK-Studio/Resources/fragment.glsl b/PCK-Studio/Resources/fragment.glsl new file mode 100644 index 00000000..5c13ed1c --- /dev/null +++ b/PCK-Studio/Resources/fragment.glsl @@ -0,0 +1,15 @@ +#version 330 core + +layout(location = 0) out vec4 color; + +uniform vec4 u_Color; +uniform sampler2D u_Texture; + +in vec2 v_TexCoord; + +void main() +{ + vec4 texColor = texture(u_Texture, v_TexCoord); + color = u_Color; + color = texColor; +}; \ No newline at end of file diff --git a/PCK-Studio/Resources/steve.png b/PCK-Studio/Resources/steve.png deleted file mode 100644 index 90d4fa23..00000000 Binary files a/PCK-Studio/Resources/steve.png and /dev/null differ diff --git a/PCK-Studio/Resources/vertexShader.glsl b/PCK-Studio/Resources/vertexShader.glsl new file mode 100644 index 00000000..a9ee9052 --- /dev/null +++ b/PCK-Studio/Resources/vertexShader.glsl @@ -0,0 +1,14 @@ +#version 330 core + +layout(location = 0) in vec4 vertexPosition; +layout(location = 1) in vec2 texCoord; + +uniform mat4 u_MVP; + +out vec2 v_TexCoord; + +void main() +{ + gl_Position = u_MVP * vertexPosition; + v_TexCoord = texCoord; +}; \ No newline at end of file