daily update on 20231016 by nitload youmu, vao,vbo,ebo struct added
This commit is contained in:
+63
-62
@@ -6,7 +6,6 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
@@ -17,61 +16,30 @@ namespace StgSharp
|
||||
|
||||
internal unsafe static void Main(string[] args)
|
||||
{
|
||||
internalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
|
||||
|
||||
Graphic.InitGL(3, 3);
|
||||
Graphic.InitGL(4, 6);
|
||||
|
||||
Form f = Graphic.GLcreateWindow(
|
||||
Form f = Graphic.CreateWindow(
|
||||
800, 600, "Test STG#!", IntPtr.Zero, null
|
||||
);
|
||||
Graphic.GLmakeContexCurrent(f);
|
||||
internalIO.glfwSetFramebufferSizeCallback(f.windowID, FormSizeCallback);
|
||||
Graphic.MakeContexCurrent(f);
|
||||
Graphic.SetFrameBufferSizeCallback(f, FormSizeCallback);
|
||||
|
||||
GetApiRep();
|
||||
Graphic.InitGLAD(Graphic.GetProcAddress);
|
||||
Graphic.InitGLManager(Graphic.GetProcAddress);
|
||||
|
||||
string vertstr = File.ReadAllText("Shader\\vertex.vert", Encoding.ASCII);
|
||||
byte[] vert = Encoding.ASCII.GetBytes(vertstr + '\0');
|
||||
uint vertexShader;
|
||||
fixed (byte* shaderSource = vert)
|
||||
{
|
||||
vertexShader = internalIO.InternalLoadShaderCode(shaderSource, GLFW.GL_VERTEX_SHADER);
|
||||
if (vertexShader == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
Shader shader = new Shader();
|
||||
shader.CompileVertexShader(
|
||||
File.ReadAllText("Shader\\vertex.vert")
|
||||
);
|
||||
shader.CompileFragmentShader(
|
||||
File.ReadAllText("Shader\\fragment.frag")
|
||||
);
|
||||
shader.Link();
|
||||
|
||||
|
||||
|
||||
string fragstr = File.ReadAllText("Shader\\fragment.frag", Encoding.ASCII);
|
||||
byte[] frag = Encoding.ASCII.GetBytes(fragstr + '\0');
|
||||
|
||||
uint fragmentShader;
|
||||
fixed (byte* shaderSource = frag)
|
||||
{
|
||||
fragmentShader = internalIO.InternalLoadShaderCode(shaderSource, GLFW.GL_FRAGMENT_SHADER);
|
||||
if (fragmentShader == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint shaderProgram = Graphic.glCreateProgram();
|
||||
|
||||
Graphic.glAttachShader(shaderProgram, vertexShader);
|
||||
Graphic.glAttachShader(shaderProgram, fragmentShader);
|
||||
|
||||
if (internalIO.InternalLinkShaderProgram(shaderProgram) == 0)
|
||||
{
|
||||
IntPtr log = internalIO.InternalReadLog();
|
||||
Console.WriteLine(Marshal.PtrToStringAnsi(log));
|
||||
}
|
||||
|
||||
Graphic.glDeleteShader(vertexShader);
|
||||
Graphic.glDeleteShader(fragmentShader);
|
||||
|
||||
|
||||
|
||||
Triangle tri = new Triangle(
|
||||
-0.5f, -0.3f, 0.0f,
|
||||
@@ -80,16 +48,30 @@ namespace StgSharp
|
||||
);
|
||||
|
||||
Rectangle rec = new Rectangle(
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
-0.4f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f,
|
||||
0.5f, -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);
|
||||
vao.Bind();
|
||||
|
||||
/*
|
||||
uint VAO;
|
||||
Graphic.glGenVertexArrays(1, &VAO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VAO);
|
||||
Graphic.glBindVertexArray(VAO);
|
||||
/**/
|
||||
|
||||
|
||||
/*
|
||||
// for triangle rendering
|
||||
@@ -109,27 +91,38 @@ namespace StgSharp
|
||||
/**/
|
||||
// for rectangle rendering
|
||||
|
||||
VertexBuffer vbo = new VertexBuffer(1);
|
||||
vbo.Bind();
|
||||
vbo.SetData(polygon.VertexBuffer, BufferReadType.STATIC_DRAW);
|
||||
|
||||
/*
|
||||
uint VBO;
|
||||
Graphic.glGenBuffers(1, &VBO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VBO);
|
||||
Graphic.SetBufferData(BufferType.ARRAY_BUFFER, polygon.VertexBuffer, BufferReadType.STATIC_DRAW);
|
||||
/**/
|
||||
|
||||
|
||||
/*
|
||||
fixed (void* data = &rec.vertexMat)
|
||||
{
|
||||
Graphic.glBufferData(GLFW.GL_ARRAY_BUFFER, 16 * sizeof(float), data, GLFW.GL_STATIC_DRAW);
|
||||
}
|
||||
/**/
|
||||
|
||||
uint[] indices = new uint[6]
|
||||
{
|
||||
0,1,3,
|
||||
1,2,3
|
||||
};
|
||||
|
||||
ElementBuffer ebo = new ElementBuffer(1);
|
||||
ebo.Bind();
|
||||
ebo.SetData(polygon.Indices, BufferReadType.STATIC_DRAW);
|
||||
|
||||
/*
|
||||
uint EBO;
|
||||
Graphic.glGenBuffers(1, &EBO);
|
||||
Graphic.glBindBuffer(GLFW.GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
fixed (void* data = &indices[0])
|
||||
{
|
||||
Graphic.glBufferData(GLFW.GL_ELEMENT_ARRAY_BUFFER, indices.Length * sizeof(uint), data, GLFW.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
Graphic.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, polygon.Indices, BufferReadType.STATIC_DRAW);
|
||||
/**/
|
||||
|
||||
|
||||
Graphic.glVertexAttribPointer(0, 3, GLFW.GL_FLOAT, false, 4 * sizeof(float), (void*)0);
|
||||
Graphic.glEnableVertexAttribArray(0);
|
||||
@@ -144,14 +137,15 @@ namespace StgSharp
|
||||
{
|
||||
ProcessInput(f.windowID);
|
||||
|
||||
Graphic.glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
Graphic.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
Graphic.glClear(GLFW.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
Graphic.glUseProgram(shaderProgram);
|
||||
Graphic.glBindVertexArray(VAO);
|
||||
shader.Use();
|
||||
|
||||
Graphic.glBindVertexArray(vao._bufferID);
|
||||
|
||||
//Graphic.glDrawArrays(GLFW.GL_TRIANGLES, 0, 3);
|
||||
Graphic.glDrawElements(GLFW.GL_TRIANGLES, 6, GLFW.GL_UNSIGNED_INT, (void*)0);
|
||||
Graphic.glDrawElements(GLFW.GL_TRIANGLES, 9, GLFW.GL_UNSIGNED_INT, (void*)0);
|
||||
|
||||
Graphic.glBindVertexArray(0);
|
||||
|
||||
@@ -159,9 +153,16 @@ namespace StgSharp
|
||||
internalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
vao.Dispose();
|
||||
vbo.Dispose();
|
||||
ebo.Dispose();
|
||||
|
||||
/*
|
||||
Graphic.glDeleteVertexArrays(1, &VAO);
|
||||
Graphic.glDeleteBuffers(1, &VBO);
|
||||
Graphic.glDeleteBuffers(1, &EBO);
|
||||
/**/
|
||||
|
||||
internalIO.glfwTerminate();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user