Makefile now tracks headers
This commit is contained in:
parent
a45862c454
commit
549753d0c2
8
Makefile
8
Makefile
|
@ -85,7 +85,7 @@ endif
|
||||||
|
|
||||||
LELIBS := -Wl,-Bstatic $(addprefix -l, ${ELIBS}) -Wl,-Bdynamic $(addprefix -l, $(CLIBS))
|
LELIBS := -Wl,-Bstatic $(addprefix -l, ${ELIBS}) -Wl,-Bdynamic $(addprefix -l, $(CLIBS))
|
||||||
|
|
||||||
|
DEPENDS := $(patsubst %.o, %.d, $(bsobjects) $(eobjects))
|
||||||
|
|
||||||
yuginec := ./source/engine/yugine.c
|
yuginec := ./source/engine/yugine.c
|
||||||
|
|
||||||
|
@ -104,15 +104,17 @@ xbrainstorm: libengine.a $(bsobjects)
|
||||||
@$(CXX) $(bsobjects) -DGLEW_STATIC $(includeflag) $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
|
@$(CXX) $(bsobjects) -DGLEW_STATIC $(includeflag) $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
|
||||||
mv xbrainstorm brainstorm/brainstorm$(EXT)
|
mv xbrainstorm brainstorm/brainstorm$(EXT)
|
||||||
|
|
||||||
|
-include $(DEPENDS)
|
||||||
|
|
||||||
$(objprefix)/%.o:%.cpp
|
$(objprefix)/%.o:%.cpp
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@echo Making C++ object $@
|
@echo Making C++ object $@
|
||||||
@$(CXX) $(includeflag) $(COMPILER_FLAGS) -c $< -o $@
|
@$(CXX) $(includeflag) $(COMPILER_FLAGS) -c -MMD -MP $< -o $@
|
||||||
|
|
||||||
$(objprefix)/%.o:%.c
|
$(objprefix)/%.o:%.c
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@echo Making C object $@
|
@echo Making C object $@
|
||||||
@$(CC) $(includeflag) $(COMPILER_FLAGS) -c $< -o $@
|
@$(CC) $(includeflag) $(COMPILER_FLAGS) -c -MMD -MP $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo Cleaning project
|
@echo Cleaning project
|
||||||
|
|
|
@ -11,17 +11,19 @@
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
|
|
||||||
static struct Character Characters[127] = { '\0' };
|
|
||||||
|
|
||||||
static uint32_t VBO = 0;
|
static uint32_t VBO = 0;
|
||||||
static uint32_t VAO = 0;
|
static uint32_t VAO = 0;
|
||||||
|
|
||||||
unsigned char ttf_buffer[24 << 20];
|
unsigned char ttf_buffer[24 << 20];
|
||||||
unsigned char temp_bitmap[512 * 512];
|
unsigned char temp_bitmap[512 * 512];
|
||||||
|
|
||||||
static struct sFont *font;
|
struct sFont *font;
|
||||||
static struct mShader *shader;
|
static struct mShader *shader;
|
||||||
|
|
||||||
|
void font_init() {
|
||||||
|
shader = MakeShader("textvert.glsl", "textfrag.glsl");
|
||||||
|
}
|
||||||
|
|
||||||
struct sFont *MakeFont(const char *fontfile, int height)
|
struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
{
|
{
|
||||||
struct sFont *newfont = calloc(1, sizeof(struct sFont));
|
struct sFont *newfont = calloc(1, sizeof(struct sFont));
|
||||||
|
@ -65,12 +67,12 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||||
GL_LINEAR_MIPMAP_LINEAR);
|
GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
|
||||||
Characters[c].TextureID = ftexture;
|
newfont->Characters[c].TextureID = ftexture;
|
||||||
Characters[c].Advance = advance;
|
newfont->Characters[c].Advance = advance;
|
||||||
Characters[c].Size[0] = w;
|
newfont->Characters[c].Size[0] = w;
|
||||||
Characters[c].Size[1] = h;
|
newfont->Characters[c].Size[1] = h;
|
||||||
Characters[c].Bearing[0] = lsb;
|
newfont->Characters[c].Bearing[0] = lsb;
|
||||||
Characters[c].Bearing[1] = 0;
|
newfont->Characters[c].Bearing[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure VAO/VBO for texture quads
|
// configure VAO/VBO for texture quads
|
||||||
|
@ -157,10 +159,13 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_settype(struct sFont *mfont, struct mShader *mshader)
|
void text_settype(struct sFont *mfont)
|
||||||
{
|
{
|
||||||
font = mfont;
|
font = mfont;
|
||||||
shader = mshader;
|
}
|
||||||
|
|
||||||
|
void strwidth(const char *str) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw)
|
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw)
|
||||||
|
@ -176,69 +181,47 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
char modText[sizeof(*text)];
|
|
||||||
strcpy(modText, text);
|
|
||||||
|
|
||||||
char *line, *wordstart;
|
char *line, *wordstart;
|
||||||
line = strtok(modText, "\n");
|
line = text;
|
||||||
|
|
||||||
while (line != NULL) {
|
|
||||||
cursor[0] = pos[0];
|
|
||||||
|
|
||||||
int wordWidth = 0;
|
|
||||||
|
|
||||||
// iterate through all characters
|
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
|
|
||||||
|
switch (*line) {
|
||||||
|
case '\n':
|
||||||
|
cursor[1] -= scale * font->height;
|
||||||
|
line++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ' ':
|
||||||
|
sdrawCharacter(font->Characters[*line], cursor, scale, shader, color);
|
||||||
|
cursor[0] += font->Characters[*line].Advance * scale;
|
||||||
|
line++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
wordstart = line;
|
wordstart = line;
|
||||||
if (!isspace(*line)) {
|
int wordWidth = 0;
|
||||||
struct Character ch = Characters[*line];
|
|
||||||
|
|
||||||
if (lw > 0
|
while (!isspace(*line) && *line != '\0') {
|
||||||
&& (cursor[0] + ((ch.Advance >> 6) * scale) - pos[0] >=
|
wordWidth += font->Characters[*line].Advance * scale;
|
||||||
lw)) {
|
line++;
|
||||||
cursor[0] = pos[0];
|
|
||||||
cursor[1] -= scale * font->height;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// now advance cursors for next glyph (note that advance is number of 1/64 pixels)
|
|
||||||
cursor[0] += (ch.Advance >> 6) * scale; // bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sdrawCharacter(ch, cursor, scale, shader, color);
|
if (lw > 0 && (cursor[0] + wordWidth - pos[0]) >= lw) {
|
||||||
++line;
|
|
||||||
} else {
|
|
||||||
while (!isspace(*line) || *line != '\0') { // Seek line to the end of the word
|
|
||||||
++line;
|
|
||||||
wordWidth += (Characters[*line].Advance >> 6) * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now wordStart and stringPos surround the word, go through them. If the word that's about to be drawn goes past the line width, go to next line
|
|
||||||
if (lw > 0 && (cursor[0] + wordWidth - pos[0] >= lw)) {
|
|
||||||
cursor[0] = pos[0];
|
cursor[0] = pos[0];
|
||||||
cursor[1] -= scale * font->height;
|
cursor[1] -= scale * font->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (wordstart < line) { // Go through
|
while (wordstart < line) {
|
||||||
|
sdrawCharacter(font->Characters[*wordstart], cursor, scale, shader, color);
|
||||||
|
cursor[0] += font->Characters[*wordstart].Advance * scale;
|
||||||
struct Character ch = Characters[*wordstart];
|
wordstart++;
|
||||||
sdrawCharacter(Characters[*wordstart], cursor, scale,
|
}
|
||||||
shader, color);
|
|
||||||
|
|
||||||
cursor[0] += (ch.Advance >> 6) * scale;
|
|
||||||
++wordstart;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
cursor[1] -= scale * font->height;
|
|
||||||
|
|
||||||
line = strtok(NULL, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
|
@ -16,12 +16,14 @@ struct Character {
|
||||||
struct sFont {
|
struct sFont {
|
||||||
uint32_t fontTexture;
|
uint32_t fontTexture;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
struct Character Characters[127];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void font_init();
|
||||||
struct sFont *MakeFont(const char *fontfile, int height);
|
struct sFont *MakeFont(const char *fontfile, int height);
|
||||||
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale,
|
void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale,
|
||||||
struct mShader *shader, float color[3]);
|
struct mShader *shader, float color[3]);
|
||||||
void text_settype(struct sFont *font, struct mShader *shader);
|
void text_settype(struct sFont *font);
|
||||||
void renderText(
|
void renderText(
|
||||||
const char *text, mfloat_t pos[2], float scale,
|
const char *text, mfloat_t pos[2], float scale,
|
||||||
mfloat_t color[3], float lw);
|
mfloat_t color[3], float lw);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#define logLevel 0
|
#define logLevel 4
|
||||||
|
|
||||||
void mYughLog(int category, int priority, const char *message,
|
void mYughLog(int category, int priority, const char *message,
|
||||||
int line, const char *file, ...)
|
int line, const char *file, ...)
|
||||||
|
|
|
@ -107,7 +107,6 @@ void openglInit(struct mSDLWindow *window)
|
||||||
////// MAKE SHADERS
|
////// MAKE SHADERS
|
||||||
outlineShader = MakeShader("outlinevert.glsl", "outline.glsl");
|
outlineShader = MakeShader("outlinevert.glsl", "outline.glsl");
|
||||||
|
|
||||||
textShader = MakeShader("textvert.glsl", "textfrag.glsl");
|
|
||||||
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
||||||
animSpriteShader =
|
animSpriteShader =
|
||||||
MakeShader("animspritevert.glsl", "animspritefrag.glsl");
|
MakeShader("animspritevert.glsl", "animspritefrag.glsl");
|
||||||
|
@ -116,6 +115,8 @@ void openglInit(struct mSDLWindow *window)
|
||||||
|
|
||||||
stdFont = MakeFont("notosans.ttf", 300);
|
stdFont = MakeFont("notosans.ttf", 300);
|
||||||
|
|
||||||
|
text_settype(stdFont);
|
||||||
|
|
||||||
//glEnable(GL_STENCIL_TEST);
|
//glEnable(GL_STENCIL_TEST);
|
||||||
glClearColor(editorClearColor[0], editorClearColor[1],
|
glClearColor(editorClearColor[0], editorClearColor[1],
|
||||||
editorClearColor[2], editorClearColor[3]);
|
editorClearColor[2], editorClearColor[3]);
|
||||||
|
@ -137,7 +138,7 @@ void openglInit(struct mSDLWindow *window)
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
shader_setUBO(spriteShader, "Projection", 0);
|
shader_setUBO(spriteShader, "Projection", 0);
|
||||||
shader_setUBO(textShader, "Projection", 0);
|
/* shader_setUBO(textShader, "Projection", 0);*/
|
||||||
shader_setUBO(animSpriteShader, "Projection", 0);
|
shader_setUBO(animSpriteShader, "Projection", 0);
|
||||||
|
|
||||||
|
|
||||||
|
@ -622,7 +623,7 @@ void openglRender3d(struct mSDLWindow *window, struct mCamera *mcamera)
|
||||||
shader_setmat4(textShader, "projection", window->projection);
|
shader_setmat4(textShader, "projection", window->projection);
|
||||||
mfloat_t fontpos[2] = { 25.f, 25.f };
|
mfloat_t fontpos[2] = { 25.f, 25.f };
|
||||||
mfloat_t fontcolor[3] = { 0.5f, 0.8f, 0.2f };
|
mfloat_t fontcolor[3] = { 0.5f, 0.8f, 0.2f };
|
||||||
text_settype(stdFont, textShader);
|
text_settype(stdFont);
|
||||||
renderText("Sample text", fontpos, 0.4f,
|
renderText("Sample text", fontpos, 0.4f,
|
||||||
fontcolor, -1.f);
|
fontcolor, -1.f);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue