break and place blocks

This commit is contained in:
onezplpl 2024-07-18 13:46:29 -04:00
parent 227d642be6
commit ed720e0ea0
No known key found for this signature in database
GPG key ID: 7EC026A136F9EEC3
2 changed files with 61 additions and 54 deletions

27
main.c
View file

@ -147,7 +147,7 @@ int main(void) {
struct v3f *cubeO = malloc(CTRI_ALL);
struct v3f *textO = malloc(CTRI_ALL);
int bleh = (CHUNK_DIAMETER_H) * (CHUNK_DIAMETER_V);
int *i2 = calloc(bleh, sizeof(int));
int *i2 = calloc(CHUNK_ALL, sizeof(int));
GLuint vertex_buffer[2];
@ -217,7 +217,7 @@ int main(void) {
pos[1] += (state ? 1 : -1);
}
pos[1] += 15;
pos[1] += 5;
// int x = 0, y = 25, z = 0;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
@ -231,11 +231,13 @@ int main(void) {
struct chunk chunk = gen_chunk(pos[0] / CHUNK_LENGTH, pos[1] / CHUNK_LENGTH,
pos[2] / CHUNK_LENGTH, 0, 0);
is_render = 2;
vec3 dir_temp = {0, 0, 0};
vec3 direction;
fr = 1;
fr = 0;
while (!glfwWindowShouldClose(window)) {
@ -281,9 +283,9 @@ int main(void) {
args.text = &text;
args.cubeO = &cubeO;
args.textO = &textO;
args.pos[0] = pos[0] + direction[0] / 400.0 * CHUNK_LENGTH;
args.pos[0] = pos[0];
args.pos[1] = pos[1];
args.pos[2] = pos[2] + direction[2] / 400.0 * CHUNK_LENGTH;
args.pos[2] = pos[2];
args.vertex_buffer = vertex_buffer;
args.is_render = &is_render;
args.i2 = i2;
@ -304,14 +306,15 @@ int main(void) {
glfwPollEvents();
if (is_render == 2) {
if (thread_id != 0) {
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
glBufferSubData(GL_ARRAY_BUFFER, 0,
(long)cube_count * sizeof(struct v3f), textO);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
glBufferSubData(GL_ARRAY_BUFFER, 0, (long)cube_count * sizeof(struct v3f),
textO);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0,
(long)cube_count * sizeof(struct v3f), cubeO);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, (long)cube_count * sizeof(struct v3f),
cubeO);
if (thread_id != 0) {
pthread_join(thread_id, NULL);
chunk = gen_chunk(pos[0] / CHUNK_LENGTH, pos[1] / CHUNK_LENGTH,
pos[2] / CHUNK_LENGTH, 0, 0);