Simple 2D-Kamera-Bewegung implementiert

master
mono 4 years ago
parent 3e47899971
commit 71e600b9c9

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
</configuration>

@ -1,56 +0,0 @@
namespace JuicyGraphics {
partial class mainForm {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.canvas2 = new JuicyGraphics.canvas();
((System.ComponentModel.ISupportInitialize)(this.canvas2)).BeginInit();
this.SuspendLayout();
//
// canvas2
//
this.canvas2.Dock = System.Windows.Forms.DockStyle.Fill;
this.canvas2.Location = new System.Drawing.Point(0, 0);
this.canvas2.Name = "canvas2";
this.canvas2.Size = new System.Drawing.Size(704, 521);
this.canvas2.TabIndex = 3;
this.canvas2.Text = "canvas2";
//
// mainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 521);
this.Controls.Add(this.canvas2);
this.Name = "mainForm";
this.Text = "JuicyGraphics";
((System.ComponentModel.ISupportInitialize)(this.canvas2)).EndInit();
this.ResumeLayout(false);
}
#endregion
private canvas canvas2;
}
}

@ -8,8 +8,9 @@
<OutputType>WinExe</OutputType>
<RootNamespace>JuicyGraphics</RootNamespace>
<AssemblyName>JuicyGraphics</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -31,9 +32,14 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -45,16 +51,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="canvas.cs">
<Compile Include="SharpGL\Matrix.cs" />
<Compile Include="JuicyGraphics\renderer\camera2D.cs" />
<Compile Include="JuicyGraphics\renderer\iGraphicalObject.cs" />
<Compile Include="JuicyGraphics\renderer\line.cs" />
<Compile Include="JuicyGraphics\renderer\renderCam.cs" />
<Compile Include="JuicyGraphics\ui\canvas.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Form1.cs">
<Compile Include="JuicyGraphics\ui\Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<Compile Include="JuicyGraphics\ui\Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="JuicyGraphics\Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpGL\DIBSection.cs" />
<Compile Include="SharpGL\Enumerations\OpenGLEnumerations.cs" />
@ -80,7 +91,7 @@
<Compile Include="SharpGL\VertexBuffers\VertexBuffer.cs" />
<Compile Include="SharpGL\VertexBuffers\VertexBufferArray.cs" />
<Compile Include="SharpGL\Win32.cs" />
<EmbeddedResource Include="Form1.resx">
<EmbeddedResource Include="JuicyGraphics\ui\Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
@ -91,6 +102,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -105,6 +117,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="JuicyGraphics\math\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,32 @@
using SharpGL;
using System.Numerics;
namespace Graphics {
class camera2D {
protected Matrix mat;
public Vector2 translation {
get {
return new Vector2((float)mat[0, 3], (float)mat[1, 3]);
}
set {
mat[0, 3] = value.X;
mat[1, 3] = value.Y;
}
}
public double scale {
get {
return mat[0, 0];
}
set {
mat[0, 0] = value;
mat[1, 1] = value;
}
}
public camera2D() {
mat = new Matrix(Matrix.Identity(4));
}
}
}

@ -0,0 +1,7 @@
using SharpGL;
namespace Graphics.Objects {
interface iGraphicalObject {
void render(renderCam context);
}
}

