GLSDLScreen Funktioniert
Testprog ist ein Testprogramm, erstellt ein Fenster
This commit is contained in:
parent
ce1f282bc0
commit
ef309c3240
16
Makefile
16
Makefile
|
@ -1,14 +1,15 @@
|
|||
COMPILER = g++
|
||||
OBJECTS = emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glgui/glgui.a
|
||||
OBJECTS = emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o glgui/glgui.a
|
||||
VERSION = 0.0.1
|
||||
LIBNAME = segl
|
||||
LIBNAME = libsegl
|
||||
|
||||
|
||||
sgllib: $(OBJECTS)
|
||||
segllib: $(OBJECTS)
|
||||
|
||||
sglar: $(OBJECTS)
|
||||
rm -f lib$(LIBNAME).a
|
||||
ar rfc lib$(LIBNAME).a $(OBJECTS)
|
||||
seglar: $(OBJECTS)
|
||||
rm -f $(LIBNAME).a
|
||||
ar rcs $(LIBNAME).a $(OBJECTS)
|
||||
# ranlib $(LIBNAME).a
|
||||
|
||||
%.o: %.cpp %.h
|
||||
$(COMPILER) -c `sdl-config --cflags` $<
|
||||
|
@ -17,6 +18,9 @@ sglar: $(OBJECTS)
|
|||
glgui/glgui.a:
|
||||
cd glgui; $(MAKE);
|
||||
|
||||
testprog: seglar testprog.o
|
||||
g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS)
|
||||
cd glgui; $(MAKE) clean
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# COMPILER = g++
|
||||
COMPILER = g++
|
||||
OBJECTS = button.o object.o textlabel.o window.o
|
||||
|
||||
glguilib: $(OBJECTS)
|
||||
rm glgui.a -f
|
||||
ar rfc glgui.a $(OBJECTS)
|
||||
# rm glgui.a -f
|
||||
ar crus glgui.a $(OBJECTS)
|
||||
|
||||
%.o: %.cpp %.h
|
||||
$(COMPILER) -c `sdl-config --cflags` $<
|
||||
|
|
|
@ -22,7 +22,7 @@ class GLGuiButton : public GLGuiTextLabel {
|
|||
void setHighlightColor();
|
||||
|
||||
void onMouseOver(int m_x, int m_y);
|
||||
void onMouseClick(int m_x, int m_y);
|
||||
void onMouseClick(int m_x, int m_y, int m_button);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
#include "glsdlscreen.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Projection
|
||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, znear, zfar);
|
||||
|
||||
if(extraglparam) {
|
||||
extraglparam();
|
||||
}
|
||||
|
||||
// Texturen neuladen, eigentlich nur für Windows. Aber egal.
|
||||
GLTexture::reloadAll();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef __GLSDLSCREEN_H
|
||||
#define __GLSDLSCREEN_H
|
||||
|
||||
#include <iostream>
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include "gltexture.h"
|
||||
|
||||
class GLSDLScreen {
|
||||
private:
|
||||
SDL_Surface *screen;
|
||||
|
||||
int width, height, bpp;
|
||||
bool opengl;
|
||||
bool glsetup;
|
||||
bool resizable;
|
||||
bool fullscreen;
|
||||
|
||||
// OpenGL related
|
||||
float znear, zfar;
|
||||
void (*extraglparam)();
|
||||
int getFlags();
|
||||
public:
|
||||
GLSDLScreen();
|
||||
|
||||
void enableOpenGL(bool);
|
||||
void enableResizable(bool);
|
||||
void enableFullscreen(bool);
|
||||
void setVideoMode(int _width, int _height, int _bpp);
|
||||
|
||||
void setGLNearFar(float _znear, float _zfar);
|
||||
void enableGLSetup(bool);
|
||||
void setExtraGLParamFunc(void (*extrafunc)());
|
||||
|
||||
bool isOK();
|
||||
bool apply();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
#include "glsdlscreen.h"
|
||||
|
||||
int main() {
|
||||
GLSDLScreen screen;
|
||||
|
||||
screen.enableOpenGL(true);
|
||||
screen.setVideoMode(640, 480, 32);
|
||||
screen.apply();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue