framebuffer

This commit is contained in:
Eduardo Bart 2011-08-11 22:38:54 -03:00
parent 651315d4cd
commit 1a81d1520f
4 changed files with 25 additions and 1 deletions

View File

@ -34,6 +34,8 @@ PFNGLCHECKFRAMEBUFFERSTATUSPROC oglCheckFramebufferStatus = 0;
FrameBuffer::FrameBuffer(int width, int height)
{
g_graphics.disableDrawing();
m_fbo = 0;
m_width = width;
m_height = height;
@ -50,7 +52,7 @@ FrameBuffer::FrameBuffer(int width, int height)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// use FBO ext only if supported
if(g_graphics.isExtensionSupported("ARB_framebuffer_object")) {
if(g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
m_fallbackOldImp = false;
if(!oglGenFramebuffers) {
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)Platform::getExtensionProcAddress("glGenFramebuffers");
@ -84,6 +86,8 @@ FrameBuffer::FrameBuffer(int width, int height)
FrameBuffer::~FrameBuffer()
{
g_graphics.disableDrawing();
glDeleteTextures(1, &m_fboTexture);
if(m_fbo)
oglDeleteFramebuffers(1, &m_fbo);
@ -91,6 +95,8 @@ FrameBuffer::~FrameBuffer()
void FrameBuffer::bind()
{
g_graphics.disableDrawing();
if(!m_fallbackOldImp) {
// bind framebuffer
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
@ -113,6 +119,8 @@ void FrameBuffer::bind()
void FrameBuffer::unbind()
{
g_graphics.disableDrawing();
if(!m_fallbackOldImp) {
// bind back buffer again
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
@ -137,6 +145,8 @@ void FrameBuffer::unbind()
void FrameBuffer::draw(int x, int y, int width, int height)
{
g_graphics.disableDrawing();
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(x, y);

View File

@ -27,6 +27,9 @@
#include <global.h>
class FrameBuffer;
typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
class FrameBuffer
{
public:

View File

@ -3,6 +3,11 @@
void Map::draw(int x, int y, int width, int heigth)
{
if(!m_framebuffer)
m_framebuffer = FrameBufferPtr(new FrameBuffer(19*32, 15*32));
m_framebuffer->bind();
Position playerPos = g_game.getPlayer()->getPosition();
for(int ix = 0; ix < 19; ++ix) {
for(int iy = 0; iy < 15; ++iy) {
@ -13,6 +18,9 @@ void Map::draw(int x, int y, int width, int heigth)
}
}
}
m_framebuffer->unbind();
m_framebuffer->draw(0, 0, width, heigth);
}
void Map::addThing(Thing *thing, const Position& pos)

View File

@ -3,6 +3,7 @@
#include "position.h"
#include "tile.h"
#include <graphics/framebuffer.h>
class Map
{
@ -14,6 +15,8 @@ public:
private:
// Visible tiles are 15x11, but we have a +3 value. We have 15 floors.
Tile m_map[19][15][15];
FrameBufferPtr m_framebuffer;
};
#endif // MAP_H