diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-03-04 16:32:40 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-03-04 16:33:19 +0300 |
commit | 8fd450f698f8277eb8348da914d3dcbc11890ea6 (patch) | |
tree | ebaddac087d5e5b29f23a2aa01dd2758c3b8f68a /src/opengl1graphics.cpp | |
parent | c6d7f7ed3d6d7827b820670faf6c48f0689fd5c2 (diff) | |
parent | f74202392745923f9ce372a6bdcd0a45db6bcd08 (diff) | |
download | manaverse-8fd450f698f8277eb8348da914d3dcbc11890ea6.tar.gz manaverse-8fd450f698f8277eb8348da914d3dcbc11890ea6.tar.bz2 manaverse-8fd450f698f8277eb8348da914d3dcbc11890ea6.tar.xz manaverse-8fd450f698f8277eb8348da914d3dcbc11890ea6.zip |
Merge branch 'master' into stripped
Conflicts:
configure.ac
data/Makefile.am
data/fonts/liberationsans-bold.ttf
data/fonts/liberationsans.ttf
data/fonts/liberationsansmono-bold.ttf
data/fonts/liberationsansmono.ttf
data/themes/redandblack/CMakeLists.txt
data/themes/redandblack/Makefile.am
po/cs.po
po/de.po
po/es.po
po/fi.po
po/fr.po
po/id.po
po/ja.po
po/manaplus.pot
po/nl_BE.po
po/pl.po
po/pt.po
po/pt_BR.po
po/ru.po
po/zh_CN.po
src/guichan/color.cpp
src/guichan/defaultfont.cpp
src/guichan/focushandler.cpp
src/guichan/include/guichan/actionlistener.hpp
src/guichan/include/guichan/deathlistener.hpp
src/guichan/include/guichan/focushandler.hpp
src/guichan/include/guichan/focuslistener.hpp
src/guichan/include/guichan/graphics.hpp
src/guichan/include/guichan/keylistener.hpp
src/guichan/include/guichan/listmodel.hpp
src/guichan/include/guichan/mouselistener.hpp
src/guichan/include/guichan/sdl/sdlpixel.hpp
src/guichan/include/guichan/widget.hpp
src/guichan/include/guichan/widgetlistener.hpp
src/guichan/include/guichan/widgets/listbox.hpp
src/guichan/include/guichan/widgets/slider.hpp
src/guichan/sdl/sdlgraphics.cpp
src/guichan/sdl/sdlimage.cpp
src/guichan/widgets/scrollarea.cpp
src/guichan/widgets/slider.cpp
src/guichan/widgets/tabbedarea.cpp
src/guichan/widgets/textbox.cpp
src/guichan/widgets/window.cpp
src/net/manaserv/attributes.cpp
src/net/manaserv/beinghandler.cpp
src/net/manaserv/charhandler.cpp
src/net/manaserv/gamehandler.h
src/net/manaserv/inventoryhandler.cpp
src/net/manaserv/inventoryhandler.h
src/net/manaserv/itemhandler.cpp
src/net/manaserv/loginhandler.cpp
src/net/manaserv/network.cpp
Diffstat (limited to 'src/opengl1graphics.cpp')
-rw-r--r-- | src/opengl1graphics.cpp | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index 34e9fcda3..b04deedac 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -25,6 +25,7 @@ #ifdef USE_OPENGL #include "opengl1graphics.h" +#include "configuration.h" #include "graphicsvertexes.h" #include "logger.h" @@ -46,8 +47,8 @@ GLuint OpenGL1Graphics::mLastImage = 0; OpenGL1Graphics::OpenGL1Graphics(): - mAlpha(false), mTexture(false), mColorAlpha(false), - mSync(false) + mAlpha(false), mTexture(false), mColorAlpha(false), mSync(false), + mFboId(0), mTextureId(0), mRboId(0) { mOpenGL = 2; } @@ -393,8 +394,10 @@ void OpenGL1Graphics::drawRescaledImagePattern(Image *image, int x, int y, // Draw a set of textured rectangles glBegin(GL_QUADS); - const float scaleFactorW = (float) scaledWidth / image->getWidth(); - const float scaleFactorH = (float) scaledHeight / image->getHeight(); + const float scaleFactorW = static_cast<float>(scaledWidth) + / image->getWidth(); + const float scaleFactorH = static_cast<float>(scaledHeight) + / image->getHeight(); for (int py = 0; py < h; py += ih) { @@ -491,10 +494,54 @@ void OpenGL1Graphics::_endDraw() popClipArea(); } +void OpenGL1Graphics::prepareScreenshot() +{ +#if !defined(_WIN32) + if (config.getBoolValue("usefbo")) + { + int h = mTarget->h; + int w = mTarget->w; + + // create a texture object + glGenTextures(1, &mTextureId); + glBindTexture(GL_TEXTURE_2D, mTextureId); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glBindTexture(GL_TEXTURE_2D, 0); + + // create a renderbuffer object to store depth info + glGenRenderbuffersEXT(1, &mRboId); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRboId); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + GL_DEPTH_COMPONENT, w, h); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); + + // create a framebuffer object + glGenFramebuffersEXT(1, &mFboId); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId); + + // attach the texture to FBO color attachment point + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, mTextureId, 0); + + // attach the renderbuffer to depth attachment point + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mRboId); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFboId); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } +#endif +} + SDL_Surface* OpenGL1Graphics::getScreenshot() { - int h = mTarget->h; - int w = mTarget->w; + const int h = mTarget->h; + const int w = mTarget->w - (mTarget->w % 4); GLint pack = 1; SDL_Surface *screenshot = SDL_CreateRGBSurface( @@ -502,6 +549,9 @@ SDL_Surface* OpenGL1Graphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); + if (!screenshot) + return nullptr; + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); @@ -528,6 +578,29 @@ SDL_Surface* OpenGL1Graphics::getScreenshot() free(buf); +#if !defined(_WIN32) + if (config.getBoolValue("usefbo")) + { + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + if (mFboId) + { + glDeleteFramebuffersEXT(1, &mFboId); + mFboId = 0; + } + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); + if (mRboId) + { + glDeleteRenderbuffersEXT(1, &mRboId); + mRboId = 0; + } + if (mTextureId) + { + glDeleteTextures(1, &mTextureId); + mTextureId = 0; + } + } +#endif + glPixelStorei(GL_PACK_ALIGNMENT, pack); if (SDL_MUSTLOCK(screenshot)) |