Skip to content

Commit

Permalink
Refactor|Fonts|Resources|Client: Continued updating bitmap implementa…
Browse files Browse the repository at this point in the history
…tion to use libdeng2 components
  • Loading branch information
danij-deng committed Nov 13, 2013
1 parent 4043e83 commit d95b821
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 239 deletions.
5 changes: 3 additions & 2 deletions doomsday/client/include/gl/gl_draw.h
Expand Up @@ -25,6 +25,7 @@
#ifndef LIBDENG_GRAPHICS_DRAW_H
#define LIBDENG_GRAPHICS_DRAW_H

#include <de/Vector>
#include <de/rect.h>

#ifdef __cplusplus
Expand All @@ -33,10 +34,10 @@ extern "C" {

void GL_DrawLine(float x1, float y1, float x2, float y2, float r, float g, float b, float a);

void GL_DrawRect(const RectRaw* rect);
void GL_DrawRect(RectRaw const *rect);
void GL_DrawRect2(int x, int y, int w, int h);

void GL_DrawRectWithCoords(const RectRaw* rect, Point2Raw coords[4]);
void GL_DrawRectWithCoords(RectRaw const *rect, de::Vector2i coords[4]);

void GL_DrawRectf(const RectRawf* rect);
void GL_DrawRectf2(double x, double y, double w, double h);
Expand Down
21 changes: 11 additions & 10 deletions doomsday/client/include/resource/abstractfont.h
Expand Up @@ -20,8 +20,11 @@
#ifndef CLIENT_RESOURCE_ABSTRACTFONT_H
#define CLIENT_RESOURCE_ABSTRACTFONT_H

#include "dd_types.h"
#include "def_main.h"
#include "dd_types.h" // fontid_t
#include <de/Rectangle>
#include <de/Vector>

#define MAX_CHARS 256 // Normal 256 ANSI characters.

/**
* @defgroup fontFlags Font Flags
Expand All @@ -32,8 +35,6 @@
#define FF_SHADOWED 0x2 /// Font has an embedded shadow.
/*@}*/

#define MAX_CHARS 256 // Normal 256 ANSI characters.

/**
* Abstract font resource.
*
Expand All @@ -53,11 +54,11 @@ class AbstractFont
int _ascent;
int _descent;

Size2Raw _noCharSize;
de::Vector2ui _noCharSize;

/// Do fonts have margins? Is this a pixel border in the composited character
/// map texture (perhaps per-glyph)?
int _marginWidth, _marginHeight;
de::Vector2ui _margin;

AbstractFont(fontid_t bindId = 0);
virtual ~AbstractFont() {}
Expand All @@ -78,11 +79,11 @@ class AbstractFont
virtual void glInit();
virtual void glDeinit();

virtual RectRaw const *charGeometry(unsigned char ch) = 0;
virtual int charWidth(unsigned char ch) = 0;
virtual int charHeight(unsigned char ch) = 0;
virtual de::Rectanglei const &charGeometry(uchar ch) = 0;
virtual int charWidth(uchar ch) = 0;
virtual int charHeight(uchar ch) = 0;

void charSize(Size2Raw *size, unsigned char ch);
de::Vector2i charSize(uchar ch);
};

#endif // CLIENT_RESOURCE_ABSTRACTFONT_H
21 changes: 9 additions & 12 deletions doomsday/client/include/resource/bitmapfont.h
Expand Up @@ -22,10 +22,9 @@

#include "abstractfont.h"
#include "Texture"
#include <de/point.h>
#include <de/rect.h>
#include <de/size.h>
#include <de/str.h>
#include "gl/gl_main.h"
#include <de/Rectangle>
#include <de/Vector>

/**
* Bitmap font.
Expand All @@ -38,8 +37,8 @@ class BitmapFont : public AbstractFont
// Data for a character.
struct bitmapfont_char_t
{
RectRaw geometry;
Point2Raw coords[4];
de::Rectanglei geometry;
de::Vector2i coords[4];
};

public:
Expand All @@ -51,17 +50,15 @@ class BitmapFont : public AbstractFont
void setFilePath(char const *filePath);

/// @return GL-texture name.
DGLuint textureGLName() const;
Size2Raw const *textureSize() const;
int textureHeight() const;
int textureWidth() const;
GLuint textureGLName() const;
de::Vector2i const &textureDimensions() const;

void charCoords(unsigned char ch, Point2Raw coords[4]);
void charCoords(unsigned char ch, de::Vector2i coords[4]);

void glInit();
void glDeinit();

RectRaw const *charGeometry(unsigned char ch);
de::Rectanglei const &charGeometry(unsigned char ch);
int charWidth(unsigned char ch);
int charHeight(unsigned char ch);

Expand Down
29 changes: 14 additions & 15 deletions doomsday/client/include/resource/compositebitmapfont.h
Expand Up @@ -21,11 +21,10 @@
#define CLIENT_RESOURCE_COMPOSITEBITMAPFONT_H

#include "abstractfont.h"
#include "def_main.h"
#include "Texture"
#include <de/point.h>
#include <de/rect.h>
#include <de/size.h>
#include <de/str.h>
#include <de/Rectangle>
#include <de/Vector>

/**
* Composite bitmap font.
Expand All @@ -38,7 +37,7 @@ class CompositeBitmapFont : public AbstractFont
// Data for a character.
struct bitmapcompositefont_char_t
{
RectRaw geometry;
de::Rectanglei geometry;
patchid_t patch;
de::Texture::Variant *tex;
uint8_t border;
Expand All @@ -49,8 +48,8 @@ class CompositeBitmapFont : public AbstractFont

static CompositeBitmapFont *fromDef(fontid_t bindId, ded_compositefont_t *def);

struct ded_compositefont_s *definition() const;
void setDefinition(struct ded_compositefont_s *def);
ded_compositefont_t *definition() const;
void setDefinition(ded_compositefont_t *newDef);

/**
* Update the font according to the supplied definition. To be called after
Expand All @@ -62,21 +61,21 @@ class CompositeBitmapFont : public AbstractFont
*/
void rebuildFromDef(ded_compositefont_t *def);

patchid_t charPatch(unsigned char ch);
void charSetPatch(unsigned char ch, char const *encodedPatchName);
patchid_t charPatch(uchar ch);
void charSetPatch(uchar ch, char const *encodedPatchName);

de::Texture::Variant *charTexture(unsigned char ch);
de::Texture::Variant *charTexture(uchar ch);

uint8_t charBorder(unsigned char chr);
uint8_t charBorder(uchar chr);

void charCoords(unsigned char chr, Point2Raw coords[4]);
void charCoords(uchar chr, de::Vector2i coords[4]);

void glInit();
void glDeinit();

RectRaw const *charGeometry(unsigned char ch);
int charWidth(unsigned char ch);
int charHeight(unsigned char ch);
de::Rectanglei const &charGeometry(uchar ch);
int charWidth(uchar ch);
int charHeight(uchar ch);

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/src/con_main.cpp
Expand Up @@ -53,8 +53,6 @@
#include "de_defs.h"
#include "de_filesys.h"

#include "resource/fonts.h"
//#include "cbuffer.h"
#include "Game"
#include <de/LogBuffer>

Expand Down
16 changes: 9 additions & 7 deletions doomsday/client/src/gl/gl_draw.cpp
Expand Up @@ -33,12 +33,14 @@
#include "gl/sys_opengl.h"
#include "api_render.h"

#include "gl/gl_draw.h"

using namespace de;

static bool drawFilter = false;
static Vector4f filterColor;

void GL_DrawRectWithCoords(const RectRaw* rect, Point2Raw coords[4])
void GL_DrawRectWithCoords(RectRaw const *rect, Vector2i coords[4])
{
if(!rect) return;

Expand All @@ -47,26 +49,26 @@ void GL_DrawRectWithCoords(const RectRaw* rect, Point2Raw coords[4])

glBegin(GL_QUADS);
// Upper left.
if(coords) glTexCoord2iv((GLint*)coords[0].xy);
if(coords) glTexCoord2i(coords[0].x, coords[0].y);
glVertex2f(rect->origin.x, rect->origin.y);

// Upper Right.
if(coords) glTexCoord2iv((GLint*)coords[1].xy);
if(coords) glTexCoord2i(coords[1].x, coords[1].y);
glVertex2f(rect->origin.x + rect->size.width, rect->origin.y);

// Lower right.
if(coords) glTexCoord2iv((GLint*)coords[2].xy);
if(coords) glTexCoord2i(coords[2].x, coords[2].y);
glVertex2f(rect->origin.x + rect->size.width, rect->origin.y + rect->size.height);

// Lower left.
if(coords) glTexCoord2iv((GLint*)coords[3].xy);
if(coords) glTexCoord2i(coords[3].x, coords[3].y);
glVertex2f(rect->origin.x, rect->origin.y + rect->size.height);
glEnd();
}

void GL_DrawRect(const RectRaw* rect)
void GL_DrawRect(RectRaw const *rect)
{
Point2Raw coords[4];
Vector2i coords[4];
coords[0].x = 0;
coords[0].y = 0;
coords[1].x = 1;
Expand Down
41 changes: 20 additions & 21 deletions doomsday/client/src/render/rend_font.cpp
@@ -1,4 +1,4 @@
/** @file rend_font.cpp
/** @file rend_font.cpp Font Renderer.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,10 +17,6 @@
* http://www.gnu.org/licenses</small>
*/

/**
* Font Renderer.
*/

#include <assert.h>
#include <ctype.h>
#include <stdio.h>
Expand Down Expand Up @@ -100,10 +96,7 @@ typedef struct {
} caseMod[2]; // 1=upper, 0=lower
} drawtextstate_t;

static __inline fr_state_attributes_t* currentAttribs(void);
static int topToAscent(AbstractFont* font);
static int lineHeight(AbstractFont* font, unsigned char ch);
static void drawChar(unsigned char ch, int posX, int posY, AbstractFont* font, int alignFlags, short textFlags);
static void drawChar(unsigned char ch, int posX, int posY, AbstractFont *font, int alignFlags, short textFlags);
static void drawFlash(Point2Raw const *origin, Size2Raw const *size, bool bright);

static int inited = false;
Expand Down Expand Up @@ -426,10 +419,15 @@ void FR_SetCaseScale(boolean value)
}

