improved FPS by ~5x

This commit is contained in:
Alexandre 2025-02-01 22:28:01 +01:00
parent 576e83feeb
commit 8bd13e158c
25 changed files with 124 additions and 279 deletions

View File

@ -1,6 +1,6 @@
CC = gcc
FLAGS = -O2 -Wall -Wextra -g
LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses src/glad.c -ldl -lglfw -lcglm
LFLAGS = -lm -lncurses src/glad.c -ldl -lglfw -lcglm
all: bin/back

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,16 +8,11 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"
#include "base.h"
imgs digits ;
imgs letters ;
int ln_baseN(int n, int b) {
int r = 0;
while(n != 0) {

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
@ -33,20 +31,20 @@ void init_draworder() {
drawOrder = malloc(sizeof(int)*6) ;
}
float vertices[9] ;
float vertices_tr[9] ;
void gl_renderTriangle(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO, double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, float r, float g, float b) {
vertices[0] = (float)x0;
vertices[1] = (float)y0;
vertices[2] = (float)z0;
vertices[3] = (float)x1;
vertices[4] = (float)y1;
vertices[5] = (float)z1;
vertices[6] = (float)x2;
vertices[7] = (float)y2;
vertices[8] = (float)z2;
vertices_tr[0] = (float)x0;
vertices_tr[1] = (float)y0;
vertices_tr[2] = (float)z0;
vertices_tr[3] = (float)x1;
vertices_tr[4] = (float)y1;
vertices_tr[5] = (float)z1;
vertices_tr[6] = (float)x2;
vertices_tr[7] = (float)y2;
vertices_tr[8] = (float)z2;
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_tr), vertices_tr, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
@ -64,120 +62,78 @@ void gl_renderTriangle(unsigned int shaderProgram, unsigned int VAO, unsigned in
}
double near = 0.4 ;
double far = 30.0 ;
double far = 10.0 ;
double top = 1.0 ;
double bottom = -1.0 ;
double left = -1.0 ;
double right = 1.0 ;
double z_depth(double z) {
return ((2.0*(1/z - 1/near)/(1/far - 1/near)) - 1.0);
//return ((1/z - 1/near)/(1/far - 1/near));
//return (2*z -1);
}
pt_2d gl_project(pt_2d p) {
double w = -p.z;
pt_2d res = {
.x = p.x*(2.0*near/(right-left)) + p.z*(right+left)/(right-left),
.y = p.y*(2.0*near/(top-bottom)) + p.z*(top+bottom)/(top-bottom),
.z = -p.z*(far+near)/(far-near) -(2*far*near)/(far-near),
};
res.x = res.x / w;
res.y = res.y / w;
res.z = res.z / w;
return res;
}
mat4 model, view, projection;
mat4 scale;
float vertices[108];
void init_vertices() {
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f;
vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = -0.5f;
vertices[6] = -0.5f; vertices[7] = 0.5f; vertices[8] = 0.5f;
vertices[9] = -0.5f; vertices[10] = -0.5f; vertices[11] = -0.5f;
vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.5f;
vertices[15] = -0.5f; vertices[16] = 0.5f; vertices[17] = 0.5f;
vertices[18] = 0.5f; vertices[19] = -0.5f; vertices[20] = -0.5f;
vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = -0.5f;
vertices[24] = 0.5f; vertices[25] = 0.5f; vertices[26] = 0.5f;
vertices[27] = 0.5f; vertices[28] = -0.5f; vertices[29] = -0.5f;
vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = 0.5f;
vertices[33] = 0.5f; vertices[34] = 0.5f; vertices[35] = 0.5f;
vertices[36] = -0.5f; vertices[37] = -0.5f; vertices[38] = -0.5f;
vertices[39] = 0.5f; vertices[40] = -0.5f; vertices[41] = -0.5f;
vertices[42] = 0.5f; vertices[43] = -0.5f; vertices[44] = 0.5f;
vertices[45] = -0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f;
vertices[48] = -0.5f; vertices[49] = -0.5f; vertices[50] = 0.5f;
vertices[51] = 0.5f; vertices[52] = -0.5f; vertices[53] = 0.5f;
vertices[54] = -0.5f; vertices[55] = 0.5f; vertices[56] = -0.5f;
vertices[57] = 0.5f; vertices[58] = 0.5f; vertices[59] = -0.5f;
vertices[60] = 0.5f; vertices[61] = 0.5f; vertices[62] = 0.5f;
vertices[63] = -0.5f; vertices[64] = 0.5f; vertices[65] = -0.5f;
vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 0.5f;
vertices[69] = 0.5f; vertices[70] = 0.5f; vertices[71] = 0.5f;
vertices[72] = -0.5f; vertices[73] = -0.5f; vertices[74] = -0.5f;
vertices[75] = 0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f;
vertices[78] = 0.5f; vertices[79] = 0.5f; vertices[80] = -0.5f;
vertices[81] = -0.5f; vertices[82] = -0.5f; vertices[83] = -0.5f;
vertices[84] = -0.5f; vertices[85] = 0.5f; vertices[86] = -0.5f;
vertices[87] = 0.5f; vertices[88] = 0.5f; vertices[89] = -0.5f;
vertices[90] = -0.5f; vertices[91] = -0.5f; vertices[92] = 0.5f;
vertices[93] = 0.5f; vertices[94] = -0.5f; vertices[95] = 0.5f;
vertices[96] = 0.5f; vertices[97] = 0.5f; vertices[98] = 0.5f;
vertices[99] = -0.5f; vertices[100] = -0.5f; vertices[101] = 0.5f;
vertices[102] = -0.5f; vertices[103] = 0.5f; vertices[104] = 0.5f;
vertices[105] = 0.5f; vertices[106] = 0.5f; vertices[107] = 0.5f;
}
void gl_renderSurface(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, int sf) {
float vertices[] = {
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0),
(float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
(float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0),
};
glm_mat4_identity(model);
glm_mat4_identity(scale);
scale[0][0] = (float)(c->w);
scale[1][1] = (float)(c->h);
scale[2][2] = (float)(c->d);
glm_translate(model, (vec3){(float)(c->x+c->w/2.0), (float)(c->y+c->h/2.0), (float)(c->z+c->d/2.0)});
glm_rotate(model, (float)(-c->hz_angle), (vec3){0.0f, 1.0f, 0.0f});
glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f});
vec3 dir0;
vec3 direction;
dir0[0] = sinf((float)(rot_hz)) * cosf((float)(rot_vt));
dir0[1] = -sinf((float)(rot_vt));
dir0[2] = cosf((float)(rot_hz)) * cosf((float)(rot_vt));
glm_vec3_normalize(dir0); // Normalize to unit length
glm_vec3_add((vec3){(float)camx, (float)camy, (float)camz}, dir0, direction);
glm_mat4_identity(view);
glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view);
glm_perspective(glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f, projection);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "scale"), 1, GL_FALSE, (float*)scale);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, (float*)model);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "view"), 1, GL_FALSE, (float*)view);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, (float*)projection);
glUseProgram(fragmentShader);
glUniform4f(glGetUniformLocation(fragmentShader, "u_color"), c->red/255.0f, c->green/255.0f, c->blue/255.0f, 1.0f);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);
// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other
// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.
glBindVertexArray(0);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
@ -198,3 +154,27 @@ void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsig
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, current_room->ents[k].pos);
}
}
vec3 dir0;
vec3 direction;
void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO) {
dir0[0] = sinf((float)(rot_hz)) * cosf((float)(rot_vt));
dir0[1] = -sinf((float)(rot_vt));
dir0[2] = cosf((float)(rot_hz)) * cosf((float)(rot_vt));
glm_vec3_normalize(dir0); // Normalize to unit length
glm_vec3_add((vec3){(float)camx, (float)camy, (float)camz}, dir0, direction);
glm_mat4_identity(view);
glm_lookat((vec3){(float)camx, (float)camy, (float)camz}, direction, (vec3){0.0f, 1.0f, 0.0f}, view);
glm_perspective(glm_rad((float)fov), 1500.0f / 1000.0f, 0.1f, 100.0f, projection);
glUseProgram(shaderProgram);
//glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
}
void gl_drawTriangle() {
}

