#import "config.h" #import "graphics.h" #import "memory.h" #import "gl_headers.h" #import "oops.h" #include "SDL.h" void clear_screen() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void reshape_screen(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); } graphics *new_graphics(graphics_settings settings) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { oops(critical_error, "Wow. This... has never happened to me before. I just don't know what to say."); } // Try to get a 16-bit depth buffer. SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); // Double-buffer output. SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); Uint32 flags = SDL_OPENGL; if (settings.fullscreen) { flags |= SDL_FULLSCREEN; } graphics *new_graphics = alloc(sizeof(graphics)); new_graphics->screen = SDL_SetVideoMode(settings.screen_width, settings.screen_height, 0, flags); if (new_graphics->screen == NULL) { oops(critical_error, "Couldn't set up the screen. Are you running a really old computer or something?"); } glClearDepth(100.0f); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glClearColor(0.5, 0.1, 0.9, 1.0); reshape_screen(settings.screen_width, settings.screen_height); new_graphics->cam = retain(new_camera(settings)); return new_graphics; }