@ -0,0 +1,96 @@
using SharpGL;
using System.Numerics;
namespace Graphics.Objects {
class line : iGraphicalObject {
#region fields
Vector2 pt01;
Vector2 pt02;
double thickness01;
double thickness02;
double tilt01;
double tilt02;
#endregion
#region properties
#endregion
#region constructors
public line(Vector2 startPoint, Vector2 endPoint) {
pt01 = startPoint;
pt02 = endPoint;
thickness01 = 1.0;
thickness02 = 1.0;
tilt01 = 0.0;
tilt02 = 0.0;
}
public line(Vector2 startPoint, Vector2 endPoint, double thickness) {
pt01 = startPoint;
pt02 = endPoint;
thickness01 = thickness;
thickness02 = thickness;
tilt01 = 0.0;
tilt02 = 0.0;
}
public enum valueing { defineLinearThickness, defineBothTilts }
public line(Vector2 startPoint, Vector2 endPoint,
valueing defineType, double startPointParam, double endPointParam) {
pt01 = startPoint;
pt02 = endPoint;
switch (defineType) {
case valueing.defineLinearThickness:
thickness01 = startPointParam;
thickness02 = endPointParam;
tilt01 = 0.0;
tilt02 = 0.0;
break;
case valueing.defineBothTilts:
thickness01 = 1.0;
thickness02 = 1.0;
tilt01 = startPointParam;
tilt02 = endPointParam;
break;
default:
thickness01 = 1.0;
thickness02 = 1.0;
tilt01 = 0.0;
tilt02 = 0.0;
break;
}
}
public line(Vector2 startPoint, Vector2 endPoint,
double thickness, double tiltOfStartPoint, double tiltOfEndPoint) {
pt01 = startPoint;
pt02 = endPoint;
thickness01 = thickness;
thickness02 = thickness;
tilt01 = tiltOfStartPoint;
tilt02 = tiltOfEndPoint;
}
public line(Vector2 startPoint, Vector2 endPoint,
double thicknessOfStartPoint, double thicknessOfEndPoint,
double tiltOfStartPoint, double tiltOfEndPoint) {
pt01 = startPoint;
pt02 = endPoint;
thickness01 = thicknessOfStartPoint;
thickness02 = thicknessOfEndPoint;
tilt01 = tiltOfStartPoint;
tilt02 = tiltOfEndPoint;
}
#endregion
public void render(renderCam context) {
context.drawQuad(pt01, pt01 + new Vector2(0.03f, 0), pt02 + new Vector2(0.03f, 0), pt02);
}
}
}

@ -0,0 +1,37 @@
using System.Windows.Forms;
using System.Numerics;
using SharpGL;
namespace Graphics {
class renderCam : camera2D {
OpenGL gl;
Control ownerControl;
public renderCam(OpenGL glContext, Control owner) : base() {
gl = glContext;
ownerControl = owner;
}
public void attacheMatrix() {
gl.MultMatrix(mat);
}
public void drawTriangle(Vector2 corner01, Vector2 corner02, Vector2 corner03) {
gl.Vertex(corner01);
gl.Vertex(corner02);
gl.Vertex(corner03);
}
public void drawQuad(Vector2 corner01, Vector2 corner02, Vector2 corner03, Vector2 corner04) {
gl.Vertex(corner01);
gl.Vertex(corner02);
gl.Vertex(corner03);
gl.Vertex(corner03);
gl.Vertex(corner04);
gl.Vertex(corner01);
}
}
}

@ -0,0 +1,138 @@
namespace JuicyGraphics {
partial class mainForm {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.canvas1 = new JuicyGraphics.canvas();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.menuStrip1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.canvas1)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.editToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(704, 24);
this.menuStrip1.TabIndex = 4;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
this.editToolStripMenuItem.Text = "Edit";
//
// tabControl1
//
this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(13, 28);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(679, 481);
this.tabControl1.TabIndex = 5;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.canvas1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(671, 455);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Scene Editor";
this.tabPage1.UseVisualStyleBackColor = true;
//
// canvas1
//
this.canvas1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.canvas1.Location = new System.Drawing.Point(7, 7);
this.canvas1.Name = "canvas1";
this.canvas1.Size = new System.Drawing.Size(508, 442);
this.canvas1.TabIndex = 0;
this.canvas1.Text = "canvas1";
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(671, 455);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Object Editor";
this.tabPage2.UseVisualStyleBackColor = true;
//
// mainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 521);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "mainForm";
this.Text = "JuicyGraphics";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.canvas1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private canvas canvas1;
private System.Windows.Forms.TabPage tabPage2;
}
}

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

