78 lines
2.2 KiB
C
78 lines
2.2 KiB
C
#include "../include/app.h"
|
|
#include <GL/gl.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
int main()
|
|
{
|
|
App app;
|
|
init_app(&app, 1280, 720);
|
|
|
|
Chunk *chunks = malloc(25*sizeof(Chunk));
|
|
memset(chunks, 0, 25*sizeof(Chunk));
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
for (int j = 0; j < 5; j++) {
|
|
Chunk c;
|
|
c.start_pos.x = i*CHUNK_MAX_X;
|
|
c.start_pos.y = j*CHUNK_MAX_Y;
|
|
c.start_pos.z = 0;
|
|
for (int x = 0; x < CHUNK_MAX_X; x++) {
|
|
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
|
for (int z = 0; z < CHUNK_MAX_Z; z++) {
|
|
if (z < 40)
|
|
c.blocks[x][y][z].type = BLOCKTYPE_STONE;
|
|
else
|
|
c.blocks[x][y][z].type = BLOCKTYPE_AIR;
|
|
}
|
|
}
|
|
}
|
|
chunk_set_blocks_visibility(&c);
|
|
chunk_create_displayl(&app, &c);
|
|
|
|
chunks[i+(j*5)] = c;
|
|
}
|
|
}
|
|
|
|
app.chunks = chunks;
|
|
app.chunk_count = 25;
|
|
|
|
app_generate_world(&app, 5);
|
|
|
|
while(app.is_running) {
|
|
struct timespec start;
|
|
struct timespec end;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
|
|
|
handle_events(&app);
|
|
update_app(&app);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
set_view(&app.camera);
|
|
|
|
for (int i = 0; i < 25; i++) {
|
|
chunk_render(&chunks[i]);
|
|
}
|
|
|
|
// vec3f pos = app.camera.position;
|
|
// vec3f dir = get_camera_dir_vec3f(&app.camera);
|
|
|
|
// draw_cube(&app, pos.x + dir.x*3, pos.y + dir.y*3, pos.z + dir.z*3);
|
|
|
|
SDL_GL_SwapWindow(app.window);
|
|
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &end);
|
|
|
|
app.frame_time = calc_frame_time(&start, &end);
|
|
|
|
//printf("fps: %f\n", 1000/app.frame_time);
|
|
//printf("lkat pos x: %f y: %f z: %f\n", pos.x+5*dir.x, pos.y+5*dir.y, pos.z+5*dir.z);
|
|
//printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
|
//printf("dir x: %f y: %f z: %f\n", dir.x, dir.y, dir.z);
|
|
//printf("dird x: %f y: %f z: %f\n", app.camera.rotation.x, app.camera.rotation.y, app.camera.rotation.z);
|
|
}
|
|
|
|
return 0;
|
|
}
|