Add easy log macros; add vec_init; windows managed by vec now

This commit is contained in:
John Alanbrook 2022-06-27 19:12:26 +00:00
parent bccb0a53fd
commit 9c5767436d
9 changed files with 67 additions and 47 deletions

View file

@ -12,7 +12,7 @@ UNAME_P != uname -m
CCACHE = ccache
#CC specifies which compiler we're using
CC = $(CCACHE) clang
CC = $(CCACHE) tcc
MUSL = /usr/local/musl/include
@ -95,7 +95,7 @@ ifeq ($(UNAME), Windows_NT)
CLIBS = glew32
EXT = .exe
else
LINKER_FLAGS = -fuse-ld=lld #/usr/local/lib/tcc/bcheck.o /usr/local/lib/tcc/bt-exe.o /usr/local/lib/tcc/bt-log.o
LINKER_FLAGS = -g #/usr/local/lib/tcc/bcheck.o /usr/local/lib/tcc/bt-exe.o /usr/local/lib/tcc/bt-log.o
ELIBS = m c engine editor glfw3
CLIBS =
EXT =

View file

@ -46,16 +46,6 @@ struct sFont *MakeFont(const char *fontfile, int height)
printf("failed\n");
}
int tw,th;
unsigned char *testbitmap = stbtt_GetCodepointBitmap(&fontinfo, 0, stbtt_ScaleForPixelHeight(&fontinfo, 100), 'G', &tw, &th, 0,0);
for (int i = 0; i < th; ++i) {
for (int j = 0; j<tw; ++j)
putchar(" .:ioVM@"[testbitmap[i*tw+j]>>5]);
putchar('\n');
}
float scale = stbtt_ScaleForPixelHeight(&fontinfo, 64);
int ascent, descent, linegap;
@ -75,13 +65,6 @@ struct sFont *MakeFont(const char *fontfile, int height)
bitmap = stbtt_GetCodepointBitmap(&fontinfo, 0,
stbtt_ScaleForPixelHeight(&fontinfo, newfont->height), c, &w, &h, 0, 0);
for (int i = 0; i < h; ++i) {
for (int j = 0; j<w; ++j)
putchar(" .:ioVM@"[bitmap[i*w+j]>>5]);
putchar('\n');
}
GLuint ftexture;
glGenTextures(1, &ftexture);
glBindTexture(GL_TEXTURE_2D, ftexture);

View file

@ -9,6 +9,10 @@
#define LOG_CRITICAL 3
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__)
#define YughInfo(msg, ...) mYughLog(0, 0, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughWarn(msg, ...) mYughLog(0, 1, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughError(msg, ...) mYughLog(0, 2, __LINE__, __FILE__, msg, __VA_ARGS__);
#define YughCritical(msg, ...) mYughLog(0, 3, __LINE__, __FILE__, msg, __VA_ARGS__);
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...);

View file

@ -94,6 +94,11 @@ static unsigned int projUBO;
void openglInit()
{
if (!mainwin) {
YughError("No window to init OpenGL on.", 1);
abort();
}
sprite_initialize();
////// MAKE SHADERS

View file

@ -41,7 +41,7 @@ struct Texture *texture_pullfromfile(const char *path)
shput(texhash, tex->path, tex);
glGenTextures(1, &tex->id);
//glGenTextures(1, &tex->id);
return tex;
}

View file

@ -3,6 +3,16 @@
#include <string.h>
#include <stdlib.h>
struct vec vec_init(size_t width, int size)
{
struct vec v;
v.size = size;
v.width = width;
v.len = 0;
v.data = calloc(v.size, v.width);
return v;
}
struct vec *vec_make(size_t width, int size)
{
struct vec *new = calloc(1, sizeof(struct vec));

View file

@ -4,12 +4,13 @@
#include <stdio.h>
struct vec {
int len;
int size;
size_t width;
int len; // How many elements are in the vec
int size; // The capacity of the vec
size_t width; // The size in bytes of an element of the vector
void *data;
};
struct vec vec_init(size_t width, int size);
struct vec *vec_make(size_t width, int size);
void *vec_get(struct vec *vec, int n);
void vec_walk(struct vec *vec, void (*fn)(void *data));

View file

@ -8,42 +8,60 @@
#include <stdlib.h>
#include <stdio.h>
struct mSDLWindow *mainwin;
#include <vec.h>
static struct mSDLWindow *windows[5];
static int numWindows = 0;
static struct mSDLWindow *mainwin;
static struct vec windows;
struct Texture *icon = NULL;
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
uint32_t flags)
{
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
w->width = width;
w->height = height;
w->window = glfwCreateWindow(width, height, name, NULL, NULL);
struct mSDLWindow *w;
if (!w->window) {
printf("Couldn't make GLFW window\n");
if (windows.data == NULL) {
windows = vec_init(sizeof(struct mSDLWindow), 5);
w = vec_add(&windows, NULL);
mainwin = w;
} else {
glfwMakeContextCurrent(w->window);
gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(1);
w->id = numWindows;
if (numWindows < 5)
windows[numWindows++] = w;
w = vec_add(&windows, NULL);
}
mainwin = windows[0];
GLFWwindow *sharewin = mainwin ? NULL : mainwin->window;
w->width = width;
w->height = height;
printf("NUmber of windows: %d.\n", windows.len);
w->id = windows.len-1;
w->window = glfwCreateWindow(width, height, name, NULL, sharewin);
if (!w->window) {
YughError("Couldn't make GLFW window\n", 1);
return w;
}
if (icon) window_seticon(w, icon);
glfwMakeContextCurrent(w->window);
gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(1);
return w;
}
void window_set_icon(const char *png)
{
icon = texture_pullfromfile(png);
}
void window_destroy(struct mSDLWindow *w)
{
glfwDestroyWindow(w->window);
vec_delete(&windows, w->id);
}
void window_handle_event(struct mSDLWindow *w)
@ -131,9 +149,7 @@ void window_handle_event(struct mSDLWindow *w)
void window_all_handle_events()
{
for (int i = 0; i < numWindows; i++) {
window_handle_event(windows[i]);
}
vec_walk(&windows, window_handle_event);
}
void window_makefullscreen(struct mSDLWindow *w)

View file

@ -28,6 +28,7 @@ extern struct mSDLWindow *mainwin;
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
uint32_t flags);
void window_set_icon(const char *png);
void window_destroy(struct mSDLWindow *w);
void window_handle_event(struct mSDLWindow *w);
void window_all_handle_events();