162 lines
4.4 KiB
C#
162 lines
4.4 KiB
C#
using StgSharp.Geometries;
|
|
using StgSharp.Graphics;
|
|
using StgSharp.Math;
|
|
using StgSharp.Math.Linear;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Numerics;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp
|
|
{
|
|
|
|
internal static class Program
|
|
{
|
|
|
|
internal unsafe static void DebugMain(string[] args)
|
|
{
|
|
|
|
InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
|
|
InternalIO.InternalWriteLog($"{typeof(vec3d).Name}", LogType.Info);
|
|
Graphic.InitGL(4, 6);
|
|
|
|
//GL.glfw->WindowHint(GLFW.GLFW_DECORATED, GLFW.GL_FALSE);
|
|
//Form f = Graphic.CreateWindow(800, 600, "Test STG#!", IntPtr.Zero, null);
|
|
Form f = new Form(800, 600, "Hello,STG#!", IntPtr.Zero, null);
|
|
f.MakeAsCurrentContext();
|
|
f.SetSizeLimit(800, 600, 800, 600);
|
|
GL.SetFrameBufferSizeCallback(f, FormSizeCallback);
|
|
|
|
f.LoadGlapi(GL.LoadGLfunc);
|
|
|
|
Shader shader = new Shader();
|
|
shader.CompileVertexShader(
|
|
File.ReadAllText("Shader\\vertex.vert")
|
|
);
|
|
shader.CompileFragmentShader(
|
|
File.ReadAllText("Shader\\fragment.frag")
|
|
);
|
|
shader.Link();
|
|
|
|
|
|
Triangle tri = new Triangle(
|
|
-0.5f, -0.3f, 0.0f,
|
|
0.5f, -0.5f, 0.0f,
|
|
0.0f, 0.5f, 0.0f
|
|
);
|
|
|
|
Rectangle rec = new Rectangle(
|
|
-0.4f, 0.5f, 0.0f,
|
|
0.5f, 0.5f, 0.0f,
|
|
0.6f, -0.5f, 0.0f,
|
|
-0.7f, -0.5f, 0.0f
|
|
);
|
|
|
|
Polygon5 polygon = new Polygon5(
|
|
-0.4f, 0.5f, 0.0f,
|
|
0.5f, 0.5f, 0.0f,
|
|
0.6f, -0.5f, 0.0f,
|
|
0, -1, 0,
|
|
-0.7f, -0.5f, 0.0f
|
|
);
|
|
|
|
|
|
VertexArray vao = new VertexArray(1);
|
|
VertexBuffer vbo = new VertexBuffer(1);
|
|
ElementBuffer ebo = new ElementBuffer(1);
|
|
|
|
GL.context->BindVertexArray(vao[0]);
|
|
|
|
|
|
|
|
vbo.SetData(0, polygon.VertexBuffer, BufferUsage.STATIC_DRAW);
|
|
ebo.SetData(0, polygon.Indices, BufferUsage.STATIC_DRAW);
|
|
|
|
|
|
|
|
GL.context->VertexAttribPointer(0, 3, GLconst.FLOAT, false, 4 * sizeof(float), (void*)0);
|
|
GL.context->EnableVertexAttribArray(0);
|
|
|
|
|
|
/**/
|
|
GL.context->BindBuffer(GLconst.ARRAY_BUFFER, 0);
|
|
GL.context->BindVertexArray(0);
|
|
/**/
|
|
|
|
|
|
|
|
while (GL.glfw.WindowShouldClose(f.windowID) == 0)
|
|
{
|
|
ProcessInput(f.windowID);
|
|
|
|
GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
GL.context->Clear(GLconst.COLOR_BUFFER_BIT);
|
|
|
|
shader.Use();
|
|
|
|
GL.context->BindVertexArray(vao._bufferID[0]);
|
|
|
|
GL.DrawElements(GepmetryType.TRIANGLES, 9, typeof(uint), IntPtr.Zero);
|
|
|
|
GL.context->BindVertexArray(0);
|
|
|
|
GL.glfw.SwapBuffers(f.windowID);
|
|
GL.glfw.PollEvents();
|
|
GL.glfw.PollEvents();
|
|
}
|
|
|
|
/**/
|
|
vao.Dispose();
|
|
vbo.Dispose();
|
|
ebo.Dispose();
|
|
/**/
|
|
|
|
/*
|
|
Graphic.glDeleteVertexArrays(1, &vao);
|
|
Graphic.glDeleteBuffers(1, &vao);
|
|
Graphic.glDeleteBuffers(1, &vao);
|
|
/**/
|
|
|
|
GL.glfw.Terminate();
|
|
}
|
|
|
|
internal unsafe static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
DebugMain(args);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
InternalIO.InternalWriteLog(
|
|
ex.Message + "\n" + ex.StackTrace,
|
|
LogType.Error);
|
|
}
|
|
}
|
|
|
|
public static unsafe void FormSizeCallback(IntPtr window, int width, int height)
|
|
{
|
|
GL.context->Viewport(0, 0, width, height);
|
|
}
|
|
|
|
public static unsafe void ProcessInput(IntPtr windowPtr)
|
|
{
|
|
if (GL.glfw.GetKey(windowPtr, (int)Control.Key.ESCAPE)
|
|
== KeyStatus.PRESS)
|
|
{
|
|
GL.glfw.SetWindowShouldClose(windowPtr, 1);
|
|
}
|
|
}
|
|
|
|
[DllImport(InternalIO.SSGC_libname, EntryPoint = "printShaderCode",
|
|
CallingConvention = CallingConvention.Cdecl)]
|
|
internal extern unsafe static void PrintShader(byte** shadercode);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|