added draw_string function + addeed dps when clipping inside block

This commit is contained in:
Alexandre 2025-02-09 20:51:03 +01:00
parent 30717e9c1f
commit 2f07c81f4f
8 changed files with 46 additions and 4 deletions

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -222,6 +222,6 @@ void gl_drawData(unsigned int shaderProg) {
gl_drawInteger(shaderProg, njumps, 0.0f, 0.80f, 0.04f, 255, 255, 128, 0.005f, 1);
gl_drawString(shaderProg, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", -0.95f, 0.7f, 0.03f, 255-player_hp/4, player_hp/4, 0, 0.003f, 1);
gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
gl_printf(shaderProg, -0.95f, 0.9f, 0.05f, 0.005f, 255-player_hp/4, player_hp/4, 0, "HP %d", player_hp);
//gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
}

View File

@ -294,8 +294,48 @@ void gl_drawString(unsigned int fragShader, char* str, float x, float y, float s
}
}
void gl_printf(unsigned int fragShader, int count, ...) {
void gl_printf(unsigned int fragShader, float x, float y, float size, float width, int r, int g, int b, const char* str, ...) {
va_list args;
va_start(args, str);
int i = 0;
char cur = str[i];
bool is_perc = false;
float curx = x;
while(cur != '\0') {
//printf("%f\n", curx);
if(is_perc) {
is_perc = false;
switch (cur) {
case 'd':
int val = (int)(va_arg(args, int));
//printf("%d", val);
gl_drawInteger(fragShader, val, curx, y, size, r, g, b, width, 1);
curx += (size+4*width)*(ln_baseN(abs(val), 10));
break;
case 's':
char* chval = (char*)(va_arg(args, const char*));
//printf("%s", chval);
gl_drawString(fragShader, chval, curx, y, size, r, g, b, width, 1);
curx += (size+4*width)*(1+get_string_len(chval));
break;
default:
break;
}
} else {
if(cur == '%') {
is_perc = true;
} else {
//printf("%c", cur);
gl_drawChar(fragShader, cur, curx, y, size, r, g, b, width);
curx += (size+4*width);
}
}
i += 1;
cur = str[i];
}
va_end(args);
//printf("\n");
}
void gl_initDrawRect(unsigned int shaderProgram) {

View File

@ -35,6 +35,7 @@ void gl_initDrawRect(unsigned int shaderProgram);
void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size, int r, int g, int b, float width, int side);
void gl_drawString(unsigned int fragShader, char* str, float x, float y, float size, int r, int g, int b, float width, int side);
void gl_printf(unsigned int fragShader, float x, float y, float size, float width, int r, int g, int b, const char* str, ...);
void init_interf();
void free_interf();

View File

@ -176,7 +176,7 @@ void updateF(cube_0* cb, double dtime) {
(dot3D(vt, normal) <= 0.0 && dot3D(vtdt, normal) >= 0.0) ||
(dot3D(vt, normal) >= 0.0 && dot3D(vtdt, normal) <= 0.0)
) {
printf("%d\n", d);
//printf("%d\n", d);
double normv = sqrt(camvx*camvx + camvy*camvy + camvz*camvz);
double alpha = acos(dot3D(normal, (pt_2d){.x = camvx, .y = camvy, .z = camvz})/normv);
@ -240,6 +240,7 @@ bool is_colliding(float dtime) {
}
}
}
is_clipping = false;
return true;
}
}