1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* Copyright (C) 2005 Maarten de Boer <maarten@resorama.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#include "Screen.hxx"
#include "SDL.h"
#include <GL/gl.h>
#include <cstdlib>
Screen::Screen(int _w, int _h)
:w(_w), h(_h)
{
flags = 0;
bpp = 0;
sdl_surface = 0;
}
void Screen::FullScreen(bool b)
{
if (b)
flags |= SDL_FULLSCREEN;
else
flags &= (~SDL_FULLSCREEN);
}
void Screen::DoubleBuffer(bool b)
{
if (b)
flags |= SDL_DOUBLEBUF;
else
flags &= (~SDL_DOUBLEBUF);
}
void Screen::Init(void)
{
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
GLint gl_doublebuf;
GLint maxtexsize;
flags |= SDL_OPENGL;
gl_doublebuf = flags & SDL_DOUBLEBUF;
if (bpp == 15) {
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
}
if (bpp == 16) {
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
} else if (bpp >= 24) {
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
}
if (bpp)
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, bpp);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, gl_doublebuf);
sdl_surface = SDL_SetVideoMode(w, h, bpp, flags);
if (!sdl_surface) {
fprintf(stderr, "Failed to open screen %d %d %d %d!\n", w, h, bpp,
flags);
exit(-1);
}
/*
SDL_Delay(1000);
*/
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
if (maxtexsize < 1024) {
fprintf(stderr, "Need at least 1024x1024 textures!\n");
exit(-1);
}
/*
* Set up OpenGL for 2D rendering.
*/
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
}
void Screen::Exit(void)
{
SDL_Quit();
}
void Screen::Flip(void)
{
SDL_GL_SwapBuffers();
}
|