diff --git a/Makefile b/Makefile index 5adc0d6..22434ac 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC = g++ AR = ar -OBJECTS = punkt3d.o punkt2d.o 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 +OBJECTS = punkt3d.o punkt2d.o 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 fpsmanager.o OBJOPT = -Wall -c `sdl-config --cflags` SUBDIRS = glgui glmenu SUBDIROBJECTS = glgui/*.o glmenu/*.o @@ -8,8 +8,6 @@ VERSION = 0.0.1 LIBNAME = libsegl seglar: $(OBJECTS) subdirs - @echo OBJOPT $(OBJOPT) - @echo CC $(CC) rm -f $(LIBNAME).a $(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS) # ranlib $(LIBNAME).a diff --git a/fpsmanager.cpp b/fpsmanager.cpp new file mode 100644 index 0000000..9c84af1 --- /dev/null +++ b/fpsmanager.cpp @@ -0,0 +1,33 @@ +#include "fpsmanager.h" + +FPSManager::FPSManager(int _fps) { + setFPS(_fps); + frames = 0; + framerate = 0; + lastticks = SDL_GetTicks(); +} + +void FPSManager::setFPS(int _fps) { + if(_fps<1 || _fps > 500) + return; + tickrate = 1000.0f/(float)_fps; +} + +void FPSManager::delay() { + frames++; + + Uint32 now = SDL_GetTicks(); + Uint32 target = lastticks + (Uint32)(tickrate * (float)frames); + + if(now <= target) { + SDL_Delay(target-now); + } else { + framerate = frames/((now-lastticks)/1000.0f); + frames = 0; + lastticks = SDL_GetTicks(); + } +} + +float FPSManager::getFPS() { + return framerate; +} diff --git a/fpsmanager.h b/fpsmanager.h new file mode 100644 index 0000000..bf45d53 --- /dev/null +++ b/fpsmanager.h @@ -0,0 +1,20 @@ +#ifndef __FPSMANAGER_H +#define __FPSMANAGER_H + +#include + +class FPSManager { + private: + Uint32 lastticks; + int frames; + float tickrate; + float framerate; + public: + FPSManager(int _fps); + + void setFPS(int _fps); + void delay(); + float getFPS(); +}; + +#endif diff --git a/glmenu/menuitems.cpp b/glmenu/menuitems.cpp index bd8e292..2b2df3b 100644 --- a/glmenu/menuitems.cpp +++ b/glmenu/menuitems.cpp @@ -85,7 +85,7 @@ void MIToggle::setValueInt(int val) { void MIToggle::setValueString(std::string str) { for(unsigned int t=0; t0?valuewidth:0)); + glDisable(GL_DEPTH_TEST); if(paintbackground&&true) { // geht noch nicht ganz glDisable(GL_TEXTURE_2D); @@ -154,10 +155,12 @@ void MenuMenu::render() { glColor4f(0.2f, 0.2f, 0.2f, 0.3f); GLFontEngine::paintSDLRect(bgarea); glDisable(GL_BLEND); + } for(unsigned int i=0; irender(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, cvlen, cvlen+extravalwidth+valuewidth); pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset; } + glEnable(GL_DEPTH_TEST); } diff --git a/gltexture.cpp b/gltexture.cpp index 336900b..cd50d07 100644 --- a/gltexture.cpp +++ b/gltexture.cpp @@ -136,7 +136,7 @@ bool GLTexture::setParameter(GLint _minfilter, GLint _magfilter, GLint _wraps, G unloadTexture(); return loadLocalSurface(); } else if(filename!="") { - std::cout << "Filename: " << filename << std::endl; + //std::cout << "Filename: " << filename << std::endl; return loadImage(filename); } else { // keine datei, kein surface @@ -144,7 +144,7 @@ bool GLTexture::setParameter(GLint _minfilter, GLint _magfilter, GLint _wraps, G std::cerr << "Couldn't reload GLTexture " << this << "- No surface, no file!" << std::endl; return false; } - std::cout << "Texture reloaded" << std::endl; + //std::cout << "Texture reloaded" << std::endl; } int GLTexture::getW() {