From 501da27b1a495e5dc79ef095c2bee96c12fbb2da Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 4 Nov 2007 15:33:43 +0000 Subject: [PATCH] --- Source/Examples/Tutorial/Textures.cs | 146 ++++++++++++++++++ .../WinForms/DerivedGLControl.Designer.cs | 37 +++++ Source/Examples/WinForms/DerivedGLControl.cs | 42 +++++ .../W04_Multiple_GLControls.Designer.cs | 74 +++++++++ .../WinForms/W04_Multiple_GLControls.cs | 32 ++++ .../WinForms/W04_Multiple_GLControls.resx | 120 ++++++++++++++ 6 files changed, 451 insertions(+) create mode 100644 Source/Examples/Tutorial/Textures.cs create mode 100644 Source/Examples/WinForms/DerivedGLControl.Designer.cs create mode 100644 Source/Examples/WinForms/DerivedGLControl.cs create mode 100644 Source/Examples/WinForms/W04_Multiple_GLControls.Designer.cs create mode 100644 Source/Examples/WinForms/W04_Multiple_GLControls.cs create mode 100644 Source/Examples/WinForms/W04_Multiple_GLControls.resx diff --git a/Source/Examples/Tutorial/Textures.cs b/Source/Examples/Tutorial/Textures.cs new file mode 100644 index 00000000..11c2f4dd --- /dev/null +++ b/Source/Examples/Tutorial/Textures.cs @@ -0,0 +1,146 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; +using System.IO; + +using System.Drawing; +using System.Drawing.Imaging; + +using OpenTK; +using OpenTK.OpenGL; +using OpenTK.Fonts; +using OpenTK.OpenGL.Enums; + +namespace Examples.Tutorial +{ + /// + /// Demonstrates simple OpenGL Texturing. + /// + public class Textures : GameWindow, IExample + { + Bitmap bitmap = new Bitmap("Data\\metal.jpg"); + int texture; + TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 24.0f)); + + public Textures() : base(new DisplayMode(800, 600), "OpenTK | Tutorial 5: Texturing") { } + + #region OnLoad + + /// + /// Setup OpenGL and load resources here. + /// + /// Not used. + public override void OnLoad(EventArgs e) + { + GL.ClearColor(Color.MidnightBlue); + GL.Enable(EnableCap.Texture2d); + + GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); + + //bitmap = new OpenTK.Fonts.Renderer().bmp; + //bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); + GL.GenTextures(1, out texture); + GL.BindTexture(TextureTarget.Texture2d, texture); + + BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + + GL.TexImage2D(TextureTarget.Texture2d, 0, PixelInternalFormat.Three, bitmap.Width, bitmap.Height, 0, + OpenTK.OpenGL.Enums.PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0); + + bitmap.UnlockBits(data); + + GL.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, (int)All.Linear); + GL.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, (int)All.Linear); + } + + #endregion + + #region OnResize + + /// + /// Respond to resize events here. + /// + /// Contains information on the new GameWindow size. + /// There is no need to call the base implementation. + protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) + { + GL.Viewport(0, 0, e.Width, e.Height); + + GL.MatrixMode(MatrixMode.Projection); + GL.LoadIdentity(); + GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0); + } + + #endregion + + #region OnUpdateFrame + + /// + /// Add your game logic here. + /// + /// Contains timing information. + /// There is no need to call the base implementation. + public override void OnUpdateFrame(UpdateFrameEventArgs e) + { + if (Keyboard[OpenTK.Input.Key.Escape]) + this.Exit(); + } + + #endregion + + #region OnRenderFrame + + /// + /// Add your game rendering code here. + /// + /// Contains timing information. + /// There is no need to call the base implementation. + public override void OnRenderFrame(RenderFrameEventArgs e) + { + GL.Clear(ClearBufferMask.ColorBufferBit); + + GL.LoadIdentity(); + GL.BindTexture(TextureTarget.Texture2d, texture); + + GL.Begin(BeginMode.Quads); + + GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-0.8f + 0.0375f, -0.8f + 0.0375f); + GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(0.8f + 0.0375f, -0.8f + 0.0375f); + GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(0.8f + 0.0375f, 0.8f + 0.0375f); + GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-0.8f + 0.0375f, 0.8f + 0.0375f); + + GL.End(); + + //sans. + GL.Scale(2.0f / Width, 2.0f / Height, 1.0f); + //sans.Print('A'); + + SwapBuffers(); + } + + #endregion + + #region IExample Members + + /// + /// Only used by the ExampleLauncher application, no need to add a Launch() method in your code. + /// Add a call to Run() in your Main() function instead. + /// + public void Launch() + { + this.Run(10.0, 5.0); + } + + #endregion + + public static readonly int order = 5; + } +} diff --git a/Source/Examples/WinForms/DerivedGLControl.Designer.cs b/Source/Examples/WinForms/DerivedGLControl.Designer.cs new file mode 100644 index 00000000..26605b60 --- /dev/null +++ b/Source/Examples/WinForms/DerivedGLControl.Designer.cs @@ -0,0 +1,37 @@ +namespace Examples.WinForms +{ + partial class DerivedGLControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/Source/Examples/WinForms/DerivedGLControl.cs b/Source/Examples/WinForms/DerivedGLControl.cs new file mode 100644 index 00000000..3f5ac3c5 --- /dev/null +++ b/Source/Examples/WinForms/DerivedGLControl.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Text; +using System.Windows.Forms; + +using OpenTK; +using OpenTK.OpenGL; +using OpenTK.OpenGL.Enums; + +namespace Examples.WinForms +{ + public partial class DerivedGLControl : GLControl + { + Color clearColor; + + public Color ClearColor + { + get { return clearColor; } + set + { + clearColor = value; + MakeCurrent(); + GL.ClearColor(clearColor); + } + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + if (!this.DesignMode) + { + MakeCurrent(); + GL.Clear(ClearBufferMask.ColorBufferBit); + SwapBuffers(); + } + } + } +} diff --git a/Source/Examples/WinForms/W04_Multiple_GLControls.Designer.cs b/Source/Examples/WinForms/W04_Multiple_GLControls.Designer.cs new file mode 100644 index 00000000..2cf38adb --- /dev/null +++ b/Source/Examples/WinForms/W04_Multiple_GLControls.Designer.cs @@ -0,0 +1,74 @@ +namespace Examples.WinForms +{ + partial class W04_Multiple_GLControls + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.derivedGLControl1 = new Examples.WinForms.DerivedGLControl(); + this.derivedGLControl2 = new Examples.WinForms.DerivedGLControl(); + this.SuspendLayout(); + // + // derivedGLControl1 + // + this.derivedGLControl1.BackColor = System.Drawing.Color.Black; + this.derivedGLControl1.ClearColor = System.Drawing.Color.Blue; + this.derivedGLControl1.Location = new System.Drawing.Point(12, 12); + this.derivedGLControl1.Name = "derivedGLControl1"; + this.derivedGLControl1.Size = new System.Drawing.Size(300, 225); + this.derivedGLControl1.TabIndex = 0; + this.derivedGLControl1.VSync = false; + // + // derivedGLControl2 + // + this.derivedGLControl2.BackColor = System.Drawing.Color.Black; + this.derivedGLControl2.ClearColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); + this.derivedGLControl2.Location = new System.Drawing.Point(319, 13); + this.derivedGLControl2.Name = "derivedGLControl2"; + this.derivedGLControl2.Size = new System.Drawing.Size(293, 224); + this.derivedGLControl2.TabIndex = 1; + this.derivedGLControl2.VSync = false; + // + // W04_Multiple_GLControls + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(624, 444); + this.Controls.Add(this.derivedGLControl2); + this.Controls.Add(this.derivedGLControl1); + this.Name = "W04_Multiple_GLControls"; + this.Text = "W04_Multiple_GLControls"; + this.ResumeLayout(false); + + } + + #endregion + + private DerivedGLControl derivedGLControl1; + private DerivedGLControl derivedGLControl2; + + } +} \ No newline at end of file diff --git a/Source/Examples/WinForms/W04_Multiple_GLControls.cs b/Source/Examples/WinForms/W04_Multiple_GLControls.cs new file mode 100644 index 00000000..b938ba22 --- /dev/null +++ b/Source/Examples/WinForms/W04_Multiple_GLControls.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +using OpenTK; +using OpenTK.OpenGL; + +namespace Examples.WinForms +{ + public partial class W04_Multiple_GLControls : Form, IExample + { + public W04_Multiple_GLControls() + { + InitializeComponent(); + } + + #region IExample Members + + public void Launch() + { + + } + + public static readonly int order = 4; + + #endregion + } +} \ No newline at end of file diff --git a/Source/Examples/WinForms/W04_Multiple_GLControls.resx b/Source/Examples/WinForms/W04_Multiple_GLControls.resx new file mode 100644 index 00000000..ff31a6db --- /dev/null +++ b/Source/Examples/WinForms/W04_Multiple_GLControls.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file