Update li2d

main
Li 9 months ago
parent 71e2042967
commit bcef33db10

@ -1,5 +1,11 @@
// Li2D - Created by Li
// li2d.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
@ -8,68 +14,64 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "default_frg.h"
#include "default_vrt.h"
#include "errorhandling.h"
#include "math.h"
#include "color.h"
#define TRUE 1
#define FALSE 0
#include "default_frag.h"
#include "default_vert.h"
static GLFWwindow* mainWindow;
#include "bool.h"
const float triangleVertex[6] = {
-0.5f, -0.5f,
0.0f, 0.5f,
0.5f, -0.5f
};
static unsigned int triangleBuffer = 0;
static int windowWidth = 0;
static int windowHeight = 0;
#include "shader.h"
#include "vertexbuffer.h"
#include "indexbuffer.h"
static GLFWwindow* mainWindow;
static int compileShader(const char* shaderSourceCode, unsigned int type) {
unsigned int shaderId = glCreateShader(type);
glShaderSource(shaderId, 1, &shaderSourceCode, NULL);
glCompileShader(shaderId);
const float triangleVertex[3*2] = {
-0.5f, -0.5f, // 0
-0.5f, 0.5f, // 1
0.5f, -0.5f, // 2
};
int res;
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &res);
if (res == GL_FALSE) {
int len;
glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len);
char* log = malloc(len * sizeof(char));
glGetShaderInfoLog(shaderId, len, &len, log);
const float squareVertex[4*2] = {
-0.5f, -0.5f, //0
0.5f, -0.5f, //1
0.5f, 0.5f, //2
-0.5f, 0.5f, //3
};
printf("== %s SHADER COMPILATION FAILED ==\n%s\n", (type == GL_VERTEX_SHADER ? "VERTEX" : "FRAGMENT"), log);
const unsigned char squareIndicies[6] = {
0, 1, 2,
2, 3, 0
};
free(log);
static unsigned int triangleVertexBuffer = 0;
static unsigned int triangleVao = 0;
glDeleteShader(shaderId);
return 0;
}
static unsigned int squareVertexBuffer = 0;
static unsigned int squareIndexBuffer = 0;
static unsigned int squareVao = 0;
return shaderId;
}
static unsigned int createProgram(const char* vertexShaderCode, const char* fragmentShaderCode) {
unsigned int program = glCreateProgram();
unsigned int vertexShader = compileShader(vertexShaderCode, GL_VERTEX_SHADER);
unsigned int fragmentShader = compileShader(fragmentShaderCode, GL_FRAGMENT_SHADER);
static int windowWidth = 0;
static int windowHeight = 0;
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
static int defaultProgram = 0;
static int colorUniformLocation = 0;
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
unsigned int li2dCreateHexColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
RGBA col;
col.R = red;
col.G = green;
col.B = blue;
col.A = alpha;
return program;
uint32_t hexcolor = *(uint32_t*)&col;
return _byteswap_ulong(hexcolor);
}
int li2dInit(int width, int height, char* windowTitle) {
if (!glfwInit())
return FALSE;
@ -77,12 +79,18 @@ int li2dInit(int width, int height, char* windowTitle) {
windowHeight = height;
windowWidth = width;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
mainWindow = glfwCreateWindow(width, height, windowTitle, NULL, NULL);
if (!mainWindow)
{
glfwTerminate();
return FALSE;
}
glfwSwapInterval(1);
glfwMakeContextCurrent(mainWindow);
@ -91,30 +99,61 @@ int li2dInit(int width, int height, char* windowTitle) {
return FALSE;
}
printf("Li2D!\n");
printf("Li2D! - Created by Li.\n");
printf("Trans rights are Human Rights\n");
printf("Using OpenGL Version: %s\n", glGetString(GL_VERSION));
// Initalize vertex buffers
// Triangle
triangleVertexBuffer = createVertexBuffer(triangleVertex, sizeof(triangleVertex));
GLCall(glGenVertexArrays(1, &triangleVao));
GLCall(glBindVertexArray(triangleVao));
GLCall(glEnableVertexAttribArray(0));
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
// Square
squareVertexBuffer = createVertexBuffer(squareVertex, sizeof(squareVertex));
squareIndexBuffer = createIndexBuffer(squareIndicies, sizeof(squareIndicies));
GLCall(glGenVertexArrays(1, &squareVao));
GLCall(glBindVertexArray(squareVao));
GLCall(glEnableVertexAttribArray(0));
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
glGenBuffers(1, &triangleBuffer);
glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
glBufferData(GL_ARRAY_BUFFER, sizeof(triangleVertex), triangleVertex, GL_STATIC_DRAW);
// Compile shaders
unsigned int prg = createProgram(default_vrt, default_frg);
glUseProgram(prg);
unsigned int defaultProgram = createProgram(default_vert, default_frag);
GLCall(glUseProgram(defaultProgram));
colorUniformLocation = glGetUniformLocation(defaultProgram, "u_Color");
ASSERT(colorUniformLocation != -1);
return TRUE;
}
int li2dDrawSquare(int x, int y, int x2, int y2, int color) {
RGBA_normalized col = normalizeHexColor(color);
bindVertexBuffer(squareVertexBuffer);
bindIndexBuffer(squareIndexBuffer);
GLCall(glBindVertexArray(squareVao));
GLCall(glUniform4f(colorUniformLocation, col.R, col.G, col.B, col.A));
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, NULL));
return TRUE;
}
int li2dDrawTriangle(int x, int y, size_t sz) {
glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer);
glDrawArrays(GL_TRIANGLES, 0, 3);
int li2dDrawTriangle(int x, int y, int x2, int y2, int color) {
RGBA_normalized col = normalizeHexColor(color);
bindVertexBuffer(triangleVertexBuffer);
GLCall(glBindVertexArray(triangleVao));
GLCall(glUniform4f(colorUniformLocation, col.R, col.G, col.B, col.A));
GLCall(glDrawArrays(GL_TRIANGLES, 0, 3));
return TRUE;
}
@ -131,29 +170,29 @@ int li2dSwapBuffers() {
return TRUE;
}
int li2dClearScreen(int r, int g, int b) {
GLclampf red = ((float)r / 255);
GLclampf green = ((float)g / 255);
GLclampf blue = ((float)b / 255);
glClearColor(red, green, blue, 1);
glClear(GL_COLOR_BUFFER_BIT);
int li2dClearScreen(int color) {
RGBA_normalized col = normalizeHexColor(color);
GLCall(glClearColor(col.R, col.G, col.B, col.A));
GLCall(glClear(GL_COLOR_BUFFER_BIT));
return TRUE;
}
int li2dTerm() {
glfwTerminate();
glDeleteProgram(defaultProgram);
glfwTerminate();
return TRUE;
}
int main(void)
{
li2dInit(840, 650, "Li2D!");
do {
li2dClearScreen(0, 0, 0);
li2dDrawTriangle(0, 0, 10);
li2dClearScreen(li2dCreateHexColor(rand() % 0xFF, rand() % 0xFF, rand() % 0xFF, 0xFF));
li2dDrawSquare(0, 0, 10, 10, li2dCreateHexColor(rand() % 0xFF, rand() % 0xFF, rand() % 0xFF, 0xFF));
li2dSwapBuffers();
} while (!li2dWasClosePressed());

@ -99,8 +99,8 @@
<AdditionalDependencies>glew32s.lib;glfw3_mt.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frg" default_frg "$(ProjectDir)default_frg.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vrt" default_vrt "$(ProjectDir)default_vrt.h"</Command>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frag" default_frag "$(ProjectDir)default_frag.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vert" default_vert "$(ProjectDir)default_vert.h"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -123,8 +123,8 @@
<AdditionalDependencies>glew32s.lib;glfw3_mt.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frg" default_frg "$(ProjectDir)default_frg.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vrt" default_vrt "$(ProjectDir)default_vrt.h"</Command>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frag" default_frag "$(ProjectDir)default_frag.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vert" default_vert "$(ProjectDir)default_vert.h"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -150,8 +150,8 @@
<TreatOutputAsContent>false</TreatOutputAsContent>
</CustomBuildStep>
<PreBuildEvent>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frg" default_frg "$(ProjectDir)default_frg.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vrt" default_vrt "$(ProjectDir)default_vrt.h"</Command>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frag" default_frag "$(ProjectDir)default_frag.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vert" default_vert "$(ProjectDir)default_vert.h"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>
@ -186,8 +186,8 @@
<TreatOutputAsContent>false</TreatOutputAsContent>
</CustomBuildStep>
<PreBuildEvent>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frg" default_frg "$(ProjectDir)default_frg.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vrt" default_vrt "$(ProjectDir)default_vrt.h"</Command>
<Command>"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.frag" default_frag "$(ProjectDir)default_frag.h"
"$(SolutionDir)..\tools\compileHeaders.exe" "$(ProjectDir)shaders\default.vert" default_vert "$(ProjectDir)default_vert.h"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>
@ -195,15 +195,26 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="color.c" />
<ClCompile Include="errorhandling.c" />
<ClCompile Include="indexbuffer.c" />
<ClCompile Include="Li2D.c" />
<ClCompile Include="math.c" />
<ClCompile Include="shader.c" />
<ClCompile Include="vertexbuffer.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="default_frg.h" />
<ClInclude Include="default_vrt.h" />
<None Include="bool.h" />
<None Include="shaders\default.frag" />
<None Include="shaders\default.vert" />
</ItemGroup>
<ItemGroup>
<None Include="shaders\default.frg" />
<None Include="shaders\default.vrt" />
<ClInclude Include="color.h" />
<ClInclude Include="errorhandling.h" />
<ClInclude Include="indexbuffer.h" />
<ClInclude Include="math.h" />
<ClInclude Include="shader.h" />
<ClInclude Include="vertexbuffer.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

@ -18,17 +18,48 @@
<ClCompile Include="Li2D.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="errorhandling.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="color.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="math.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="shader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="vertexbuffer.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="indexbuffer.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="default_frg.h">
<None Include="shaders\default.frag" />
<None Include="shaders\default.vert" />
<None Include="bool.h" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="errorhandling.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="default_vrt.h">
<ClInclude Include="color.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="math.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="vertexbuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="indexbuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="shaders\default.frg" />
<None Include="shaders\default.vrt" />
</ItemGroup>
</Project>

@ -0,0 +1,10 @@
// bool.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#define TRUE 1
#define FALSE 0

@ -0,0 +1,27 @@
// color.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include "color.h"
#include "math.h"
#include <stdint.h>
RGBA readHexColor(unsigned int color) {
RGBA col;
*(uint32_t*)&col = _byteswap_ulong(color);
return col;
}
RGBA_normalized normalizeHexColor(unsigned int color) {
RGBA col = readHexColor(color);
RGBA_normalized ncol;
ncol.R = normalize(col.R, 0xFF);
ncol.G = normalize(col.G, 0xFF);
ncol.B = normalize(col.B, 0xFF);
ncol.A = normalize(col.A, 0xFF);
return ncol;
}

@ -0,0 +1,26 @@
// color.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <stdint.h>
#include <stdlib.h>
typedef struct RGBA {
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t A;
} RGBA;
typedef struct RGBA_normalized {
float R;
float G;
float B;
float A;
} RGBA_normalized;
RGBA readHexColor(unsigned int color);
RGBA_normalized normalizeHexColor(unsigned int color);

@ -0,0 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
const uint8_t default_frag[0x79] = {
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x33, 0x33, 0x30, 0x20, 0x63, 0x6F, 0x72, 0x65, 0x0D, 0x0A, 0x0D, 0x0A, 0x6C, 0x61, 0x79, 0x6F, 0x75, 0x74, 0x28, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x3D, 0x20, 0x30, 0x29, 0x20, 0x6F, 0x75, 0x74, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x75, 0x6E, 0x69, 0x66, 0x6F, 0x72, 0x6D, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5F, 0x43, 0x6F, 0x6C, 0x6F, 0x72, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x6D, 0x61, 0x69, 0x6E, 0x28, 0x29, 0x7B, 0x0D, 0x0A, 0x09, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0x20, 0x3D, 0x20, 0x75, 0x5F, 0x43, 0x6F, 0x6C, 0x6F, 0x72, 0x3B, 0x0D, 0x0A, 0x7D, 0x00
};
const uint64_t default_frag_len = 0x78;

@ -1,6 +0,0 @@
#include <stdint.h>
#include <stdlib.h>
const uint8_t default_frg[0x71] = {
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x33, 0x33, 0x30, 0x20, 0x63, 0x6F, 0x72, 0x65, 0x0D, 0x0A, 0x0D, 0x0A, 0x6C, 0x61, 0x79, 0x6F, 0x75, 0x74, 0x28, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x3D, 0x20, 0x30, 0x29, 0x20, 0x6F, 0x75, 0x74, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x6D, 0x61, 0x69, 0x6E, 0x28, 0x29, 0x7B, 0x0D, 0x0A, 0x09, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0x20, 0x3D, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28, 0x31, 0x2E, 0x30, 0x2C, 0x20, 0x30, 0x2E, 0x30, 0x2C, 0x20, 0x30, 0x2E, 0x30, 0x2C, 0x20, 0x31, 0x2E, 0x30, 0x29, 0x3B, 0x0D, 0x0A, 0x7D, 0x00
};
const uint64_t default_frg_len = 0x70;

@ -1,6 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
const uint8_t default_vrt[0x6a] = {
const uint8_t default_vert[0x6a] = {
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x33, 0x33, 0x30, 0x20, 0x63, 0x6F, 0x72, 0x65, 0x0D, 0x0A, 0x0D, 0x0A, 0x6C, 0x61, 0x79, 0x6F, 0x75, 0x74, 0x28, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x3D, 0x20, 0x30, 0x29, 0x20, 0x69, 0x6E, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x6D, 0x61, 0x69, 0x6E, 0x28, 0x29, 0x7B, 0x0D, 0x0A, 0x09, 0x67, 0x6C, 0x5F, 0x50, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x3D, 0x20, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x3B, 0x20, 0x0D, 0x0A, 0x7D, 0x00
};
const uint64_t default_vrt_len = 0x69;
const uint64_t default_vert_len = 0x69;

@ -0,0 +1,25 @@
// errorhandling.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <GL/glew.h>
#include "errorhandling.h"
void ClearError() {
while (glGetError() != GL_NO_ERROR);
}
int LogError(char* function, char* file, int line) {
GLenum err = glGetError();
if (err != GL_NO_ERROR) {
printf("[OpenGL Error] 0x%x; in function %s on %s:%i\n", err, function, file, line);
return 1;
}
else {
return 0;
}
}

@ -0,0 +1,20 @@
// errorhandling.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#define ASSERT(x) if (!(x)) __debugbreak();
#ifdef _DEBUG
#define GLCall(x) \
ClearError(); \
x; \
ASSERT(LogError(#x, __FILE__, __LINE__) == 0);
#else
#define GLCall(x) x;
#endif
void ClearError();
int LogError(char* function, char* file, int line);

@ -0,0 +1,30 @@
// indexbuffer.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <stdint.h>
#include <GL/glew.h>
#include "bool.h"
#include "errorhandling.h"
int createIndexBuffer(void* indexBuffer, size_t indexBufferSz) {
int indexBufferId = 0;
GLCall(glGenBuffers(1, &indexBufferId));
bindIndexBuffer(indexBufferId);
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSz, indexBuffer, GL_STATIC_DRAW));
return indexBufferId;
}
int deleteIndexBuffer(int indexBufferId) {
GLCall(glDeleteBuffers(1, &indexBufferId));
return TRUE;
}
int bindIndexBuffer(int indexBuffer) {
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer));
return TRUE;
}

@ -0,0 +1,11 @@
// indexbuffer.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
int createIndexBuffer(void* indexBuffer, size_t indexBufferSz);
int deleteIndexBuffer(int indexBufferId);
int bindIndexBuffer(int indexBuffer);

@ -0,0 +1,12 @@
// math.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
float normalize(int value, int max) {
return ((float)value / max);
}

@ -0,0 +1,9 @@
// math.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
float normalize(int value, int max);

@ -0,0 +1,56 @@
// shader.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <GL/glew.h>
#include "errorhandling.h"
#include <stdlib.h>
static unsigned int compileShader(const char* shaderSourceCode, unsigned int type) {
GLCall(unsigned int shaderId = glCreateShader(type));
GLCall(glShaderSource(shaderId, 1, &shaderSourceCode, NULL));
GLCall(glCompileShader(shaderId));
int shaderCompileStatus;
GLCall(glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderCompileStatus));
if (shaderCompileStatus == GL_FALSE) {
int len;
GLCall(glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len));
char* log = malloc(len * sizeof(char));
GLCall(glGetShaderInfoLog(shaderId, len, &len, log));
printf("== %s SHADER COMPILATION FAILED ==\n%s\n", (type == GL_VERTEX_SHADER ? "VERTEX" : "FRAGMENT"), log);
free(log);
glDeleteShader(shaderId);
ASSERT(shaderCompileStatus == GL_FALSE);
return 0;
}
return shaderId;
}
unsigned int createProgram(const char* vertexShaderCode, const char* fragmentShaderCode) {
unsigned int program = glCreateProgram();
unsigned int vertexShader = compileShader(vertexShaderCode, GL_VERTEX_SHADER);
unsigned int fragmentShader = compileShader(fragmentShaderCode, GL_FRAGMENT_SHADER);
GLCall(glAttachShader(program, vertexShader));
GLCall(glAttachShader(program, fragmentShader));
GLCall(glLinkProgram(program));
GLCall(glValidateProgram(program));
GLCall(glDeleteShader(vertexShader));
GLCall(glDeleteShader(fragmentShader));
return program;
}