@ -0,0 +1,160 @@
using System;
using System.Windows.Forms;
using System.Windows;
using SharpGL.Enumerations;
using SharpGL.Version;
using SharpGL;
using System.ComponentModel;
using Graphics;
using Graphics.Objects;
using System.Numerics;
using System.Drawing;
namespace JuicyGraphics {
class canvas : Control, ISupportInitialize {
OpenGL GL = new OpenGL();
renderCam rc;
public canvas() {
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeOpenGL();
rc = new renderCam(GL, this);
}
void InitializeOpenGL() {
GL.Create(OpenGLVersion.OpenGL4_3, RenderContextType.NativeWindow, Width, Height, 32, this.Handle);
GL.ShadeModel(OpenGL.GL_SMOOTH);
GL.ClearDepth(1.0f);
GL.Enable(OpenGL.GL_DEPTH_TEST);
GL.DepthFunc(OpenGL.GL_LEQUAL);
GL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
GL.Viewport(0, 0, Width, Height);
}
bool renderingForDesigner() {
if (this == null)
return false;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return true;
Control p = this.Parent;
while (p != null) {
if (p.GetType().FullName.Contains(".DesignerFrame"))
return true;
p = p.Parent;
}
return false;
}
protected override void OnPaintBackground(PaintEventArgs e) {
if (renderingForDesigner()) { base.OnPaintBackground(e); }
return;
}
protected override void OnPaint(PaintEventArgs e) {
if (renderingForDesigner()) {
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeOpenGL();
}
GL.LoadIdentity();
GL.Ortho(-(Width / 2160.0), Width / 2160.0,
-(Height / 2160.0), Height / 2160.0,
-1, 1);
if (rc != null)
rc.attacheMatrix();
GL.MakeCurrent();
GL.ClearColor(0.3f, 0.35f, 0.7f, 1f);
GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
GL.Begin(BeginMode.Triangles);
GL.Color(0.9, 0.83, 0.1);
GL.Vertex(1.0, 1.0);
GL.Vertex(-1.0, -1.0);
GL.Vertex(-1.0, 1.0);
GL.Color(0, 0, 0);
line testLine = new line(new Vector2(-0.4f, 0.4f), new Vector2(0.4f, -0.4f));
testLine.render(rc);
GL.End();
GL.Flush();
var handleDeviceContext = e.Graphics.GetHdc();
GL.Blit(handleDeviceContext);
e.Graphics.ReleaseHdc(handleDeviceContext);
}
protected override void OnSizeChanged(EventArgs e) {
if (GL.RenderContextProvider == null)
return;
GL.SetDimensions(Width, Height);
GL.Viewport(0, 0, Width, Height);
Invalidate();
}
enum mouseInteractionMode { none, left, middle, right };
mouseInteractionMode pressedMouseButton = mouseInteractionMode.none;
Point prevMousePosition = Point.Empty;
protected override void OnMouseDown(MouseEventArgs e) {
switch (e.Button) {
case MouseButtons.Left:
pressedMouseButton = mouseInteractionMode.left;
break;
case MouseButtons.Middle:
pressedMouseButton = mouseInteractionMode.middle;
break;
case MouseButtons.Right:
pressedMouseButton = mouseInteractionMode.right;
break;
}
prevMousePosition = MousePosition;
}
protected override void OnMouseMove(MouseEventArgs e) {
switch (pressedMouseButton) {
case mouseInteractionMode.left:
break;
case mouseInteractionMode.middle:
rc.translation += new Vector2(MousePosition.X - prevMousePosition.X,
prevMousePosition.Y - MousePosition.Y) / 1080.0f;
Invalidate();
break;
case mouseInteractionMode.right:
break;
}
prevMousePosition = MousePosition;
}
protected override void OnMouseUp(MouseEventArgs e) {
switch (e.Button) {
case MouseButtons.Left:
if (pressedMouseButton == mouseInteractionMode.left)
pressedMouseButton = mouseInteractionMode.none;
break;
case MouseButtons.Middle:
if (pressedMouseButton == mouseInteractionMode.middle)
pressedMouseButton = mouseInteractionMode.none;
break;
case MouseButtons.Right:
if (pressedMouseButton == mouseInteractionMode.right)
pressedMouseButton = mouseInteractionMode.none;
break;
}
}
protected override void OnMouseWheel(MouseEventArgs e) {
rc.scale *= Math.Pow(1.0008, e.Delta);
Invalidate();
}
public void BeginInit() { }
public void EndInit() {
InitializeOpenGL();
OnSizeChanged(null);
}
}
}

