mirror of
https://github.com/edubart/otclient.git
synced 2025-10-21 23:05:54 +02:00
reorganize sources
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "animatedtexture.h"
|
||||
#include "graphics.h"
|
||||
#include <core/platform.h>
|
||||
#include <core/eventdispatcher.h>
|
||||
|
||||
#include <framework/platform/platform.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "texture.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
BorderImage::BorderImage(TexturePtr texture,
|
||||
const Rect& left,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef GRAPHICSDECLARATIONS_H
|
||||
#define GRAPHICSDECLARATIONS_H
|
||||
#ifndef FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||
#define FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
class Texture;
|
||||
class Font;
|
@@ -2,7 +2,7 @@
|
||||
#include "texturemanager.h"
|
||||
#include "graphics.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
void Font::load(const OTMLNodePtr& fontNode)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ void Font::load(const OTMLNodePtr& fontNode)
|
||||
// read custom widths
|
||||
if(OTMLNodePtr node = fontNode->get("glyph widths")) {
|
||||
for(const OTMLNodePtr& child : node->childNodes())
|
||||
m_glyphsSize[aux::safe_cast<int>(child->tag())].setWidth(child->read<int>());
|
||||
m_glyphsSize[fw::safe_cast<int>(child->tag())].setWidth(child->read<int>());
|
||||
}
|
||||
|
||||
// calculate glyphs texture coords
|
||||
@@ -130,8 +130,6 @@ void Font::renderText(const std::string& text,
|
||||
}
|
||||
|
||||
g_graphics.stopDrawing();
|
||||
|
||||
g_graphics.bindColor(Color::white);
|
||||
}
|
||||
|
||||
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include "graphicsdeclarations.h"
|
||||
#include <otml/otmldeclarations.h>
|
||||
#include "declarations.h"
|
||||
|
||||
#include <framework/otml/declarations.h>
|
||||
|
||||
class Font
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "fontmanager.h"
|
||||
|
||||
#include <core/resourcemanager.h>
|
||||
#include <otml/otml.h>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
FontManager g_fonts;
|
||||
|
||||
@@ -64,6 +64,6 @@ FontPtr FontManager::getDefaultFont()
|
||||
{
|
||||
// default font should always exists, otherwise the app may crash
|
||||
if(!m_defaultFont)
|
||||
throw std::runtime_error("no default font to display, cannot continue to run");
|
||||
logFatal("FATAL ERROR: no default font to display, cannot continue to run");
|
||||
return m_defaultFont;
|
||||
}
|
||||
|
@@ -6,9 +6,10 @@
|
||||
class FontManager
|
||||
{
|
||||
public:
|
||||
// Release fonts references, thus making possible to destruct them
|
||||
/// Release fonts references, thus making possible to destruct them
|
||||
void releaseFonts();
|
||||
|
||||
/// Import a font from .otfont file
|
||||
bool importFont(std::string fontFile);
|
||||
|
||||
bool fontExists(const std::string& fontName);
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#include "framebuffer.h"
|
||||
#include "graphics.h"
|
||||
#include <core/platform.h>
|
||||
#include "texture.h"
|
||||
|
||||
#include <framework/platform/platform.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
@@ -14,22 +17,13 @@ PFNGLCHECKFRAMEBUFFERSTATUSPROC oglCheckFramebufferStatus = 0;
|
||||
FrameBuffer::FrameBuffer(int width, int height)
|
||||
{
|
||||
m_fbo = 0;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
// create FBO texture
|
||||
glGenTextures(1, &m_fboTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// we want bilinear filtering (for a smooth framebuffer)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
m_texture = TexturePtr(new Texture(width, height, 4));
|
||||
m_texture->enableBilinearFilter();
|
||||
|
||||
// use FBO ext only if supported
|
||||
if(g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
|
||||
if(false && g_graphics.isExtensionSupported("GL_ARB_framebuffer_object")) {
|
||||
m_fallbackOldImp = false;
|
||||
if(!oglGenFramebuffers) {
|
||||
oglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)g_platform.getExtensionProcAddress("glGenFramebuffers");
|
||||
@@ -44,7 +38,7 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
|
||||
|
||||
// attach 2D texture to this FBO
|
||||
oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_fboTexture, 0);
|
||||
oglFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture->getId(), 0);
|
||||
|
||||
GLenum status = oglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
|
||||
switch(status) {
|
||||
@@ -58,6 +52,8 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||
|
||||
// restore back buffer
|
||||
oglBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||
glDrawBuffer(GL_BACK);
|
||||
glReadBuffer(GL_BACK);
|
||||
} else {
|
||||
// otherwise fallback to copy texture from screen implementation
|
||||
m_fallbackOldImp = true;
|
||||
@@ -66,7 +62,6 @@ FrameBuffer::FrameBuffer(int width, int height)
|
||||
|
||||
FrameBuffer::~FrameBuffer()
|
||||
{
|
||||
glDeleteTextures(1, &m_fboTexture);
|
||||
if(m_fbo)
|
||||
oglDeleteFramebuffers(1, &m_fbo);
|
||||
}
|
||||
@@ -79,10 +74,10 @@ void FrameBuffer::bind()
|
||||
}
|
||||
|
||||
// setup framebuffer viewport
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glViewport(0, 0, m_texture->getWidth(), m_texture->getHeight());
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0.0f, m_width, 0, m_height);
|
||||
gluOrtho2D(0.0f, m_texture->getWidth(), 0, m_texture->getHeight());
|
||||
|
||||
// back to model view
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -105,8 +100,8 @@ void FrameBuffer::unbind()
|
||||
g_graphics.restoreViewport();
|
||||
} else {
|
||||
// copy screen to texture
|
||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture->getId());
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_texture->getWidth(), m_texture->getHeight());
|
||||
|
||||
// restore graphics viewport
|
||||
g_graphics.restoreViewport();
|
||||
@@ -117,14 +112,7 @@ void FrameBuffer::unbind()
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBuffer::draw(int x, int y, int width, int height)
|
||||
void FrameBuffer::draw(const Rect& screenCoords, const Rect& framebufferCoords)
|
||||
{
|
||||
glColor4ubv(Color::white.rgbaPtr());
|
||||
glBindTexture(GL_TEXTURE_2D, m_fboTexture);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2i(0, 0); glVertex2i(x, y);
|
||||
glTexCoord2i(0, 1); glVertex2i(x, y+height);
|
||||
glTexCoord2i(1, 1); glVertex2i(x+width, y+height);
|
||||
glTexCoord2i(1, 0); glVertex2i(x+width, y);
|
||||
glEnd();
|
||||
g_graphics.drawTexturedRect(screenCoords, m_texture ,framebufferCoords);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef FRAMEBUFFER_H
|
||||
#define FRAMEBUFFER_H
|
||||
|
||||
#include "graphicsdeclarations.h"
|
||||
#include "declarations.h"
|
||||
|
||||
class FrameBuffer
|
||||
{
|
||||
@@ -9,21 +9,21 @@ public:
|
||||
FrameBuffer(int width, int height);
|
||||
virtual ~FrameBuffer();
|
||||
|
||||
/// Bind the framebuffer, everything rendered will be draw on it
|
||||
/// Binds the framebuffer, by switching render buffer to itself, everything rendered will be draw on it
|
||||
void bind();
|
||||
|
||||
/// Unbind the framebuffer, render on back buffer again
|
||||
/// Unbinds the framebuffer (switch render buffer to back buffer again)
|
||||
void unbind();
|
||||
|
||||
/// Draw framebuffer
|
||||
void draw(int x, int y, int width, int height);
|
||||
/// Draws framebuffer texture
|
||||
void draw(const Rect& screenCoords, const Rect& framebufferCoords = Rect());
|
||||
|
||||
TexturePtr getTexture() { return m_texture; }
|
||||
|
||||
private:
|
||||
uint m_fboTexture;
|
||||
TexturePtr m_texture;
|
||||
uint m_fbo;
|
||||
bool m_fallbackOldImp;
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include <graphics/graphics.h>
|
||||
#include <graphics/texture.h>
|
||||
#include "fontmanager.h"
|
||||
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/graphics/texture.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
@@ -109,7 +110,7 @@ void Graphics::drawTexturedRect(const Rect& screenCoords,
|
||||
const TexturePtr& texture,
|
||||
const Rect& textureCoords)
|
||||
{
|
||||
if(screenCoords.isEmpty() || textureCoords.isEmpty())
|
||||
if(screenCoords.isEmpty())
|
||||
return;
|
||||
|
||||
// rect correction for opengl
|
||||
@@ -119,12 +120,17 @@ void Graphics::drawTexturedRect(const Rect& screenCoords,
|
||||
int left = screenCoords.left();
|
||||
const Size& textureSize = texture->getGlSize();
|
||||
|
||||
float textureRight = 0.0f;
|
||||
float textureBottom = 1.0f;
|
||||
float textureTop = 0.0f;
|
||||
float textureLeft = 1.0f;
|
||||
float textureRight;
|
||||
float textureBottom;
|
||||
float textureTop;
|
||||
float textureLeft;
|
||||
|
||||
if(!textureCoords.isEmpty()) {
|
||||
if(textureCoords.isEmpty()) {
|
||||
textureRight = 1.0f;
|
||||
textureBottom = 1.0f;
|
||||
textureTop = 0.0f;
|
||||
textureLeft = 0.0f;
|
||||
} else {
|
||||
textureRight = (float)(textureCoords.right() + 1) / textureSize.width();
|
||||
textureBottom = (float)(textureCoords.bottom() + 1) / textureSize.height();
|
||||
textureTop = (float)textureCoords.top() / textureSize.height();
|
||||
@@ -222,7 +228,7 @@ void Graphics::drawBoundingRect(const Rect& screenCoords,
|
||||
{
|
||||
assert(!m_drawing);
|
||||
|
||||
if(2 * innerLineWidth > screenCoords.height() || screenCoords.isEmpty())
|
||||
if(screenCoords.isEmpty() || 2 * innerLineWidth > screenCoords.height())
|
||||
return;
|
||||
|
||||
// rect correction for opengl
|
||||
@@ -274,7 +280,7 @@ void Graphics::bindColor(const Color& color)
|
||||
|
||||
void Graphics::bindTexture(const TexturePtr& texture)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getId());
|
||||
}
|
||||
|
||||
void Graphics::startDrawing()
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef GRAPHICS_H
|
||||
#define GRAPHICS_H
|
||||
|
||||
#include "graphicsdeclarations.h"
|
||||
#include "declarations.h"
|
||||
|
||||
class Graphics
|
||||
{
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "graphics.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
Image::Image(TexturePtr texture, Rect textureCoords)
|
||||
{
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#ifndef IMAGE_H
|
||||
#define IMAGE_H
|
||||
|
||||
#include "graphicsdeclarations.h"
|
||||
#include <otml/otmldeclarations.h>
|
||||
#include "declarations.h"
|
||||
|
||||
#include <framework/otml/declarations.h>
|
||||
|
||||
class Image
|
||||
{
|
||||
|
@@ -11,7 +11,9 @@ Texture::Texture(int width, int height, int channels, uchar *pixels)
|
||||
|
||||
uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int height)
|
||||
{
|
||||
// get smax texture size supported by the driver
|
||||
m_size.setSize(width, height);
|
||||
|
||||
// gets max texture size supported by the driver
|
||||
static GLint maxTexSize = -1;
|
||||
if(maxTexSize == -1)
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
||||
@@ -28,7 +30,6 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||
GLuint id;
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
m_size.setSize(width, height);
|
||||
bool mustFree = false;
|
||||
|
||||
// old opengl drivers only accept power of two dimensions
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include "graphicsdeclarations.h"
|
||||
#include "declarations.h"
|
||||
|
||||
class Texture : public std::enable_shared_from_this<Texture>
|
||||
{
|
||||
@@ -14,12 +14,14 @@ public:
|
||||
virtual void enableBilinearFilter();
|
||||
|
||||
/// Get OpenGL texture id
|
||||
virtual uint getTextureId() const { return m_textureId; }
|
||||
virtual uint getId() const { return m_textureId; }
|
||||
|
||||
/// Copy pixels from OpenGL texture
|
||||
uchar* getPixels();
|
||||
|
||||
const Size& getSize() const { return m_size; }
|
||||
int getWidth() const { return m_size.width(); }
|
||||
int getHeight() const { return m_size.height(); }
|
||||
const Size getSize() const { return m_size; }
|
||||
const Size& getGlSize() const { return m_glSize; }
|
||||
|
||||
protected:
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include "texturemanager.h"
|
||||
#include "animatedtexture.h"
|
||||
#include <core/resourcemanager.h>
|
||||
#include <thirdparty/apngloader.h>
|
||||
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <framework/thirdparty/apngloader.h>
|
||||
|
||||
TextureManager g_textures;
|
||||
|
||||
|
Reference in New Issue
Block a user