Created
January 30, 2020 23:43
-
-
Save 8Observer8/fd1a1ff640e716cd1a911328f1c090f4 to your computer and use it in GitHub Desktop.
Sign of Mitsubishi. C#, .NET 2.0, OpenGL 3.0, OpenTK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using OpenTK.Graphics.OpenGL; | |
using OpenTK.Graphics; | |
using OpenTK; | |
namespace MitsubishiSign | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (var window = new Window()) | |
{ | |
window.Title = "Mitsubishi"; | |
window.Run(60); | |
} | |
} | |
} | |
class Window : GameWindow | |
{ | |
private Matrix4 _projMatrix; | |
private Matrix4 _modelMatrix; | |
private Matrix4 _mpMatrix; | |
private int _uMPMatrixLocation; | |
public Window() : base(250, 250, new GraphicsMode(32, 0, 0, 8)) { } | |
protected override void OnLoad(EventArgs e) | |
{ | |
base.OnLoad(e); | |
var vShaderSource = | |
@" | |
#version 130 | |
in vec3 aPosition; | |
uniform mat4 uMPMatrix; | |
void main() | |
{ | |
gl_Position = uMPMatrix * vec4(aPosition, 1.0); | |
} | |
"; | |
var fShaderSource = | |
@" | |
#version 130 | |
precision mediump float; | |
out vec4 fragColor; | |
void main() | |
{ | |
fragColor = vec4(0.0); | |
} | |
"; | |
var vShader = GL.CreateShader(ShaderType.VertexShader); | |
GL.ShaderSource(vShader, vShaderSource); | |
GL.CompileShader(vShader); | |
var fShader = GL.CreateShader(ShaderType.FragmentShader); | |
GL.ShaderSource(fShader, fShaderSource); | |
GL.CompileShader(fShader); | |
var program = GL.CreateProgram(); | |
GL.AttachShader(program, vShader); | |
GL.AttachShader(program, fShader); | |
GL.LinkProgram(program); | |
GL.UseProgram(program); | |
int vbo; | |
GL.CreateBuffers(1, out vbo); | |
float[] positions = new float[] | |
{ | |
0f, -0.866f, -1f, | |
0.5f, 0f, -1f, | |
0f, 0.866f, -1f, | |
-0.5f, 0f, -1f | |
}; | |
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); | |
GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * positions.Length, positions, BufferUsageHint.StaticDraw); | |
var aPositionLocation = GL.GetAttribLocation(program, "aPosition"); | |
GL.VertexAttribPointer(aPositionLocation, 3, VertexAttribPointerType.Float, false, 0, 0); | |
GL.EnableVertexAttribArray(aPositionLocation); | |
_uMPMatrixLocation = GL.GetUniformLocation(program, "uMPMatrix"); | |
GL.ClearColor(1f, 1f, 1f, 1f); | |
} | |
protected override void OnRenderFrame(FrameEventArgs e) | |
{ | |
base.OnRenderFrame(e); | |
GL.Clear(ClearBufferMask.ColorBufferBit); | |
_modelMatrix = | |
Matrix4.CreateScale(5f, 5f, 1f) * | |
Matrix4.CreateTranslation(0f, 0.866f * 5f, 0f); | |
_mpMatrix = _modelMatrix * _projMatrix; | |
GL.UniformMatrix4(_uMPMatrixLocation, false, ref _mpMatrix); | |
GL.DrawArrays(PrimitiveType.TriangleFan, 0, 4); | |
_modelMatrix = | |
Matrix4.CreateScale(5f, 5f, 1f) * | |
Matrix4.CreateTranslation(0f, 0.866f * 5f, 0f) * | |
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(120f)); | |
_mpMatrix = _modelMatrix * _projMatrix; | |
GL.UniformMatrix4(_uMPMatrixLocation, false, ref _mpMatrix); | |
GL.DrawArrays(PrimitiveType.TriangleFan, 0, 4); | |
_modelMatrix = | |
Matrix4.CreateScale(5f, 5f, 1f) * | |
Matrix4.CreateTranslation(0f, 0.866f * 5f, 0f) * | |
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(240f)); | |
_mpMatrix = _modelMatrix * _projMatrix; | |
GL.UniformMatrix4(_uMPMatrixLocation, false, ref _mpMatrix); | |
GL.DrawArrays(PrimitiveType.TriangleFan, 0, 4); | |
SwapBuffers(); | |
} | |
protected override void OnResize(EventArgs e) | |
{ | |
base.OnResize(e); | |
GL.Viewport(0, 0, Width, Height); | |
float aspect = (float) Width / Height; | |
float worldWidth = aspect * 20f; | |
_projMatrix = Matrix4.CreateOrthographic(worldWidth, 20f, 100f, -100f); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment