Skip to content

Commit

Permalink
updated Makefile + minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Dec 29, 2023
1 parent 351aee9 commit ad38750
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 65 deletions.
43 changes: 25 additions & 18 deletions RFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@ size_t RFont_draw_text_len(RFont_font* font, const char* text, size_t len, float

#ifdef RFONT_DEBUG

#ifndef GL_DEBUG_TYPE_ERROR
#define GL_DEBUG_TYPE_ERROR 0x824C
#define GL_DEBUG_OUTPUT 0x92E0
#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_INFO_LOG_LENGTH 0x8B84
#endif

void RFont_debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
if (type != GL_DEBUG_TYPE_ERROR)
return;
Expand All @@ -793,26 +802,27 @@ void RFont_debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
void RFont_opengl_getError() {
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR) {
switch (err) {
switch (err) {
case GL_INVALID_ENUM:
printf("OpenGL error: GL_INVALID_ENUM\n");
break;
printf("OpenGL error: GL_INVALID_ENUM\n");
break;
case GL_INVALID_VALUE:
printf("OpenGL error: GL_INVALID_VALUE\n");
break;
printf("OpenGL error: GL_INVALID_VALUE\n");
break;
case GL_INVALID_OPERATION:
printf("OpenGL error: GL_INVALID_OPERATION\n");
break;
printf("OpenGL error: GL_INVALID_OPERATION\n");
break;
case GL_STACK_OVERFLOW:
printf("OpenGL error: GL_STACK_OVERFLOW\n");
break;
printf("OpenGL error: GL_STACK_OVERFLOW\n");
break;
case GL_STACK_UNDERFLOW:
printf("OpenGL error: GL_STACK_UNDERFLOW\n");
break;
printf("OpenGL error: GL_STACK_UNDERFLOW\n");
break;
default:
printf("OpenGL error: Unknown error code 0x%x\n", err);
break;
}
printf("OpenGL error: Unknown error code 0x%x\n", err);
break;
}
exit(1);
}
}

Expand Down Expand Up @@ -1006,7 +1016,6 @@ void RFont_debug_shader(u32 src, const char* shader, const char* action) {
}

RFont_opengl_getError();
exit(1);
}
}
#endif
Expand Down Expand Up @@ -1056,16 +1065,14 @@ void RFont_render_init() {
FragColor = texture(texture0, fragTexCoord) * fragColor;
}
);

glGenVertexArrays(1, &RFont_gl.vao);

glBindVertexArray(RFont_gl.vao);

glGenBuffers(1, &RFont_gl.vbo);
glGenBuffers(1, &RFont_gl.tbo);
glGenBuffers(1, &RFont_gl.cbo);
glGenBuffers(1, &RFont_gl.ebo);

/* compile vertex shader */
RFont_gl.vShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(RFont_gl.vShader, 1, &defaultVShaderCode, NULL);
Expand Down
45 changes: 29 additions & 16 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
ifeq '$(findstring ;,$(PATH))' ';'
CC = gcc

OPENGL = -L"/home/manjaro/Games/Heroic/Prefixes/default/Sonic Mania/pfx/drive_c/windows/syswow64/"

LIBS := -lshell32 -lgdi32 -lm -lopengl32 --static
EXT = .exe

ifneq (,$(filter $(CC),winegcc x86_64-w64-mingw32-gcc))
detected_OS := Windows
else
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS))
detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS))
detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS))
ifeq '$(findstring ;,$(PATH))' ';'
detected_OS := Windows
else
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS))
detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS))
detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS))
endif
endif

ifeq ($(detected_OS),Windows)
LIBS := -lopengl32 -lshell32 -lgdi32 -lm
LIBS := -lshell32 -lgdi32 -lm -lopengl32 --static
endif
ifeq ($(detected_OS),Darwin) # Mac OS X
LIBS := -I./ext/Silicon/ -lm -framework Foundation -framework AppKit -framework OpenGL -framework CoreVideo -w
EXT =
endif
ifeq ($(detected_OS),Linux)
LIBS := -I./include -lX11 -lGLX -lm -lGL
EXT =
endif