View File

@ -4,4 +4,7 @@
void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c);
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO);
void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO);
void init_vertices();
#endif

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"
@ -73,7 +71,7 @@ void speen2(double x, double y, double z, double w, double h, double d, double h
dx = 170.0*dx/total;
dy = 170.0*dy/total;
dz = 170.0*dz/total;
appendProj(x, y, z, 0.1, 0.1, 0.1, -dx, -dy, -dz, 0.0, 0.0, 0.0, 255, 0, 0, 10, 3.0);
appendProj(x+w/2, y+h/2, z+d/2, 0.1, 0.1, 0.1, -dx, -dy, -dz, 0.0, 0.0, 0.0, 255, 0, 0, 10, 3.0);
}
}

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "structure.h"
#include "hash.h"

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
@ -98,11 +96,12 @@ void processInput(GLFWwindow *window, float dtime) {
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"uniform mat4 scale;\n"
"uniform mat4 model;\n"
"uniform mat4 view;\n"
"uniform mat4 projection;\n"
"void main() {\n"
" gl_Position = projection * view * model * vec4(aPos, 1.0);\n"
" gl_Position = projection * view * model * scale * vec4(aPos, 1.0);\n"
"}\0";
// Fragment Shader Source
@ -189,16 +188,6 @@ int main_alt() {
// set up data (buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
glBindVertexArray(VAO);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// render loop
// -----------
init_csts();
init_hashtbl();
init_ent_generator(10);
@ -208,9 +197,25 @@ int main_alt() {
int fps = 60 ;
int interval = 1000000/fps ;
clock_t origin = clock();
clock_t finish = clock();
while (!glfwWindowShouldClose(window)) {
clock_t origin = clock();
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
init_vertices();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
// position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
while(!glfwWindowShouldClose(window)) {
// input
// -----
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
@ -219,6 +224,9 @@ int main_alt() {
generate_nearby_chunks(1);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
gl_initRender(shaderProgram, shaderProgram, VAO, VBO);
gl_renderAll(shaderProgram, shaderProgram, VAO, VBO);
gl_renderProj(shaderProgram, shaderProgram, VAO, VBO);
@ -231,12 +239,12 @@ int main_alt() {
processInput(window, ((float)finish - (float)origin)/CLOCKS_PER_SEC);
update_entities(((float)finish - (float)origin)/CLOCKS_PER_SEC);
updateProj(((float)finish - (float)origin)/CLOCKS_PER_SEC);
glfwSwapBuffers(window);
glfwPollEvents();
printf("%f\n", 1.0f/(((float)origin - (float)finish)/CLOCKS_PER_SEC));
usleep(interval);
glfwSwapBuffers(window);
glfwPollEvents();
}
//printf("10\n");

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "hash.h"
#include "structure.h"
@ -106,121 +104,3 @@ bool is_colliding(float dtime) {
}
return false ;
}
bool pass = true ;
void playerActions(float dtime) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
break;
case SDL_MOUSEMOTION:
has_changed = true ;
rot_hz += sensitivity * event.motion.xrel / 100.0 ;
rot_vt -= sensitivity * event.motion.yrel / 100.0 ;
if(rot_hz >= 2*3.141592) {
rot_hz -= 2*3.141592 ;
} else if(rot_hz < 0.0) {
rot_hz += 2*3.141592 ;
}
if(rot_vt <= 3.14159/2.0) {
rot_vt = 3.14159/2.0;
} else if(rot_vt >= 3.0*3.14159/2.0) {
rot_vt = 3.0*3.14159/2.0 ;
}
break;
}
}
const Uint8* state = SDL_GetKeyboardState(NULL);
if(state[SDL_SCANCODE_Z] == 1) {
for(int k = 0; k < 10; k++) {
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
camy += speed*sin(rot_vt)/10;
if(is_colliding(dtime)) {
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
camy -= speed*sin(rot_vt)/10;
k=11;
}
}
}
if(state[SDL_SCANCODE_Q] == 1) {
for(int k = 0; k < 10; k++) {
camx -= speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10;
if(is_colliding(dtime)) {
camx += speed*cos(rot_hz)/10;
camz += speed*sin(rot_hz)/10;
k=11;
}
}
}
if(state[SDL_SCANCODE_S] == 1) {
for(int k = 0; k < 10; k++) {
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
camy -= speed*sin(rot_vt)/10;
if(is_colliding(dtime)) {
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
camy += speed*sin(rot_vt)/10;
k=11;
}
}
}
if(state[SDL_SCANCODE_D] == 1) {
for(int k = 0; k < 10; k++) {
camx += speed*cos(rot_hz)/10;
camz += speed*sin(rot_hz)/10;
if(is_colliding(dtime)) {
camx -= speed*cos(rot_hz)/10;
camz -= speed*sin(rot_hz)/10;
k=11;
}
}
}
if(state[SDL_SCANCODE_SPACE] == 1) {
stop_evetything = true ;
}
if(state[SDL_SCANCODE_T] == 1) {
stop_evetything = true ;
}
if(state[SDL_SCANCODE_A] == 1) {
rot_hz -= sensitivity;
}
if(state[SDL_SCANCODE_E] == 1) {
rot_hz += sensitivity;
}
if(state[SDL_SCANCODE_P] == 1) {
rot_vt -= sensitivity;
}
if(state[SDL_SCANCODE_M] == 1) {
rot_vt += sensitivity;
}
}
void drawHPbar(SDL_Renderer* renderer) {
SDL_Rect r ;
r.x = 1400 ;
r.y = 100 ;
r.w = 50 ;
r.h = 800 ;
SDL_SetRenderDrawColor(renderer, 96, 96, 96, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &r);
r.x += 10 ;
r.w -= 20 ;
r.y += 10 ;
r.h -= 20 ;
SDL_SetRenderDrawColor(renderer, 32, 32, 32, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &r);
r.y = 110+(780*(1000-player_hp))/1000 ;
r.h = 780-r.y+110 ;
SDL_SetRenderDrawColor(renderer, fade_dmg, 255-fade_dmg, 32, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &r);
}

View File

@ -3,8 +3,5 @@
void init_csts();
bool is_colliding(float dtime);
void playerActions(float dtime);
void drawHPbar(SDL_Renderer* renderer);
#endif

View File

@ -8,8 +8,6 @@
#include <termios.h>
#include <limits.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "structure.h"
#include "hash.h"
@ -103,9 +101,9 @@ void gl_renderProj(unsigned int shaderProgram, unsigned int fragmentShader, unsi
}
void move_cube(cube_0* cb, double dx, double dy, double dz) {
cb->x += dx+dy+dz;
cb->y += dx+dy+dz;
cb->z += dx+dy+dz;
cb->x += dx;
cb->y += dy;
cb->z += dz;
}
void updateProj(float dtime) {

View File

@ -1,11 +1,6 @@
#ifndef BACK_CONSTS_H
#define BACK_CONSTS_H
typedef struct imgs {
int len;
SDL_Texture** arr;
} imgs ;
typedef struct pt_2d {
double x;
double y;
@ -87,9 +82,6 @@ typedef hashtbl_0* hashtbl ;
extern double sim_time ;
extern imgs digits ;
extern imgs letters ;
extern double camx ;
extern double camy ;
extern double camz ;
@ -128,4 +120,6 @@ extern double speed ;
extern double min_dist ;
// ---------------------------------------------------------------------------------------------------- //
extern float vertices[108];
#endif