blender/source/gameengine/Rasterizer/RAS_IRenderTools.h

214 lines
4.0 KiB
C
Raw Normal View History

2002-10-12 11:37:38 +00:00
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*/
#ifndef __RAS_IRENDERTOOLS
#define __RAS_IRENDERTOOLS
#include "MT_Transform.h"
#include "RAS_IRasterizer.h"
2007-10-22 20:24:26 +00:00
#include "RAS_2DFilterManager.h"
2002-10-12 11:37:38 +00:00
#include <vector>
#include <algorithm>
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
2002-10-12 11:37:38 +00:00
class RAS_IPolyMaterial;
struct RAS_LightObject;
2007-10-22 20:24:26 +00:00
2002-10-12 11:37:38 +00:00
class RAS_IRenderTools
{
protected:
void* m_clientobject;
void* m_auxilaryClientInfo;
std::vector<struct RAS_LightObject*> m_lights;
2007-10-22 20:24:26 +00:00
RAS_2DFilterManager m_filtermanager;
2002-10-12 11:37:38 +00:00
public:
enum RAS_TEXT_RENDER_MODE {
RAS_TEXT_RENDER_NODEF = 0,
RAS_TEXT_NORMAL,
RAS_TEXT_PADDED,
RAS_TEXT_MAX
2002-10-12 11:37:38 +00:00
};
2007-10-22 20:24:26 +00:00
2002-10-12 11:37:38 +00:00
RAS_IRenderTools(
) :
m_clientobject(NULL)
2002-10-12 11:37:38 +00:00
{
};
virtual
~RAS_IRenderTools(
) {};
virtual
void
BeginFrame(
RAS_IRasterizer* rasty
)=0;
virtual
void
EndFrame(
RAS_IRasterizer* rasty
)=0;
// the following function was formerly called 'Render'
// by it doesn't render anymore
// It only sets the transform for the rasterizer
// so must be renamed to 'applyTransform' or something
virtual
void
applyTransform(
class RAS_IRasterizer* rasty,
double* oglmatrix,
int drawingmode
)=0;
Patch:[#25163] BGE support for Blender Font objects - unicode support Problem/Bug: ------------ There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :) You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/ Functionality Explanation: -------------------------- This patch converts the Blender Font Objects to a new BGE type: KX_FontObject This object inherits KX_GameObject.cpp and has the following properties: - text (the text of the object) - size (taken from the Blender object, usually is 1.0) - resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have) The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data. Known problems/limitations/ToDo: -------------------------------- 1) support for packed font and the <builtin> 2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF) 3) investigate some glitches I see some times 4) support for multiline 5) support for more Blender Font Object options (text aligment, text boxes, ...) [1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>. [2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic) [3] I think this may be related to the resolution we are drawing the font [4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF. So instead of: BLF_draw(fontid, (char *)text, strlen(text)); We would do: MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height); [5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem. Code Explanation: ----------------- The patch should be simple to read. They are three may parts: 1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts 2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine. 3) KX_FontObject.cpp:: a) constructor: load the font of the object, and store other values. b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools 4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API *) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added. Acknowledgements: ---------------- Thanks Benoit for the review and adjustment suggestions. Thanks Diego for the BFL expertise, patches and support (Latin community ftw) Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
/**
* Renders 3D text string using BFL.
* @param fontid The id of the font.
* @param text The string to render.
* @param size The size of the text.
* @param dpi The resolution of the text.
* @param color The color of the object.
* @param mat The Matrix of the text object.
* @param aspect A scaling factor to compensate for the size.
*/
virtual
void
RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect
) = 0;
2002-10-12 11:37:38 +00:00
/**
* Renders 2D text string.
* @param mode The type of text
* @param text The string to render.
* @param xco Position on the screen (origin in lower left corner).
* @param yco Position on the screen (origin in lower left corner).
* @param width Width of the canvas to draw to.
* @param height Height of the canvas to draw to.
*/
virtual
void
RenderText2D(
RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height
) = 0;
// 3d text, mapped on polygon
virtual
void
RenderText(
int mode,
RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib
2002-10-12 11:37:38 +00:00
)=0;
virtual
void
2002-10-12 11:37:38 +00:00
ProcessLighting(
RAS_IRasterizer *rasty,
bool uselights,
const MT_Transform& trans
2002-10-12 11:37:38 +00:00
)=0;
virtual
2002-10-12 11:37:38 +00:00
void
SetClientObject(
RAS_IRasterizer* rasty,
2002-10-12 11:37:38 +00:00
void* obj
);
void
SetAuxilaryClientInfo(
void* inf
);
virtual
void
PushMatrix(
)=0;
virtual
void
PopMatrix(
)=0;
virtual
void
AddLight(
struct RAS_LightObject* lightobject
);
virtual
void
RemoveLight(
struct RAS_LightObject* lightobject
);
virtual
void
MotionBlur(RAS_IRasterizer* rasterizer)=0;
#ifdef WITH_CXX_GUARDEDALLOC
public:
void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IRenderTools"); }
void operator delete( void *mem ) { MEM_freeN(mem); }
#endif
2002-10-12 11:37:38 +00:00
};
#endif //__RAS_IRENDERTOOLS
2007-10-22 20:24:26 +00:00