2009-01-21 01:00:31 +01:00
|
|
|
|
/* libsegl - Sebas Extended GL Library
|
|
|
|
|
* Collection of Opengl/3D-Math helpers
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
|
|
|
|
|
* http://www.seba-geek.de
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library 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
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-02-10 20:50:42 +01:00
|
|
|
|
#include "glsdlscreen.h"
|
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
|
namespace segl {
|
|
|
|
|
|
2008-02-10 20:50:42 +01:00
|
|
|
|
GLSDLScreen::GLSDLScreen() {
|
|
|
|
|
width = 0;
|
|
|
|
|
height = 1;
|
|
|
|
|
bpp = 16;
|
|
|
|
|
znear = 1.0f;
|
|
|
|
|
zfar = 100.0f;
|
|
|
|
|
|
|
|
|
|
opengl = false;
|
|
|
|
|
glsetup = true;
|
|
|
|
|
resizable = false;
|
|
|
|
|
fullscreen = false;
|
|
|
|
|
|
|
|
|
|
extraglparam = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int GLSDLScreen::getFlags() {
|
|
|
|
|
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
|
|
|
|
int videoflags = 0;
|
|
|
|
|
if(videoInfo->hw_available)
|
|
|
|
|
videoflags |= SDL_HWSURFACE;
|
|
|
|
|
else
|
|
|
|
|
videoflags |= SDL_SWSURFACE;
|
|
|
|
|
if(videoInfo->blit_hw)
|
|
|
|
|
videoflags |= SDL_HWACCEL;
|
|
|
|
|
|
|
|
|
|
if(opengl) {
|
|
|
|
|
videoflags |= SDL_OPENGL;
|
|
|
|
|
videoflags |= SDL_GL_DOUBLEBUFFER;
|
|
|
|
|
videoflags |= SDL_HWPALETTE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-23 18:00:55 +01:00
|
|
|
|
if(fullscreen)
|
|
|
|
|
videoflags |= SDL_FULLSCREEN;
|
|
|
|
|
|
2008-02-10 20:50:42 +01:00
|
|
|
|
return videoflags;
|
|
|
|
|
}
|
|
|
|
|
void GLSDLScreen::enableOpenGL(bool w) {
|
|
|
|
|
opengl = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::enableResizable(bool w) {
|
|
|
|
|
resizable = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::enableFullscreen(bool w) {
|
|
|
|
|
fullscreen = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::setGLNearFar(float _znear, float _zfar) {
|
|
|
|
|
znear = _znear;
|
|
|
|
|
zfar = _zfar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::enableGLSetup(bool w) {
|
|
|
|
|
glsetup = w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::setExtraGLParamFunc(void (*extrafunc)()) {
|
|
|
|
|
extraglparam = extrafunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::setVideoMode(int _width, int _height, int _bpp) {
|
|
|
|
|
width = _width;
|
|
|
|
|
height = _height;
|
|
|
|
|
bpp = _bpp;
|
|
|
|
|
|
|
|
|
|
if(height==0)
|
|
|
|
|
height = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-23 18:00:55 +01:00
|
|
|
|
void GLSDLScreen::getVideoRes(std::string vidstr, int *_w, int *_h) {
|
|
|
|
|
if(_w)
|
|
|
|
|
*_w = atoi(vidstr.substr(0, vidstr.find("x")).c_str());
|
|
|
|
|
if(_h)
|
|
|
|
|
*_h = atoi(vidstr.substr(vidstr.find("x")+1, (vidstr.length()-vidstr.find("x")-1)).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-10 20:50:42 +01:00
|
|
|
|
bool GLSDLScreen::isOK() {
|
|
|
|
|
return SDL_VideoModeOK(width, height, bpp, getFlags());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GLSDLScreen::apply() {
|
|
|
|
|
if(!SDL_WasInit(SDL_INIT_VIDEO)) {
|
|
|
|
|
if(SDL_Init(SDL_INIT_VIDEO)==-1) {
|
2008-04-10 01:04:14 +02:00
|
|
|
|
std::cerr << "Konnte SDL_VIDEO nicht initialisieren" << std::endl;
|
2008-02-10 20:50:42 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-10 01:04:14 +02:00
|
|
|
|
|
2008-02-10 20:50:42 +01:00
|
|
|
|
screen = SDL_SetVideoMode(width, height, bpp, getFlags());
|
|
|
|
|
|
|
|
|
|
if(!screen) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(opengl) {
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup GL
|
|
|
|
|
if(glsetup) {
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
|
glAlphaFunc(GL_GREATER, 0.1);
|
2008-07-31 00:51:39 +02:00
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2008-02-10 20:50:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Projection
|
|
|
|
|
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, znear, zfar);
|
|
|
|
|
|
|
|
|
|
if(extraglparam) {
|
|
|
|
|
extraglparam();
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-23 18:00:55 +01:00
|
|
|
|
|
2008-02-15 15:32:34 +01:00
|
|
|
|
|
2008-07-31 00:51:39 +02:00
|
|
|
|
// Texturen neuladen, eigentlich nur f<>r Windows. Aber egal.
|
2008-02-10 20:50:42 +01:00
|
|
|
|
GLTexture::reloadAll();
|
2008-03-23 18:00:55 +01:00
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
|
glLoadIdentity();
|
2008-04-10 01:04:14 +02:00
|
|
|
|
|
2008-03-23 18:00:55 +01:00
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2008-02-10 20:50:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-03-08 23:03:26 +01:00
|
|
|
|
|
|
|
|
|
int GLSDLScreen::getWidth() {
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GLSDLScreen::getHeight() {
|
|
|
|
|
return height;
|
|
|
|
|
}
|
2008-03-23 18:00:55 +01:00
|
|
|
|
|
|
|
|
|
void GLSDLScreen::clearScreen() {
|
|
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSDLScreen::renderScreen() {
|
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
|
}
|
2008-08-10 17:14:54 +02:00
|
|
|
|
|
|
|
|
|
} // namespace segl
|