OPENGL order rewrite
This commit is contained in:
parent
8009c48547
commit
bccb0a53fd
|
@ -7,6 +7,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <window.h>
|
||||||
|
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
#define STBTT_STATIC
|
#define STBTT_STATIC
|
||||||
|
@ -25,6 +26,11 @@ void font_init() {
|
||||||
shader = MakeShader("textvert.glsl", "textfrag.glsl");
|
shader = MakeShader("textvert.glsl", "textfrag.glsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void font_frame(struct mSDLWindow *w) {
|
||||||
|
shader_use(shader);
|
||||||
|
shader_setmat4(shader, "projection", w->projection);
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
@ -69,6 +75,13 @@ 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);
|
||||||
|
@ -180,7 +193,7 @@ void text_settype(struct sFont *mfont)
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
shader_use(shader);
|
//shader_use(shader);
|
||||||
shader_setvec3(shader, "textColor", color);
|
shader_setvec3(shader, "textColor", color);
|
||||||
|
|
||||||
mfloat_t cursor[2] = { 0.f };
|
mfloat_t cursor[2] = { 0.f };
|
||||||
|
|
|
@ -19,7 +19,10 @@ struct sFont {
|
||||||
struct Character Characters[127];
|
struct Character Characters[127];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mSDLWindow;
|
||||||
|
|
||||||
void font_init();
|
void font_init();
|
||||||
|
void font_frame(struct mSDLWindow *w);
|
||||||
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]);
|
||||||
|
|
|
@ -102,12 +102,13 @@ void openglInit()
|
||||||
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
||||||
animSpriteShader =
|
animSpriteShader =
|
||||||
MakeShader("animspritevert.glsl", "animspritefrag.glsl");
|
MakeShader("animspritevert.glsl", "animspritefrag.glsl");
|
||||||
|
textShader = MakeShader("textvert.glsl", "textfrag.glsl");
|
||||||
|
|
||||||
debugdraw_init();
|
debugdraw_init();
|
||||||
|
|
||||||
//stdFont = MakeFont("notosans.ttf", 300);
|
stdFont = MakeFont("notosans.ttf", 300);
|
||||||
|
|
||||||
//text_settype(stdFont);
|
text_settype(stdFont);
|
||||||
|
|
||||||
//glEnable(GL_STENCIL_TEST);
|
//glEnable(GL_STENCIL_TEST);
|
||||||
glClearColor(editorClearColor[0], editorClearColor[1],
|
glClearColor(editorClearColor[0], editorClearColor[1],
|
||||||
|
@ -130,7 +131,7 @@ void openglInit()
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,28 +148,28 @@ void openglRender(struct mSDLWindow *window, struct mCamera *mcamera)
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
glBindBuffer(GL_UNIFORM_BUFFER, projUBO);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, projection);
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, projection);
|
||||||
|
|
||||||
/*
|
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
*/
|
|
||||||
// Clear color and depth
|
// Clear color and depth
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
|
||||||
GL_STENCIL_BUFFER_BIT);
|
GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
////// TEXT && GUI
|
////// TEXT && GUI
|
||||||
/*
|
|
||||||
glDepthFunc(GL_ALWAYS);
|
glDepthFunc(GL_ALWAYS);
|
||||||
shader_use(textShader);
|
//shader_use(textShader);
|
||||||
shader_setmat4(textShader, "projection", window->projection);
|
//shader_setmat4(textShader, "projection", window->projection);
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
mfloat_t fontpos[2] = { 25.f, 25.f };
|
|
||||||
mfloat_t fontcolor[3] = { 0.5f, 0.8f, 0.2f };
|
//mfloat_t fontpos[2] = { 25.f, 25.f };
|
||||||
renderText(stdFont, textShader, "Sample text", fontpos, 0.4f, fontcolor, -1.f);
|
//mfloat_t fontcolor[3] = { 0.5f, 0.8f, 0.2f };
|
||||||
*/
|
//renderText("Sample text", fontpos, 0.4f, fontcolor, -1.f);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < numSprites; i++) {
|
for (int i = 0; i < numSprites; i++) {
|
||||||
|
|
Loading…
Reference in a new issue