all:
Expand All @@ -23,22 +36,22 @@ all:
make rgl

gl:
gcc main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_LEGACY -Wall -o gl
$(CC) main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_LEGACY -Wall -o gl
rgl:
gcc main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_RGL -Wall -o rgl
$(CC) main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_RGL -Wall -o rgl
gl3:
gcc main.c $(LIBS) -I./ext -I../ -Wall -o gl3
$(CC) main.c $(LIBS) -I./ext -I../ -Wall -o gl3

clean:
rm gl3 gl rgl -f
rm gl3$(EXT) gl$(EXT) rgl$(EXT) gl3.exe.so gl.exe.so rgl.exe.so -f

debug:
make clean

gcc main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_LEGACY -Wall -o gl -D RFONT_DEBUG
gcc main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_RGL -Wall -o rgl -D RFONT_DEBUG
gcc main.c $(LIBS) -I./ext -I../ -Wall -o gl3 -D RFONT_DEBUG
$(CC) main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_LEGACY -Wall -o gl -D RFONT_DEBUG
$(CC) main.c $(LIBS) -I./ext -I../ -D RFONT_RENDER_RGL -Wall -o rgl -D RFONT_DEBUG
$(CC) main.c $(LIBS) -I./ext -I../ -Wall -o gl3 -D RFONT_DEBUG

./gl gl
./gl3 gl3
./rgl rgl
./gl$(EXT) gl
./gl3$(EXT) gl3
./rgl$(EXT) rgl
85 changes: 58 additions & 27 deletions example/ext/RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ void RGFW_initVulkan(RGFW_window* win, void* inst) {
#include <windowsx.h>
#include <shellapi.h>

#ifdef RGFW_GL
void* RGFW_getProcAddress(const char* procname) { return (void*)wglGetProcAddress(procname); }
#endif
#endif
#if defined(__APPLE__) && !defined(RGFW_MACOS_X11)
u8 RGFW_keyMap[128] = { 0 };
Expand Down Expand Up @@ -989,8 +986,8 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
}

if (RGFW_CENTER & args) {
x = (screenR[0] - w) / 1.1;
y = (screenR[1] - h) / 4;
x = (screenR[0] - w) / 2;
y = (screenR[1] - h) / 2;
}

/* set and init the new window's data */
Expand Down Expand Up @@ -1215,8 +1212,8 @@ u32* RGFW_window_screenSize(RGFW_window* win) {

Screen* scrn = DefaultScreenOfDisplay((Display*)win->display);

RGFWScreen[0] = scrn->height;
RGFWScreen[1] = scrn->width;
RGFWScreen[0] = scrn->width;
RGFWScreen[1] = scrn->height;

return RGFWScreen;
}
Expand Down Expand Up @@ -2215,22 +2212,52 @@ wglChoosePixelFormatARB_type *wglChoosePixelFormatARB;
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_CONTEXT_FLAGS_ARB 0x2094
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002

#ifdef RGFW_WGL_LOAD
static HMODULE wglinstance = NULL;
typedef HGLRC(WINAPI *PFN_wglCreateContext)(HDC);
typedef BOOL(WINAPI *PFN_wglDeleteContext)(HGLRC);
typedef PROC(WINAPI *PFN_wglGetProcAddress)(LPCSTR);
typedef BOOL(WINAPI *PFN_wglMakeCurrent)(HDC, HGLRC);
typedef HDC (WINAPI *PFN_wglGetCurrentDC)();
typedef HGLRC (WINAPI *PFN_wglGetCurrentContext)();

PFN_wglCreateContext wglCreateContextSRC;
PFN_wglDeleteContext wglDeleteContextSRC;
PFN_wglGetProcAddress wglGetProcAddressSRC;
PFN_wglMakeCurrent wglMakeCurrentSRC;
PFN_wglGetCurrentDC wglGetCurrentDCSRC;
PFN_wglGetCurrentContext wglGetCurrentContextSRC;

