Techneck/code/source-c/initialization.c

74 lines
2.2 KiB
C

#include "state.h"
#include "world.h"
#include <SDL2/SDL.h>
const char *tc_window_title_g = "Techneck";
techneck_s tc_game_state_g;
void tc_init_renderer(techneck_s *techneck)
{
SDL_Init(SDL_INIT_EVERYTHING);
techneck->renderer.window = SDL_CreateWindow(
tc_window_title_g,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1200,
800,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
);
techneck->renderer.active_camera.position.x = 0.0f;
techneck->renderer.active_camera.position.y = 0.0f;
techneck->renderer.active_camera.position.z = 0.0f;
techneck->renderer.gl_context = SDL_GL_CreateContext(techneck->renderer.window);
gladLoadGLLoader(&SDL_GL_GetProcAddress);
gladLoadGL();
techneck->renderer.draw_shader = tc_make_shader_program("vertex_shader.glsl", "fragment_shader.glsl");
glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
}
void tc_load_textures()
{
tc_game_state_g.block_texture_atlas = tc_load_image_from_disk("assets/block_atlas.png");
tc_game_state_g.block_texture_atlas->name = "Atlas";
tc_upload_image(tc_game_state_g.block_texture_atlas);
tc_image_s *dirt =
tc_create_subimage(tc_game_state_g.block_texture_atlas, 0, 0, 8, 8);
dirt->name = "dirt";
tc_image_s *grass =
tc_create_subimage(tc_game_state_g.block_texture_atlas, 8, 0, 8, 8);
grass->name = "grass";
tc_image_s *stone =
tc_create_subimage(tc_game_state_g.block_texture_atlas, 16, 0, 8, 8);
stone->name = "stone";
}
void tc_init()
{
tc_init_renderer(&tc_game_state_g);
tc_game_state_g.asset_storage = tc_init_asset_storage("assets/");
tc_load_textures();
tc_game_state_g.block_registry = tc_init_blocks();
tc_create_blocks();
tc_init_worlds();
tc_game_state_g.main_world = tc_new_world(&tc_default_terrain_generator_g);
puts("Finished initializing!");
}
void tc_cleanup()
{
SDL_GL_DeleteContext(tc_game_state_g.renderer.gl_context);
SDL_DestroyWindow(tc_game_state_g.renderer.window);
}