Shader läuft irgendwie
This commit is contained in:
parent
f22d60fa20
commit
d17d609671
|
@ -108,6 +108,9 @@
|
||||||
<EmbeddedResource Include="JuicyGraphics\renderer\shaders\background.frag">
|
<EmbeddedResource Include="JuicyGraphics\renderer\shaders\background.frag">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="JuicyGraphics\renderer\shaders\default.vert">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|
|
@ -5,20 +5,42 @@ using SharpGL;
|
||||||
using SharpGL.Enumerations;
|
using SharpGL.Enumerations;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using SharpGL.VertexBuffers;
|
||||||
|
|
||||||
namespace Graphics.Objects {
|
namespace Graphics.Objects {
|
||||||
class gridBackground : iGraphicalObject {
|
class gridBackground : iGraphicalObject {
|
||||||
|
|
||||||
|
VertexBuffer vbo = new VertexBuffer();
|
||||||
|
VertexBufferArray vao = new VertexBufferArray();
|
||||||
|
ShaderProgram gridRender = new ShaderProgram();
|
||||||
|
|
||||||
|
public gridBackground(renderCam context) {
|
||||||
|
vao.Create(context.GL);
|
||||||
|
vao.Bind(context.GL);
|
||||||
|
gridRender.Create(context.GL, Shader.FromFile("default.vert"),
|
||||||
|
Shader.FromFile("background.frag"), new Dictionary<uint, string>()
|
||||||
|
{ { 0, "position" } });
|
||||||
|
vbo.Create(context.GL);
|
||||||
|
vbo.Bind(context.GL);
|
||||||
|
vbo.SetData(context.GL, 0, new float[] { -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f }, false, 2);
|
||||||
|
vao.Unbind(context.GL);
|
||||||
|
}
|
||||||
|
|
||||||
const double realTileSize = 24.0f;
|
const double realTileSize = 24.0f;
|
||||||
public void render(renderCam context) {
|
public void render(renderCam context) {
|
||||||
Shader renderGrid = new Shader();
|
|
||||||
renderGrid.Create(context.GL, OpenGL.GL_FRAGMENT_SHADER, "background.frag");
|
|
||||||
|
|
||||||
context.GL.Begin(BeginMode.Quads);
|
gridRender.Bind(context.GL);
|
||||||
context.GL.Vertex(-1.0, -1.0);
|
|
||||||
context.GL.Vertex(1.0, -1.0);
|
vao.Bind(context.GL);
|
||||||
context.GL.Vertex(1.0, 1.0);
|
context.GL.DrawArrays(OpenGL.GL_QUADS, 0, 8);
|
||||||
context.GL.Vertex(-1.0, 1.0);
|
|
||||||
context.GL.End();
|
vao.Unbind(context.GL);
|
||||||
|
gridRender.Unbind(context.GL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
#version 330 core
|
#version 330
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec4 vertexColor;
|
in vec2 texCoord;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
if (floor(mod(texCoord.x * 48.0, 2)) != floor(mod(texCoord.y * 27.0, 2))) {
|
||||||
}
|
fragColor = vec4(0.9, 0.9, 0.9, 1.0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fragColor = vec4(0.8, 0.8, 0.8, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
in vec2 position;
|
||||||
|
|
||||||
|
out vec2 texCoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
texCoord = position * 0.5 + vec2(0.5, 0.5);
|
||||||
|
gl_Position = vec4(position, 0.0, 1.0);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ using System.Numerics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace JuicyGraphics {
|
namespace JuicyGraphics {
|
||||||
|
|
||||||
class canvas : Control, ISupportInitialize {
|
class canvas : Control, ISupportInitialize {
|
||||||
|
|
||||||
OpenGL GL = new OpenGL();
|
OpenGL GL = new OpenGL();
|
||||||
|
@ -52,7 +53,7 @@ namespace JuicyGraphics {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gridBackground gBg = new gridBackground();
|
gridBackground gBg;
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e) {
|
protected override void OnPaint(PaintEventArgs e) {
|
||||||
if (renderingForDesigner()) {
|
if (renderingForDesigner()) {
|
||||||
|
@ -61,13 +62,15 @@ namespace JuicyGraphics {
|
||||||
InitializeOpenGL();
|
InitializeOpenGL();
|
||||||
}
|
}
|
||||||
GL.MakeCurrent();
|
GL.MakeCurrent();
|
||||||
GL.ClearColor(0.9f, 0.9f, 0.9f, 1f);
|
GL.ClearColor(0.1f, 0.9f, 0.9f, 1f);
|
||||||
GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
|
GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
|
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
GL.Color(0.8, 0.8, 0.8);
|
GL.Color(0.8, 0.8, 0.8);
|
||||||
|
if (gBg == null)
|
||||||
|
gBg = new gridBackground(rc);
|
||||||
gBg.render(rc);
|
gBg.render(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace SharpGL.Shaders
|
namespace SharpGL.Shaders
|
||||||
{
|
{
|
||||||
|
@ -13,15 +14,14 @@ namespace SharpGL.Shaders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Shader
|
public class Shader
|
||||||
{
|
{
|
||||||
public void Create(OpenGL gl, uint shaderType, string resourceFile)
|
public void Create(OpenGL gl, uint shaderType, string source)
|
||||||
{
|
{
|
||||||
// Create the OpenGL shader object.
|
// Create the OpenGL shader object.
|
||||||
shaderObject = gl.CreateShader(shaderType);
|
shaderObject = gl.CreateShader(shaderType);
|
||||||
|
|
||||||
// Set the shader source.
|
// Set the shader source.
|
||||||
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("JuicyGraphics.JuicyGraphics.renderer.shaders.{0}", resourceFile)))) {
|
|
||||||
gl.ShaderSource(shaderObject, reader.ReadToEnd());
|
gl.ShaderSource(shaderObject, source);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Compile the shader object.
|
// Compile the shader object.
|
||||||
|
@ -31,6 +31,8 @@ namespace SharpGL.Shaders
|
||||||
// going to throw an exception.
|
// going to throw an exception.
|
||||||
if (GetCompileStatus(gl) == false)
|
if (GetCompileStatus(gl) == false)
|
||||||
{
|
{
|
||||||
|
MessageBox.Show(GetInfoLog(gl));
|
||||||
|
System.Environment.Exit(1);
|
||||||
throw new ShaderCompilationException(string.Format("Failed to compile shader with ID {0}.", shaderObject), GetInfoLog(gl));
|
throw new ShaderCompilationException(string.Format("Failed to compile shader with ID {0}.", shaderObject), GetInfoLog(gl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +43,12 @@ namespace SharpGL.Shaders
|
||||||
shaderObject = 0;
|
shaderObject = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string FromFile(string resourceFile) {
|
||||||
|
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("JuicyGraphics.JuicyGraphics.renderer.shaders.{0}", resourceFile)))) {
|
||||||
|
return reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool GetCompileStatus(OpenGL gl)
|
public bool GetCompileStatus(OpenGL gl)
|
||||||
{
|
{
|
||||||
int[] parameters = new int[] { 0 };
|
int[] parameters = new int[] { 0 };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user