#define wglCreateContext wglCreateContextSRC
#define wglDeleteContext wglDeleteContextSRC
#define wglGetProcAddress wglGetProcAddressSRC
#define wglMakeCurrent wglMakeCurrentSRC

#define wglGetCurrentDC wglGetCurrentDCSRC
#define wglGetCurrentContext wglGetCurrentContextSRC
#endif

#ifdef RGFW_GL
void* RGFW_getProcAddress(const char* procname) { return (void*)wglGetProcAddress(procname); }
#endif

RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64 args) {
#ifdef RGFW_WGL_LOAD
if (wglinstance == NULL) {
wglinstance = LoadLibraryA("opengl32.dll");

wglCreateContext = (PFN_wglCreateContext) GetProcAddress(wglinstance, "wglCreateContext");
wglDeleteContext = (PFN_wglDeleteContext) GetProcAddress(wglinstance, "wglDeleteContext");
wglGetProcAddress = (PFN_wglGetProcAddress) GetProcAddress(wglinstance, "wglGetProcAddress");
wglMakeCurrent = (PFN_wglMakeCurrent) GetProcAddress(wglinstance, "wglMakeCurrent");
wglCreateContextSRC = (PFN_wglCreateContext) GetProcAddress(wglinstance, "wglCreateContext");
wglDeleteContextSRC = (PFN_wglDeleteContext) GetProcAddress(wglinstance, "wglDeleteContext");
wglGetProcAddressSRC = (PFN_wglGetProcAddress) GetProcAddress(wglinstance, "wglGetProcAddress");
wglMakeCurrentSRC = (PFN_wglMakeCurrent) GetProcAddress(wglinstance, "wglMakeCurrent");
wglGetCurrentDCSRC = (PFN_wglGetCurrentDC) GetProcAddress(wglinstance, "wglGetCurrentDC");
wglGetCurrentContextSRC = (PFN_wglGetCurrentContext) GetProcAddress(wglinstance, "wglGetCurrentContext");
}
#endif

Expand All @@ -2256,8 +2283,8 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
}

if (RGFW_CENTER & args) {
x = (r[0] - w) / 1.1;
y = (r[1] - h) / 4;
x = (r[0] - w) / 2;
y = (r[1] - h) / 2;
}

#ifndef RGFW_RECT
Expand Down Expand Up @@ -2285,16 +2312,16 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
RegisterClassA(&Class);

DWORD window_style = 0;
window_style = WS_MAXIMIZEBOX | WS_MINIMIZEBOX | window_style;

if (!(RGFW_NO_BORDER & args))
window_style |= WS_CAPTION | WS_SYSMENU | WS_BORDER;
if (!(RGFW_NO_BORDER & args)) {
window_style |= WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;

if (!(RGFW_NO_RESIZE & args))
window_style |= WS_SIZEBOX;
}
else
window_style |= WS_POPUP | WS_VISIBLE;

if (!(RGFW_NO_RESIZE & args))
window_style |= WS_SIZEBOX;

win->display = CreateWindowA( Class.lpszClassName, name, window_style, x, y, w, h, 0, 0, inh, 0);

if (RGFW_TRANSPARENT_WINDOW & args)
Expand Down Expand Up @@ -2358,7 +2385,6 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
i32 index = 0;

SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
SET_ATTRIB(WGL_STENCIL_BITS_ARB, 8);

if (RGFW_majorVersion || RGFW_minorVersion) {
SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, RGFW_majorVersion);
Expand All @@ -2369,9 +2395,13 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64

win->glWin = wglCreateContextAttribsARB(win->window, NULL, attribs);
}
else
win->glWin = wglCreateContext(win->window);
}
else {
printf("Failed to create an accelerated OpenGL Context\n");
win->glWin = wglCreateContext(win->window);
}
}
else
printf("Failed to create an accelerated OpenGL Context\n");
#endif


Expand Down Expand Up @@ -2413,7 +2443,6 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
#endif

