Basic rendering works

This commit is contained in:
Matt 2020-08-14 18:40:07 -07:00
parent ae0f4c6e19
commit 5d62a86947
6 changed files with 26 additions and 16 deletions

View File

@ -29,7 +29,7 @@ namespace Strawberry
private Dictionary<Type, List<Type>> componentAssignableLists;
public PlatformLayer PlatformLayer { get; private set; }
public Color ClearColor = .Black;
public Color ClearColor = .Red;
private bool* keyboardState;
private int32 updateCounter;

View File

@ -35,9 +35,21 @@ namespace Strawberry
public void Draw()
{
GL.glDisable(GL.GL_CULL_FACE);
GL.glBindVertexArray(vaoID);
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBufferID);
GL.glEnableVertexAttribArray(0);
GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, GL.GL_FALSE, Batcher.VertexSize, (void*)0);
GL.glEnableVertexAttribArray(1);
GL.glVertexAttribPointer(1, 2, GL.GL_FLOAT, GL.GL_FALSE, Batcher.VertexSize, (void*)8);
GL.glEnableVertexAttribArray(2);
GL.glVertexAttribPointer(2, 4, GL.GL_UNSIGNED_BYTE, GL.GL_TRUE, Batcher.VertexSize, (void*)16);
GL.glEnableVertexAttribArray(3);
GL.glVertexAttribPointer(3, 3, GL.GL_UNSIGNED_BYTE, GL.GL_TRUE, Batcher.VertexSize, (void*)20);
GL.glBufferData(GL.GL_ARRAY_BUFFER, vertices.Count * sizeof(Vertex), vertices.Ptr, GL.GL_DYNAMIC_DRAW);
GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.Count * sizeof(uint32), indices.Ptr, GL.GL_DYNAMIC_DRAW);
@ -81,8 +93,8 @@ namespace Strawberry
private struct Vertex
{
public Vector Position;
public Color Color;
public Vector TexCoord;
public Color Color;
public (uint8, uint8, uint8) Mode;
static public Vertex Shape(Vector pos, Color color)

View File

@ -102,15 +102,6 @@ namespace Strawberry
GL.glGetProgramInfoLog(glProgram, 1024, &logLen, &log);
if (logLen > 0)
Calc.Log(&log, logLen);
GL.glEnableVertexAttribArray(0);
GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, GL.GL_FALSE, Batcher.VertexSize, (void*)0);
GL.glEnableVertexAttribArray(1);
GL.glVertexAttribPointer(1, 4, GL.GL_UNSIGNED_BYTE, GL.GL_TRUE, Batcher.VertexSize, (void*)8);
GL.glEnableVertexAttribArray(2);
GL.glVertexAttribPointer(2, 2, GL.GL_FLOAT, GL.GL_FALSE, Batcher.VertexSize, (void*)12);
GL.glEnableVertexAttribArray(3);
GL.glVertexAttribPointer(3, 3, GL.GL_UNSIGNED_BYTE, GL.GL_TRUE, Batcher.VertexSize, (void*)20);
}
//Audio
@ -153,21 +144,25 @@ namespace Strawberry
public override void RenderBegin()
{
GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af);
GL.glClear(GL.GL_COLOR_BUFFER_BIT);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glUseProgram(glProgram);
float zNearPlane = 0;
float zFarPlane = 1000;
float[16] mat =
.(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
.(2.0f / Game.Width, 0, 0, 0,
0, 2.0f / Game.Height, 0, 0,
0, 0, 1.0f / (zNearPlane - zFarPlane), zNearPlane / (zNearPlane - zFarPlane),
0, 0, 0, 1);
let loc = GL.glGetUniformLocation(glProgram, "u_matrix");
GL.glUniformMatrix4fv(loc, 1, GL.GL_FALSE, &mat);
Batcher b = scope Batcher();
b.PushQuad(.(-1, -1), .(1, -1), .(1, 1), .(-1, 1), .Magenta);
b.PushQuad(.(-40, -40), .(40, -40), .(40, 40), .(-40, 40), .Yellow);
b.Draw();
}

View File

@ -2,6 +2,7 @@ using System;
namespace Strawberry
{
[Ordered, Packed, CRepr]
public struct Color
{
static public readonly Color White = 0xFFFFFFFF;

View File

@ -9,6 +9,7 @@ namespace Strawberry
Licensed under the MIT license.
*/
[Ordered, Packed, CRepr]
public struct Matrix
{
static public readonly Matrix Identity = Matrix(1, 0, 0, 1, 0, 0);

View File

@ -2,6 +2,7 @@ using System;
namespace Strawberry
{
[Ordered, Packed, CRepr]
public struct Vector
{
static public readonly Vector Right = .(1, 0);