@ -0,0 +1,9 @@
// shader.h
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
unsigned int createProgram(const char* vertexShaderCode, const char* fragmentShaderCode);

@ -2,6 +2,8 @@
layout(location = 0) out vec4 color;
uniform vec4 u_Color;
void main(){
color = vec4(1.0, 0.0, 0.0, 1.0);
color = u_Color;
}

@ -0,0 +1,29 @@
// vertexbuffer.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
#include <stdint.h>
#include <GL/glew.h>
#include "bool.h"
#include "errorhandling.h"
int createVertexBuffer(void* vertexBuffer, size_t vertexBufferSz) {
int vertexBufferId = 0;
GLCall(glGenBuffers(1, &vertexBufferId));
bindVertexBuffer(vertexBufferId);
GLCall(glBufferData(GL_ARRAY_BUFFER, vertexBufferSz, vertexBuffer, GL_STATIC_DRAW));
return vertexBufferId;
}
int deleteVertexBuffer(int vertexBufferId) {
GLCall(glDeleteBuffers(1, &vertexBufferId));
return TRUE;
}
int bindVertexBuffer(int vertexBufferId) {
GLCall(glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId));
return TRUE;
}

@ -0,0 +1,12 @@
// vertexbuffer.c
//
// Li2D - Vita2d-like graphics API!
//
// Created by Li
//
// Trans rights are human rights
int createVertexBuffer(void* vertexBuffer, size_t vertexBufferSz);
int deleteVertexBuffer(int vertexBufferId);
int bindVertexBuffer(int vertexBuffer);