ShowWindow((HWND)win->display, SW_SHOWNORMAL);

return win;
}

Expand Down Expand Up @@ -2496,8 +2525,10 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {
case WM_MOUSEMOVE:
#ifndef RGFW_RECT
win->event.x = msg.pt.x - win->x;
win->event.y = msg.pt.y - win->y;
#else
win->event.x = msg.pt.x - win->r.x;
win->event.y = msg.pt.y - win->r.y;
#endif

win->event.type = RGFW_mousePosChanged;
Expand Down Expand Up @@ -3021,8 +3052,8 @@ RGFW_window* RGFW_createWindow(const char* name, i32 x, i32 y, i32 w, i32 h, u64
}

if (RGFW_CENTER & args) {
x = (r[0] - w) / 4;
y = (r[1] - h) / 4;
x = (r[0] - w) / 2;
y = (r[1] - h) / 2;
}

#ifndef RGFW_RECT
Expand Down
17 changes: 15 additions & 2 deletions example/ext/RGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ typedef GLint (*glGetUniformLocationPROC)(GLuint program, const GLchar *name);
typedef void (*glUniformMatrix4fvPROC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
typedef void (*glTexImage2DPROC)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
typedef void (*glActiveTexturePROC) (GLenum texture);
typedef void (APIENTRY *glDebugMessageCallbackPROC)(void* callback, const void*);

glShaderSourcePROC glShaderSourceSRC = NULL;
glCreateShaderPROC glCreateShaderSRC = NULL;
Expand Down Expand Up @@ -341,6 +342,7 @@ glBindVertexArrayPROC glBindVertexArraySRC = NULL;
glGetUniformLocationPROC glGetUniformLocationSRC = NULL;
glUniformMatrix4fvPROC glUniformMatrix4fvSRC = NULL;
glActiveTexturePROC glActiveTextureSRC = NULL;
glDebugMessageCallbackPROC glDebugMessageCallbackSRC = NULL;

#define glActiveTexture glActiveTextureSRC
#define glShaderSource glShaderSourceSRC
Expand Down Expand Up @@ -371,6 +373,7 @@ glActiveTexturePROC glActiveTextureSRC = NULL;
#define glBindVertexArray glBindVertexArraySRC
#define glGetUniformLocation glGetUniformLocationSRC
#define glUniformMatrix4fv glUniformMatrix4fvSRC
#define glDebugMessageCallback glDebugMessageCallbackSRC

extern int RGL_loadGL3(RGLloadfunc proc);

Expand Down Expand Up @@ -542,7 +545,7 @@ void RGL_opengl_getError() {
#endif

void RGL_debug_shader(u32 src, const char *shader, const char *action) {
GLint status;
GLint status;
if (action[0] == 'l')
glGetProgramiv(src, GL_LINK_STATUS, &status);
else
Expand Down Expand Up @@ -1291,6 +1294,7 @@ int RGL_loadGL3(RGLloadfunc proc) {
RGL_PROC_DEF(proc, glGetUniformLocation);
RGL_PROC_DEF(proc, glUniformMatrix4fv);
RGL_PROC_DEF(proc, glActiveTexture);
RGL_PROC_DEF(proc, glDebugMessageCallback);

if (
glShaderSourceSRC == NULL ||
Expand Down Expand Up @@ -1320,9 +1324,18 @@ int RGL_loadGL3(RGLloadfunc proc) {
glGenBuffersSRC == NULL ||
glBindVertexArraySRC == NULL ||
glGetUniformLocationSRC == NULL ||
glUniformMatrix4fvSRC == NULL
glUniformMatrix4fvSRC == NULL ||
glDebugMessageCallbackSRC == NULL
)
return 1;

size_t vao;
glGenVertexArraysSRC(1, &vao);

if (vao == 0)
return 1;

glDeleteVertexArraysSRC(1, &vao);

return 0;
}
Expand Down
Loading

0 comments on commit ad38750

Please sign in to comment.