Родитель
f10ced4626
Сommit
4b2886ebec
@ -0,0 +1,120 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include "framebuffer.h"
|
||||
|
||||
#include <GL/glext.h>
|
||||
#include <GL/glu.h>
|
||||
#include "platform.h"
|
||||
#include "graphics.h"
|
||||
|
||||
FrameBuffer::FrameBuffer(int width, int height) :
|
||||
m_fbo(0)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
// texture where the framebuffer will be store
|
||||
m_frameTexture = TexturePtr(new Texture(width, height, 4));
|
||||
|
||||
// we want a smooth framebuffer
|
||||
m_frameTexture->enableBilinearFilter();
|
||||
|
||||
// use FBO only if supported
|
||||
if(Platform::isExtensionSupported("EXT_framebuffer_object")) {
|
||||
m_fallbackOldImp = false;
|
||||
|
||||
// generate FBO
|
||||
glGenFramebuffersEXT(1, &m_fbo);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||
|
||||
// attach 2D texture to this FBO
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_frameTexture->getTextureId(), 0);
|
||||
|
||||
// must be called before checking
|
||||
glDrawBuffer(GL_NONE);
|
||||
glReadBuffer(GL_NONE);
|
||||
|
||||
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||
switch(status) {
|
||||
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
||||
//ok
|
||||
break;
|
||||
default:
|
||||
m_fallbackOldImp = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// otherwise fallback to copy texture from screen implementation
|
||||
m_fallbackOldImp = true;
|
||||
}
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer()
|
||||
{
|
||||
if(m_fbo)
|
||||
glDeleteFramebuffersEXT(1, &m_fbo);
|
||||
}
|
||||
|
||||
void FrameBuffer::bind()
|
||||
{
|
||||
if(!m_fallbackOldImp) {
|
||||
// bind framebuffer
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||
|
||||
// must be called before rendering to framebuffer
|
||||
glDrawBuffer(GL_NONE);
|
||||
glReadBuffer(GL_NONE);
|
||||
}
|
||||
|
||||
// clear framebuffer
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// setup framebuffer viewport
|
||||
g_graphics.setViewport(m_width, m_height);
|
||||
}
|
||||
|
||||
void FrameBuffer::unbind()
|
||||
{
|
||||
if(!m_fallbackOldImp) {
|
||||
// bind back buffer again
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
// must be called to render to back buffer again
|
||||
glDrawBuffer(GL_BACK);
|
||||
glReadBuffer(GL_BACK);
|
||||
} else {
|
||||
// copy screen to texture
|
||||
m_frameTexture->copyFromScreen(0, 0, 0, 0, m_width, m_height);
|
||||
|
||||
// clear screen
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
// restore graphics viewport
|
||||
g_graphics.restoreViewport();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FRAMEBUFFER_H
|
||||
#define FRAMEBUFFER_H
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
class FrameBuffer
|
||||
{
|
||||
FrameBuffer(int width, int height);
|
||||
virtual ~FrameBuffer();
|
||||
|
||||
/// Return the texture where everything was drawn
|
||||
TexturePtr getFramebufferTexture();
|
||||
|
||||
/// Bind the framebuffer, everything rendered will be draw on it
|
||||
void bind();
|
||||
|
||||
/// Unbind the framebuffer, render on back buffer again
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
TexturePtr m_frameTexture;
|
||||
GLuint m_fbo;
|
||||
bool m_fallbackOldImp;
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
|
||||
#endif // FRAMEBUFFER_H
|
@ -0,0 +1,46 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
struct InputEvent;
|
||||
|
||||
class GameState
|
||||
{
|
||||
public:
|
||||
GameState() { }
|
||||
virtual ~GameState() { }
|
||||
|
||||
virtual void onEnter() = 0;
|
||||
virtual void onLeave() = 0;
|
||||
|
||||
virtual void onClose() = 0;
|
||||
virtual void onInputEvent(InputEvent *event) = 0;
|
||||
|
||||
virtual void render() = 0;
|
||||
virtual void update(int elapsedTicks) = 0;
|
||||
};
|
||||
|
||||
#endif // GAMESTATE_H
|
@ -0,0 +1,67 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "menustate.h"
|
||||
#include "framebuffer.h"
|
||||
#include "graphics.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
MenuState::MenuState()
|
||||
{
|
||||
}
|
||||
|
||||
MenuState::~MenuState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::onEnter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::onLeave()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::onClose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::onInputEvent(InputEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::render()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MenuState::update(int elapsedTicks)
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MENUSTATE_H
|
||||
#define MENUSTATE_H
|
||||
|
||||
#include "gamestate.h"
|
||||
|
||||
class MenuState : public GameState
|
||||
{
|
||||
|
||||
public:
|
||||
MenuState();
|
||||
virtual ~MenuState();
|
||||
|
||||
void onEnter();
|
||||
void onLeave();
|
||||
|
||||
void onClose();
|
||||
void onInputEvent(InputEvent *event);
|
||||
|
||||
void render();
|
||||
void update(int elapsedTicks);
|
||||
};
|
||||
|
||||
#endif // MENUSTATE_H
|
Загрузка…
Ссылка в новой задаче