76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#include "../include/app.h"
|
|
#include <GL/gl.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <GL/glu.h>
|
|
|
|
#define SHADOWMAP_SIZE 2048
|
|
int main()
|
|
{
|
|
struct timespec start;
|
|
struct timespec end;
|
|
App app;
|
|
ChunkManager cm;
|
|
app.cm = &cm;
|
|
init_app(&app, 1600, 900);
|
|
|
|
/////
|
|
while(app.is_running) {
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
handle_events(&app);
|
|
update_app(&app);
|
|
|
|
set_view(&app.camera);
|
|
reshape(1600, 900);
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
for (int i = 0; i < app.cm->chunk_count; i++) {
|
|
chunk_render(&app.cm->chunks[i]);
|
|
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
|
}
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
glOrtho(0, 1600, 900, 0, -1, 1);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
|
|
glColor3f(1, 0, 0);//white
|
|
glLineWidth(2.0);
|
|
glBegin(GL_LINES);
|
|
//horizontal line
|
|
glVertex2i(1600 / 2 - 7, 900 / 2);
|
|
glVertex2i(1600 / 2 + 7, 900 / 2);
|
|
glEnd();
|
|
//vertical line
|
|
glBegin(GL_LINES);
|
|
glVertex2i(1600 / 2, 900 / 2 + 7);
|
|
glVertex2i(1600 / 2, 900 / 2 - 7);
|
|
glEnd();
|
|
|
|
|
|
vec3f pos = app.camera.position;
|
|
vec3f dir = get_camera_dir_vec3f(&app.camera);
|
|
|
|
draw_cube(app.cm, 0, pos.x + dir.x * 2, pos.y + dir.y * 2, pos.z + dir.z * 2, 1.0);
|
|
|
|
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;
|
|
}
|