Add easy log macros; add vec_init; windows managed by vec now
This commit is contained in:
parent
bccb0a53fd
commit
9c5767436d
4
Makefile
4
Makefile
|
@ -12,7 +12,7 @@ UNAME_P != uname -m
|
||||||
CCACHE = ccache
|
CCACHE = ccache
|
||||||
|
|
||||||
#CC specifies which compiler we're using
|
#CC specifies which compiler we're using
|
||||||
CC = $(CCACHE) clang
|
CC = $(CCACHE) tcc
|
||||||
|
|
||||||
MUSL = /usr/local/musl/include
|
MUSL = /usr/local/musl/include
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ ifeq ($(UNAME), Windows_NT)
|
||||||
CLIBS = glew32
|
CLIBS = glew32
|
||||||
EXT = .exe
|
EXT = .exe
|
||||||
else
|
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
|
ELIBS = m c engine editor glfw3
|
||||||
CLIBS =
|
CLIBS =
|
||||||
EXT =
|
EXT =
|
||||||
|
|
|
@ -46,16 +46,6 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
printf("failed\n");
|
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);
|
float scale = stbtt_ScaleForPixelHeight(&fontinfo, 64);
|
||||||
|
|
||||||
int ascent, descent, linegap;
|
int ascent, descent, linegap;
|
||||||
|
@ -75,13 +65,6 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
bitmap = stbtt_GetCodepointBitmap(&fontinfo, 0,
|
bitmap = stbtt_GetCodepointBitmap(&fontinfo, 0,
|
||||||
stbtt_ScaleForPixelHeight(&fontinfo, newfont->height), c, &w, &h, 0, 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;
|
GLuint ftexture;
|
||||||
glGenTextures(1, &ftexture);
|
glGenTextures(1, &ftexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, ftexture);
|
glBindTexture(GL_TEXTURE_2D, ftexture);
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
#define LOG_CRITICAL 3
|
#define LOG_CRITICAL 3
|
||||||
|
|
||||||
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__)
|
#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, ...);
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...);
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,11 @@ static unsigned int projUBO;
|
||||||
|
|
||||||
void openglInit()
|
void openglInit()
|
||||||
{
|
{
|
||||||
|
if (!mainwin) {
|
||||||
|
YughError("No window to init OpenGL on.", 1);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
sprite_initialize();
|
sprite_initialize();
|
||||||
|
|
||||||
////// MAKE SHADERS
|
////// MAKE SHADERS
|
||||||
|
|
|
@ -41,7 +41,7 @@ struct Texture *texture_pullfromfile(const char *path)
|
||||||
|
|
||||||
shput(texhash, tex->path, tex);
|
shput(texhash, tex->path, tex);
|
||||||
|
|
||||||
glGenTextures(1, &tex->id);
|
//glGenTextures(1, &tex->id);
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.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 *vec_make(size_t width, int size)
|
||||||
{
|
{
|
||||||
struct vec *new = calloc(1, sizeof(struct vec));
|
struct vec *new = calloc(1, sizeof(struct vec));
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct vec {
|
struct vec {
|
||||||
int len;
|
int len; // How many elements are in the vec
|
||||||
int size;
|
int size; // The capacity of the vec
|
||||||
size_t width;
|
size_t width; // The size in bytes of an element of the vector
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct vec vec_init(size_t width, int size);
|
||||||
struct vec *vec_make(size_t width, int size);
|
struct vec *vec_make(size_t width, int size);
|
||||||
void *vec_get(struct vec *vec, int n);
|
void *vec_get(struct vec *vec, int n);
|
||||||
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
||||||
|
|
|
@ -8,42 +8,60 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct mSDLWindow *mainwin;
|
#include <vec.h>
|
||||||
|
|
||||||
static struct mSDLWindow *windows[5];
|
static struct mSDLWindow *mainwin;
|
||||||
static int numWindows = 0;
|
|
||||||
|
static struct vec windows;
|
||||||
|
struct Texture *icon = NULL;
|
||||||
|
|
||||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
|
struct mSDLWindow *w;
|
||||||
w->width = width;
|
|
||||||
w->height = height;
|
|
||||||
w->window = glfwCreateWindow(width, height, name, NULL, NULL);
|
|
||||||
|
|
||||||
if (!w->window) {
|
if (windows.data == NULL) {
|
||||||
printf("Couldn't make GLFW window\n");
|
windows = vec_init(sizeof(struct mSDLWindow), 5);
|
||||||
|
w = vec_add(&windows, NULL);
|
||||||
|
mainwin = w;
|
||||||
} else {
|
} else {
|
||||||
glfwMakeContextCurrent(w->window);
|
w = vec_add(&windows, NULL);
|
||||||
gladLoadGL(glfwGetProcAddress);
|
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
w->id = numWindows;
|
|
||||||
|
|
||||||
|
|
||||||
if (numWindows < 5)
|
|
||||||
windows[numWindows++] = w;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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)
|
void window_destroy(struct mSDLWindow *w)
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(w->window);
|
glfwDestroyWindow(w->window);
|
||||||
|
vec_delete(&windows, w->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_handle_event(struct mSDLWindow *w)
|
void window_handle_event(struct mSDLWindow *w)
|
||||||
|
@ -131,9 +149,7 @@ void window_handle_event(struct mSDLWindow *w)
|
||||||
|
|
||||||
void window_all_handle_events()
|
void window_all_handle_events()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numWindows; i++) {
|
vec_walk(&windows, window_handle_event);
|
||||||
window_handle_event(windows[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_makefullscreen(struct mSDLWindow *w)
|
void window_makefullscreen(struct mSDLWindow *w)
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern struct mSDLWindow *mainwin;
|
||||||
|
|
||||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||||
uint32_t flags);
|
uint32_t flags);
|
||||||
|
void window_set_icon(const char *png);
|
||||||
void window_destroy(struct mSDLWindow *w);
|
void window_destroy(struct mSDLWindow *w);
|
||||||
void window_handle_event(struct mSDLWindow *w);
|
void window_handle_event(struct mSDLWindow *w);
|
||||||
void window_all_handle_events();
|
void window_all_handle_events();
|
||||||
|
|
Loading…
Reference in a new issue