@ -9,8 +9,9 @@
//------------------------------------------------------------------------------
namespace JuicyGraphics.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -22,29 +23,29 @@ namespace JuicyGraphics.Properties {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if ((resourceMan == null)) {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JuicyGraphics.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.

@ -9,14 +9,14 @@
//------------------------------------------------------------------------------
namespace JuicyGraphics.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;

File diff suppressed because it is too large Load Diff

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Runtime.InteropServices;
using SharpGL.RenderContextProviders;
using SharpGL.Version;
using System.Numerics;
namespace SharpGL
{
@ -3978,6 +3979,16 @@ namespace SharpGL
PostGLCall();
}
/// <summary>
/// Multiply the current matrix with the specified matrix.
/// </summary>
/// <param name="m">Points to 16 consecutive values that are used as the elements of a 4x4 column-major matrix.</param>
public void MultMatrix(Matrix m) {
PreGLCall();
glMultMatrixd(m.As1DArray);
PostGLCall();
}
/// <summary>
/// Multiply the current matrix with the specified matrix.
/// </summary>
@ -6003,12 +6014,22 @@ namespace SharpGL
return result;
}
/// <summary>
/// <summary>
/// Set the current vertex (must be called between 'Begin' and 'End').
/// </summary>
/// <param name="x">X Value.</param>
/// <param name="y">Y Value.</param>
public void Vertex(double x, double y)
/// <param name="vertex">The to the vertex pointing vector.</param>
public void Vertex(Vector2 vertex) {
PreGLCall();
glVertex2d(vertex.X, vertex.Y);
PostGLCall();
}
/// <summary>
/// Set the current vertex (must be called between 'Begin' and 'End').
/// </summary>
/// <param name="x">X Value.</param>
/// <param name="y">Y Value.</param>
public void Vertex(double x, double y)
{
PreGLCall();
glVertex2d(x, y);

@ -38,8 +38,7 @@ namespace SharpGL
string name = delegateType.Name;
// ftlPhysicsGuy - Better way
Delegate del = null;
if (extensionFunctions.TryGetValue(name, out del) == false)
if (extensionFunctions.TryGetValue(name, out Delegate del) == false)
{
IntPtr proc = Win32.wglGetProcAddress(name);
if (proc == IntPtr.Zero)

@ -1,85 +0,0 @@
using System;
using System.Windows.Forms;
using SharpGL.Enumerations;
using SharpGL.Version;
using SharpGL;
using System.ComponentModel;
namespace JuicyGraphics {
class canvas : Control, ISupportInitialize {
protected OpenGL GL = new OpenGL();
public canvas() {
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeOpenGL();
}
protected void InitializeOpenGL() {
GL.Create(OpenGLVersion.OpenGL4_3, RenderContextType.NativeWindow, Width, Height, 32, this.Handle);
GL.ShadeModel(OpenGL.GL_SMOOTH);
GL.ClearDepth(1.0f);
GL.Enable(OpenGL.GL_DEPTH_TEST);
GL.DepthFunc(OpenGL.GL_LEQUAL);
GL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
GL.Viewport(0, 0, Width, Height);
}
bool renderingForDesigner() {
if (this == null)
return false;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return true;
Control p = this.Parent;
while (p != null) {
if (p.GetType().FullName.Contains(".DesignerFrame"))
return true;
p = p.Parent;
}
return false;
}
protected override void OnPaintBackground(PaintEventArgs e) {
if (renderingForDesigner()) { base.OnPaintBackground(e); }
return;
}
protected override void OnPaint(PaintEventArgs e) {
if (renderingForDesigner()) {
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeOpenGL();
}
GL.MakeCurrent();
GL.ClearColor(0f, 0.3f, 0.7f, 1f);
GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
GL.Begin(BeginMode.Triangles);
GL.Color(0.8, 0.1, 0.1);
GL.Vertex(1.0, 1.0);
GL.Vertex(-1.0, -1.0); GL.Vertex(-1.0, 1.0);
GL.End();
GL.Flush();
var handleDeviceContext = e.Graphics.GetHdc();
GL.Blit(handleDeviceContext);
e.Graphics.ReleaseHdc(handleDeviceContext);
}
protected override void OnSizeChanged(EventArgs e) {
if (GL.RenderContextProvider == null)
return;
GL.SetDimensions(Width, Height);
GL.Viewport(0, 0, Width, Height);
Invalidate();
}
public void BeginInit() { }
public void EndInit() {
InitializeOpenGL();
OnSizeChanged(null);
}
}
}
Loading…
Cancel
Save