#undef FR_CharSize
void FR_CharSize(Size2Raw* size, unsigned char ch)
void FR_CharSize(Size2Raw *size, unsigned char ch)
{
errorIfNotInited("FR_CharSize");
App_Fonts().toFont(fr.fontNum)->charSize(size, ch);
if(size)
{
Vector2i dimensions = App_Fonts().toFont(fr.fontNum)->charSize(ch);
size->width = dimensions.x;
size->height = dimensions.y;
}
}

#undef FR_CharWidth
Expand Down Expand Up @@ -591,7 +589,8 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glScalef(1.f / bmapFont->textureWidth(), 1.f / bmapFont->textureHeight(), 1.f);
glScalef(1.f / bmapFont->textureDimensions().x,
1.f / bmapFont->textureDimensions().y, 1.f);
}
}

Expand All @@ -607,10 +606,10 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
c = *ch++;
yoff = 0;

glitter = (noGlitter? 0 : sat->glitterStrength);
glitter = (noGlitter? 0 : sat->glitterStrength);
glitterMul = 0;

shadow = (noShadow? 0 : sat->shadowStrength);
shadow = (noShadow? 0 : sat->shadowStrength);
shadowMul = (noShadow? 0 : sat->rgba[CA]);

// Do the type-in effect?
Expand Down Expand Up @@ -755,7 +754,7 @@ static void drawChar(unsigned char ch, int posX, int posY, AbstractFont *font,
int alignFlags, short /*textFlags*/)
{
float x = (float) posX, y = (float) posY;
Point2Raw coords[4];
Vector2i coords[4];
RectRaw geometry;

if(alignFlags & ALIGN_RIGHT)
Expand Down Expand Up @@ -811,15 +810,15 @@ static void drawChar(unsigned char ch, int posX, int posY, AbstractFont *font,
DENG2_ASSERT(false);
}

if(font->_marginWidth)
if(font->_margin.x)
{
geometry.origin.x -= font->_marginWidth;
geometry.size.width += font->_marginWidth*2;
geometry.origin.x -= font->_margin.x;
geometry.size.width += font->_margin.x * 2;
}
if(font->_marginHeight)
if(font->_margin.y)
{
geometry.origin.y -= font->_marginHeight;
geometry.size.height += font->_marginHeight*2;
geometry.origin.y -= font->_margin.y;
geometry.size.height += font->_margin.y * 2;
}

GL_DrawRectWithCoords(&geometry, coords);
Expand Down
22 changes: 8 additions & 14 deletions doomsday/client/src/resource/abstractfont.cpp
Expand Up @@ -23,28 +23,22 @@
using namespace de;

AbstractFont::AbstractFont(fontid_t bindId)
{
_marginWidth = 0;
_marginHeight = 0;
_leading = 0;
_ascent = 0;
_descent = 0;
_noCharSize.width = 0;
_noCharSize.height = 0;
_primaryBind = bindId;
}
: _flags(0)
, _primaryBind(bindId)
, _leading(0)
, _ascent(0)
, _descent(0)
{}

void AbstractFont::glInit()
{}

void AbstractFont::glDeinit()
{}

void AbstractFont::charSize(Size2Raw *size, unsigned char ch)
Vector2i AbstractFont::charSize(unsigned char ch)
{
if(!size) return;
size->width = charWidth(ch);
size->height = charHeight(ch);
return Vector2i(charWidth(ch), charHeight(ch));
}

fontid_t AbstractFont::primaryBind() const
Expand Down

0 comments on commit d95b821

Please sign in to comment.