Erste Ansätze für einen Shader \o/

master
mono 4 years ago
parent ac39a65511
commit f22d60fa20

@ -0,0 +1,3 @@
@echo off
cls
git pull origin master

@ -105,6 +105,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="JuicyGraphics\renderer\shaders\background.frag">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

@ -1,9 +1,24 @@
using System.Numerics;
using System.Windows.Forms;
using SharpGL.Shaders;
using SharpGL;
using SharpGL.Enumerations;
using System.Reflection;
using System.IO;
namespace Graphics.Objects {
class gridBackground : iGraphicalObject {
const double realTileSize = 24.0f;
public void render(renderCam context) {
Shader renderGrid = new Shader();
renderGrid.Create(context.GL, OpenGL.GL_FRAGMENT_SHADER, "background.frag");
context.GL.Begin(BeginMode.Quads);
context.GL.Vertex(-1.0, -1.0);
context.GL.Vertex(1.0, -1.0);
context.GL.Vertex(1.0, 1.0);
context.GL.Vertex(-1.0, 1.0);
context.GL.End();
}
}
}

@ -13,6 +13,10 @@ namespace Graphics {
get { return new Vector2(ownerControl.Size.Width, ownerControl.Size.Height); }
}
public OpenGL GL {
get { return gl; }
}
public renderCam(OpenGL glContext, Control owner) : base() {
gl = glContext;
ownerControl = owner;

@ -0,0 +1,8 @@
#version 330 core
out vec4 FragColor;
in vec4 vertexColor;
void main() {
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

@ -52,21 +52,30 @@ namespace JuicyGraphics {
return;
}
gridBackground gBg = new gridBackground();
protected override void OnPaint(PaintEventArgs e) {
if (renderingForDesigner()) {
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeOpenGL();
}
GL.MakeCurrent();
GL.ClearColor(0.9f, 0.9f, 0.9f, 1f);
GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
GL.LoadIdentity();
if (rc != null) {
GL.Color(0.8, 0.8, 0.8);
gBg.render(rc);
}
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);

@ -28,10 +28,10 @@
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.canvas1 = new JuicyGraphics.canvas();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.menuStrip1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
@ -87,15 +87,15 @@
this.tabPage1.Text = "Scene Editor";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
// button2
//
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;
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(532, 37);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// button1
//
@ -106,16 +106,7 @@
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(532, 37);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// canvas1
//
@ -128,6 +119,16 @@
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);

@ -6,6 +6,7 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -20,21 +21,13 @@ namespace JuicyGraphics {
}
//private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args) {
// OpenGL GL = ((OpenGLControl)sender).OpenGL;
// //GL.SetDimensions(Width, Height);
// GL.Viewport(0, 0, Width, Height);
// GL.Ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
// GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
// GL.ClearColor(0f, 0.3f, 0.7f, 1f);
// GL.Begin(BeginMode.Triangles);
// GL.Color(1.0, 0.0, 0.0);
// GL.Vertex(1.0, 1.0);
// GL.Vertex(-1.0, -1.0);
// GL.Vertex(-1.0, 1.0);
// GL.End();
// GL.Flush();
//}
private void button1_Click(object sender, EventArgs e) {
string msg = "";
Assembly assembly = Assembly.GetExecutingAssembly();
foreach (string resource in assembly.GetManifestResourceNames()) {
msg += resource + "\n";
}
MessageBox.Show(msg);
}
}
}

@ -59,5 +59,14 @@ namespace JuicyGraphics.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to .
/// </summary>
internal static string gridFrag {
get {
return ResourceManager.GetString("gridFrag", resourceCulture);
}
}
}
}

@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,12 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="gridFrag" xml:space="preserve">
<value />
</data>
</root>

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SharpGL.Shaders
@ -11,13 +13,16 @@ namespace SharpGL.Shaders
/// </summary>
public class Shader
{
public void Create(OpenGL gl, uint shaderType, string source)
public void Create(OpenGL gl, uint shaderType, string resourceFile)
{
// Create the OpenGL shader object.
shaderObject = gl.CreateShader(shaderType);
// Set the shader source.
gl.ShaderSource(shaderObject, source);
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("JuicyGraphics.JuicyGraphics.renderer.shaders.{0}", resourceFile)))) {
gl.ShaderSource(shaderObject, reader.ReadToEnd());
}
// Compile the shader object.
gl.CompileShader(shaderObject);

Loading…
Cancel
Save