#include "M_game.h" int M_initGame(M_Game *game, const char *window_title) { game->window_width = 1280; game->window_height = 720; game->mouse_sens = 10.0f; SDL_Init( SDL_INIT_VIDEO ); game->window = SDL_CreateWindow( window_title, game->window_width, game->window_height, SDL_WINDOW_OPENGL ); SDL_SetWindowRelativeMouseMode(game->window, 1); game->render_info.render_distance = 40.0f; M_setupProjection(90.0f, ((float)game->window_width)/((float)game->window_height), &game->render_info); game->block_atlas = M_createBlockAtlas(); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); game->gpu = SDL_GL_CreateContext(game->window); SDL_GL_MakeCurrent(game->window, game->gpu); game->running = 1; int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress); if (version == 0) { return 1; } game->render_info.global_models = malloc(10*sizeof(M_ViewModel)); game->render_info.global_models[0] = M_createCube(); glClearColor(0.0f, 0.25f, 0.5f, 1.0f); glEnable(GL_DEPTH_TEST); // glEnable(GL_CULL_FACE); // glCullFace(GL_FRONT); return 0; } int M_killGame(M_Game *game) { free(game->render_info.global_models); SDL_Quit(); return 0; } int M_handleEvents(M_Game *game) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_QUIT: game->running = 0; break; case SDL_EVENT_KEY_DOWN: game->running = 0; break; case SDL_EVENT_MOUSE_MOTION: M_Camera *camera = &game->player.camera; camera->yaw += (float)event.motion.xrel * (game->mouse_sens/10); camera->pitch += (float)event.motion.yrel * (game->mouse_sens/10); if (camera->pitch > 90.0f) camera->pitch = 90.0f; if (camera->pitch < -90.0f) camera->pitch = -90.0f; break; } } return 0; }