@ -0,0 +1,13 @@
c:\users\user\documents\git\li2d\tools\vc143.pdb
c:\users\user\documents\git\li2d\tools\compileheaders.obj
c:\users\user\documents\git\li2d\tools\compileheaders.ipdb
c:\users\user\documents\git\li2d\tools\compileheaders.iobj
c:\users\user\documents\git\li2d\tools\compileheaders.exe
c:\users\user\documents\git\li2d\li2d\..\tools\compileheaders.vcxproj.filelistabsolute.txt
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\cl.command.1.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\cl.read.1.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\cl.write.1.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\compileheaders.write.1u.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\link.command.1.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\link.read.1.tlog
c:\users\user\documents\git\li2d\tools\compileheaders.tlog\link.write.1.tlog

Binary file not shown.

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\User\Documents\git\Li2D\tools\compileHeaders.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,3 @@
C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(520,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
compileHeaders.c
compileHeaders.vcxproj -> C:\Users\User\Documents\git\Li2D\tools\compileHeaders.exe

Binary file not shown.

Binary file not shown.

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.33.31517:TargetPlatformVersion=10.0.22000.0:VcpkgTriplet=x64-windows:
Debug|x64|C:\Users\User\Documents\git\Li2D\Li2D\|

@ -0,0 +1 @@
C:\Users\User\Documents\git\Li2D\tools\compileHeaders.exe

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save