Fix warnings, layout, and return value.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3871 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2011-07-01 22:57:55 +00:00
parent 009a6bfc92
commit 8cb3aebfd0
3 changed files with 264 additions and 255 deletions

View File

@ -9,23 +9,23 @@ namespace
// based on code and media from SuperTuxKart
class ScalableFont : public gui::IGUIFontBitmap
{
float m_scale;
struct TextureInfo
{
irr::core::stringc m_file_name;
bool m_has_alpha;
float m_scale;
TextureInfo()
{
m_has_alpha = false;
m_scale = 1.0f;
}
};
std::map<int /* texture file ID */, TextureInfo> m_texture_files;
void lazyLoadTexture(int texID)
float m_scale;
struct TextureInfo
{
irr::core::stringc m_file_name;
bool m_has_alpha;
float m_scale;
TextureInfo()
{
m_has_alpha = false;
m_scale = 1.0f;
}
};
std::map<int /* texture file ID */, TextureInfo> m_texture_files;
void lazyLoadTexture(int texID)
{
const bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
@ -33,7 +33,7 @@ class ScalableFont : public gui::IGUIFontBitmap
SpriteBank->setTexture(texID, Driver->getTexture( m_texture_files[texID].m_file_name ));
// set previous mip-map+filter state
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap);
// couldn't load texture, abort.
if (!SpriteBank->getTexture(texID))
{
@ -48,7 +48,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
}
}
void doReadXmlFile(io::IXMLReader* xml)
void doReadXmlFile(io::IXMLReader* xml)
{
while (xml->read())
{
@ -70,29 +70,29 @@ class ScalableFont : public gui::IGUIFontBitmap
core::stringc filename = xml->getAttributeValue(L"filename");
core::stringc fn = filename;
u32 i = (u32)xml->getAttributeValueAsInt(L"index");
float scale=1.0f;
if(xml->getAttributeValue(L"scale"))
if (xml->getAttributeValue(L"scale"))
scale = xml->getAttributeValueAsFloat(L"scale");
//std::cout << "scale = " << scale << std::endl;
core::stringw alpha = xml->getAttributeValue(L"hasAlpha");
//std::cout << "---- Adding font texture " << fn.c_str() << "; alpha=" << alpha.c_str() << std::endl;
// make sure the sprite bank has enough textures in it
while (i+1 > SpriteBank->getTextureCount())
{
SpriteBank->addTexture(NULL);
}
TextureInfo info;
info.m_file_name = fn;
info.m_has_alpha = (alpha == core::stringw("true"));
info.m_scale = scale;
m_texture_files[i] = info;
info.m_scale = scale;
m_texture_files[i] = info;
}
else if (core::stringw(L"c") == xml->getNodeName())
{
@ -101,16 +101,16 @@ class ScalableFont : public gui::IGUIFontBitmap
gui::SGUISpriteFrame f;
gui::SGUISprite s;
core::rect<s32> rectangle;
a.underhang = xml->getAttributeValueAsInt(L"u");
a.overhang = xml->getAttributeValueAsInt(L"o");
a.spriteno = SpriteBank->getSprites().size();
s32 texno = xml->getAttributeValueAsInt(L"i");
a.underhang = xml->getAttributeValueAsInt(L"u");
a.overhang = xml->getAttributeValueAsInt(L"o");
a.spriteno = SpriteBank->getSprites().size();
s32 texno = xml->getAttributeValueAsInt(L"i");
// parse rectangle
core::stringc rectstr = xml->getAttributeValue(L"r");
wchar_t ch = xml->getAttributeValue(L"c")[0];
wchar_t ch = xml->getAttributeValue(L"c")[0];
const c8 *c = rectstr.c_str();
s32 val;
val = 0;
@ -122,7 +122,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.UpperLeftCorner.X = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
@ -132,7 +132,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.UpperLeftCorner.Y = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
@ -142,7 +142,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.LowerRightCorner.X = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
@ -151,24 +151,24 @@ class ScalableFont : public gui::IGUIFontBitmap
c++;
}
rectangle.LowerRightCorner.Y = val;
CharacterMap[ch] = Areas.size();
// make frame
f.rectNumber = SpriteBank->getPositions().size();
f.textureNumber = texno;
// add frame to sprite
s.Frames.push_back(f);
s.frameTime = 0;
// add rectangle to sprite bank
SpriteBank->getPositions().push_back(rectangle);
a.width = rectangle.getWidth();
// add sprite to sprite bank
SpriteBank->getSprites().push_back(s);
// add character to font
Areas.push_back(a);
}
@ -178,13 +178,13 @@ class ScalableFont : public gui::IGUIFontBitmap
public:
bool m_black_border;
ScalableFont* m_fallback_font;
float m_fallback_font_scale;
int m_fallback_kerning_width;
//! constructor
bool m_black_border;
ScalableFont* m_fallback_font;
float m_fallback_font_scale;
int m_fallback_kerning_width;
//! constructor
ScalableFont(gui::IGUIEnvironment *env, const io::path& filename)
: Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0),
MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0)
@ -192,12 +192,12 @@ public:
#ifdef _DEBUG
setDebugName("ScalableFont");
#endif
m_fallback_font = NULL;
m_fallback_font = NULL;
m_fallback_kerning_width = 0;
m_fallback_font_scale = 1.0f;
m_scale = 0.37f;
m_black_border = false;
m_fallback_font_scale = 1.0f;
m_scale = 0.37f;
m_black_border = false;
if (Environment)
{
@ -213,7 +213,7 @@ public:
Driver->grab();
setInvisibleCharacters ( L" " );
io::IXMLReader* reader = env->getFileSystem()->createXMLReader(filename.c_str());
if (reader)
{
@ -223,21 +223,23 @@ public:
assert(Areas.size() > 0);
}
//! destructor
virtual ~ScalableFont()
//! destructor
virtual ~ScalableFont()
{
if (Driver) Driver->drop();
if (SpriteBank) SpriteBank->drop();
if (Driver)
Driver->drop();
if (SpriteBank)
SpriteBank->drop();
}
//! loads a font from an XML file
bool load(io::IXMLReader* xml)
//! loads a font from an XML file
bool load(io::IXMLReader* xml)
{
if (!SpriteBank)
return false;
doReadXmlFile(xml);
// set bad character
WrongCharacter = getAreaIDFromCharacter(L' ', NULL);
@ -246,20 +248,21 @@ public:
for(wchar_t c='0'; c<='9'; c++)
{
SFontArea a = getAreaFromCharacter(c, NULL);
if(a.overhang > m_max_digit_area.overhang ) m_max_digit_area.overhang = a.overhang;
if(a.underhang > m_max_digit_area.underhang) m_max_digit_area.underhang = a.underhang;
if(a.width > m_max_digit_area.width ) m_max_digit_area.width = a.width;
if (a.overhang > m_max_digit_area.overhang ) m_max_digit_area.overhang = a.overhang;
if (a.underhang > m_max_digit_area.underhang) m_max_digit_area.underhang = a.underhang;
if (a.width > m_max_digit_area.width) m_max_digit_area.width = a.width;
}
m_max_digit_area.overhang = 0;m_max_digit_area.underhang=0;
m_max_digit_area.overhang = 0;
m_max_digit_area.underhang=0;
return true;
}
//! draws an text and clips it to the specified rectangle if wanted
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
video::SColor color, bool hcenter=false,
bool vcenter=false, const core::rect<s32>* clip=0)
//! draws an text and clips it to the specified rectangle if wanted
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
video::SColor color, bool hcenter=false,
bool vcenter=false, const core::rect<s32>* clip=0)
{
if (!Driver) return;
core::position2d<s32> offset = position.UpperLeftCorner;
core::dimension2d<s32> text_dimension;
@ -267,11 +270,11 @@ public:
// bool has_tab = (text.findFirst(L'\t') != -1);
// ---- collect character locations
const unsigned int text_size = text.size();
core::array<s32> indices(text_size);
core::array<s32> indices(text_size);
core::array<core::position2di> offsets(text_size);
core::array<bool> fallback;
core::array<bool> fallback;
fallback.set_used(text_size);
for (u32 i = 0; i<text_size; i++)
{
wchar_t c = text[i];
@ -282,11 +285,12 @@ public:
offset.X = position.UpperLeftCorner.X + position.getWidth()/2;
continue;
}
if (c == L'\r' || // Windows breaks
c == L'\n' ) // Unix breaks
if (c == L'\r' || // Windows breaks
c == L'\n') // Unix breaks
{
if(c==L'\r' && text[i+1]==L'\n') c = text[++i];
if (c==L'\r' && text[i+1]==L'\n')
c = text[++i];
offset.Y += (int)(MaxHeight*m_scale);
offset.X = position.UpperLeftCorner.X;
if (hcenter)
@ -296,23 +300,23 @@ public:
bool use_fallback_font = false;
const SFontArea &area = getAreaFromCharacter(c, &use_fallback_font);
fallback[i] = use_fallback_font;
offset.X += area.underhang;
fallback[i] = use_fallback_font;
offset.X += area.underhang;
offsets.push_back(offset);
// Invisible character. add something to the array anyway so that
// indices from the various arrays remain in sync
indices.push_back( Invisible.findFirst(c) < 0 ? area.spriteno
: -1 );
indices.push_back((Invisible.findFirst(c) < 0) ? (int)area.spriteno
: -1);
offset.X += getCharWidth(area, fallback[i]);
} // for i<text_size
// ---- do the actual rendering
const int indiceAmount = indices.size();
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< core::rect<s32> >& positions = SpriteBank->getPositions();
const int indiceAmount = indices.size();
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< core::rect<s32> >& positions = SpriteBank->getPositions();
core::array< gui::SGUISprite >* fallback_sprites;
core::array< core::rect<s32> >* fallback_positions;
if(m_fallback_font!=NULL)
if (m_fallback_font!=NULL)
{
fallback_sprites = &m_fallback_font->SpriteBank->getSprites();
fallback_positions = &m_fallback_font->SpriteBank->getPositions();
@ -324,50 +328,51 @@ public:
}
video::IVideoDriver* driver = Environment->getVideoDriver();
const int spriteAmount = sprites.size();
const int spriteAmount = sprites.size();
for (int n=0; n<indiceAmount; n++)
{
const int spriteID = indices[n];
if (!fallback[n] && (spriteID < 0 || spriteID >= spriteAmount)) continue;
if (indices[n] == -1) continue;
if (!fallback[n] && (spriteID < 0 || spriteID >= spriteAmount))
continue;
if (indices[n] == -1)
continue;
//assert(sprites[spriteID].Frames.size() > 0);
const int texID = (fallback[n] ?
(*fallback_sprites)[spriteID].Frames[0].textureNumber :
sprites[spriteID].Frames[0].textureNumber);
(*fallback_sprites)[spriteID].Frames[0].textureNumber :
sprites[spriteID].Frames[0].textureNumber);
core::rect<s32> source = (fallback[n] ?
(*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] :
positions[sprites[spriteID].Frames[0].rectNumber]);
(*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] :
positions[sprites[spriteID].Frames[0].rectNumber]);
const TextureInfo& info = (fallback[n] ?
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second
);
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second);
float char_scale = info.m_scale;
core::dimension2d<s32> size = source.getSize();
float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale);
size.Width = (int)(size.Width * scale * char_scale);
size.Height = (int)(size.Height * scale * char_scale);
// align vertically if character is smaller
int y_shift = (size.Height < MaxHeight*m_scale ? (int)((MaxHeight*m_scale - size.Height)/2.0f) : 0);
core::rect<s32> dest(offsets[n] + core::position2di(0, y_shift), size);
video::SColor colors[] = {color, color, color, color};
video::ITexture* texture = (fallback[n] ?
m_fallback_font->SpriteBank->getTexture(texID) :
SpriteBank->getTexture(texID) );
if (texture == NULL)
{
// perform lazy loading
if (fallback[n])
{
m_fallback_font->lazyLoadTexture(texID);
@ -378,19 +383,19 @@ public:
lazyLoadTexture(texID);
texture = SpriteBank->getTexture(texID);
}
if (texture == NULL)
{
continue; // no such character
}
}
if (m_black_border)
{
// draw black border
video::SColor black(color.getAlpha(),0,0,0);
video::SColor black_colors[] = {black, black, black, black};
for (int x_delta=-2; x_delta<=2; x_delta++)
{
for (int y_delta=-2; y_delta<=2; y_delta++)
@ -401,10 +406,10 @@ public:
source,
clip,
black_colors, true);
}
}
}
}
if (fallback[n])
{
// draw text over
@ -424,23 +429,23 @@ public:
source,
clip,
colors, true);
}
}
}
//! returns the dimension of a text
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const
//! returns the dimension of a text
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const
{
assert(Areas.size() > 0);
core::dimension2d<u32> dim(0, 0);
core::dimension2d<u32> thisLine(0, (int)(MaxHeight*m_scale));
for (const wchar_t* p = text; *p; ++p)
{
if (*p == L'\r' || // Windows breaks
*p == L'\n' ) // Unix breaks
if (*p == L'\r' || // Windows breaks
*p == L'\n') // Unix breaks
{
if (*p==L'\r' && p[1] == L'\n') // Windows breaks
++p;
@ -453,26 +458,26 @@ public:
bool fallback = false;
const SFontArea &area = getAreaFromCharacter(*p, &fallback);
thisLine.Width += area.underhang;
thisLine.Width += getCharWidth(area, fallback);
}
dim.Height += thisLine.Height;
if (dim.Width < thisLine.Width) dim.Width = thisLine.Width;
// std::cout << "ScalableFont::getDimension returns : " << dim.Width << ", " << dim.Height << " --> ";
// std::cout << "ScalableFont::getDimension returns : " << dim.Width << ", " << dim.Height << " --> ";
dim.Width = (int)(dim.Width + 0.9f); // round up
dim.Height = (int)(dim.Height + 0.9f);
//std::cout << dim.Width << ", " << dim.Height << std::endl;
return dim;
}
//! Calculates the index of the character in the text which is on a specific position.
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const
//! Calculates the index of the character in the text which is on a specific position.
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const
{
s32 x = 0;
s32 idx = 0;
@ -491,20 +496,20 @@ public:
return -1;
}
//! Returns the type of this font
virtual gui::EGUI_FONT_TYPE getType() const { return gui::EGFT_BITMAP; }
//! Returns the type of this font
virtual gui::EGUI_FONT_TYPE getType() const { return gui::EGFT_BITMAP; }
//! set an Pixel Offset on Drawing ( scale position on width )
virtual void setKerningWidth (s32 kerning)
//! set an Pixel Offset on Drawing ( scale position on width )
virtual void setKerningWidth (s32 kerning)
{
GlobalKerningWidth = kerning;
}
virtual void setKerningHeight (s32 kerning)
virtual void setKerningHeight (s32 kerning)
{
GlobalKerningHeight = kerning;
}
//! set an Pixel Offset on Drawing ( scale position on width )
virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const
//! set an Pixel Offset on Drawing ( scale position on width )
virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const
{
s32 ret = GlobalKerningWidth;
@ -520,67 +525,69 @@ public:
return ret;
}
virtual s32 getKerningHeight() const
virtual s32 getKerningHeight() const
{
return GlobalKerningHeight;
}
//! gets the sprite bank
virtual gui::IGUISpriteBank* getSpriteBank() const
//! gets the sprite bank
virtual gui::IGUISpriteBank* getSpriteBank() const
{
return SpriteBank;
}
//! returns the sprite number from a given character
virtual u32 getSpriteNoFromChar(const wchar_t *c) const
//! returns the sprite number from a given character
virtual u32 getSpriteNoFromChar(const wchar_t *c) const
{
return Areas[getAreaIDFromCharacter(*c, NULL)].spriteno;
}
virtual void setInvisibleCharacters( const wchar_t *s )
virtual void setInvisibleCharacters( const wchar_t *s )
{
Invisible = s;
}
private:
struct SFontArea
{
SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {}
s32 underhang;
s32 overhang;
s32 width;
u32 spriteno;
};
int getCharWidth(const SFontArea& area, const bool fallback) const
struct SFontArea
{
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {}
s32 underhang;
s32 overhang;
s32 width;
u32 spriteno;
};
int getCharWidth(const SFontArea& area, const bool fallback) const
{
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< gui::SGUISprite >* fallback_sprites = (m_fallback_font != NULL ?
&m_fallback_font->SpriteBank->getSprites() :
NULL);
&m_fallback_font->SpriteBank->getSprites() :
NULL);
const int texID = (fallback ?
(*fallback_sprites)[area.spriteno].Frames[0].textureNumber :
sprites[area.spriteno].Frames[0].textureNumber);
(*fallback_sprites)[area.spriteno].Frames[0].textureNumber :
sprites[area.spriteno].Frames[0].textureNumber);
const TextureInfo& info = (fallback ?
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second
);
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second);
const float char_scale = info.m_scale;
//std::cout << "area.spriteno=" << area.spriteno << ", char_scale=" << char_scale << std::endl;
if (fallback) return (int)(((area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width) * m_scale * char_scale);
else return (int)((area.width + area.overhang + GlobalKerningWidth) * m_scale * char_scale);
if (fallback)
return (int)(((area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width) * m_scale * char_scale);
else
return (int)((area.width + area.overhang + GlobalKerningWidth) * m_scale * char_scale);
}
s32 getAreaIDFromCharacter(const wchar_t c, bool* fallback_font) const
{
std::map<wchar_t, s32>::const_iterator n = CharacterMap.find(c);
if (n != CharacterMap.end())
{
if (fallback_font != NULL) *fallback_font = false;
if (fallback_font != NULL)
*fallback_font = false;
return (*n).second;
}
else if (m_fallback_font != NULL && fallback_font != NULL)
@ -591,19 +598,20 @@ private:
else
{
// std::cout << "The font does not have this character : <" << (int)c << ">" << std::endl;
if (fallback_font != NULL) *fallback_font = false;
if (fallback_font != NULL)
*fallback_font = false;
return WrongCharacter;
}
}
const SFontArea &getAreaFromCharacter(const wchar_t c, bool* fallback_font) const
const SFontArea &getAreaFromCharacter(const wchar_t c, bool* fallback_font) const
{
const int area_id = getAreaIDFromCharacter(c, fallback_font);
const bool use_fallback_font = (fallback_font && *fallback_font);
const bool use_fallback_font = (fallback_font && *fallback_font);
// Note: fallback_font can be NULL
return ( use_fallback_font ? m_fallback_font->Areas[area_id] : Areas[area_id]);
} // getAreaFromCharacter
void setMaxHeight()
void setMaxHeight()
{
// FIXME: should consider per-texture scaling
MaxHeight = 0;
@ -618,18 +626,18 @@ private:
MaxHeight = t;
}
}
core::array<SFontArea> Areas;
/** The maximum values of all digits, used in monospace_digits. */
mutable SFontArea m_max_digit_area;
std::map<wchar_t, s32> CharacterMap;
video::IVideoDriver* Driver;
gui::IGUISpriteBank* SpriteBank;
gui::IGUIEnvironment* Environment;
u32 WrongCharacter;
s32 MaxHeight;
s32 GlobalKerningWidth, GlobalKerningHeight;
core::array<SFontArea> Areas;
/** The maximum values of all digits, used in monospace_digits. */
mutable SFontArea m_max_digit_area;
std::map<wchar_t, s32> CharacterMap;
video::IVideoDriver* Driver;
gui::IGUISpriteBank* SpriteBank;
gui::IGUIEnvironment* Environment;
u32 WrongCharacter;
s32 MaxHeight;
s32 GlobalKerningWidth, GlobalKerningHeight;
core::stringw Invisible;
core::stringw Invisible;
};
}
@ -655,12 +663,12 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
logTestString("Testing driver %ls\n", driver->getName());
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true);
driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY,true);
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true);
driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY,true);
video::ITexture* images = driver->getTexture("../media/2ddemo.png");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);
@ -668,54 +676,54 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
io::path cwd = device->getFileSystem()->getWorkingDirectory();
device->getFileSystem()->changeWorkingDirectoryTo("media");
ScalableFont* font = new ScalableFont(device->getGUIEnvironment(), "title_font.xml");
font->m_fallback_font_scale = 4.0f;
font->m_fallback_kerning_width = 15;
font->setKerningWidth(-18);
font->m_black_border = true;
ScalableFont* font = new ScalableFont(device->getGUIEnvironment(), "title_font.xml");
font->m_fallback_font_scale = 4.0f;
font->m_fallback_kerning_width = 15;
font->setKerningWidth(-18);
font->m_black_border = true;
/*
Prepare a nicely filtering 2d render mode for special cases.
*/
driver->getMaterial2D().UseMipMaps = true;
Prepare a nicely filtering 2d render mode for special cases.
*/
driver->getMaterial2D().UseMipMaps = true;
driver->getMaterial2D().TextureLayer[0].BilinearFilter = true;
{
driver->beginScene(true, true, video::SColor(255,120,102,136));
driver->enableMaterial2D();
driver->enableMaterial2D();
// draw fire & dragons background world
driver->draw2DImage(images, core::position2di(),
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(114,75),
imp1, 0, video::SColor(255,255,255,255), true);
imp1, 0, video::SColor(255,255,255,255), true);
// draw second flying imp
driver->draw2DImage(images, core::position2d<s32>(220,55),
imp2, 0, video::SColor(255,255,255,255), true);
imp2, 0, video::SColor(255,255,255,255), true);
driver->draw2DImage(images, core::rect<s32>(10,10,108,48),
core::rect<s32>(354,87,442,118));
core::rect<s32>(354,87,442,118));
video::SColor colors[] = {0xff00ffff, 0xff00ffff, 0xffffff00, 0xffffff00};
driver->draw2DImage(images, core::recti(10,50,108,88),
core::recti(354,87,442,118), 0, colors, true);
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,20,300,300),
video::SColor(255,255,255,255) );
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,20,300,300),
video::SColor(255,255,255,255) );
driver->enableMaterial2D(false);
driver->draw2DImage(images, core::recti(10,90,108,128),
core::recti(354,87,442,118), 0, colors, true);
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,60,300,400),
video::SColor(255,255,255,255) );
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,60,300,400),
video::SColor(255,255,255,255) );
driver->endScene();
}
font->drop();
@ -727,7 +735,7 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
device->closeDevice();
device->run();
device->drop();
return result;
return result;
}
// This test renders a 3d scene and a gui on top of it. The GUI is
@ -821,7 +829,7 @@ static bool addBlend2d(video::E_DRIVER_TYPE type)
device->closeDevice();
device->run();
device->drop();
return result;
return result;
}
// This test renders 4 times the same image. Two via IGUIImage, two via draw2DImage
@ -833,8 +841,8 @@ static bool moreFilterTests(video::E_DRIVER_TYPE type)
if (!device)
return true;
video::IVideoDriver* driver = device->getVideoDriver();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
video::IVideoDriver* driver = device->getVideoDriver();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
if (!driver->queryFeature(video::EVDF_BILINEAR_FILTER))
{
@ -848,41 +856,41 @@ static bool moreFilterTests(video::E_DRIVER_TYPE type)
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
video::ITexture* tex = driver->getTexture("../media/irrlichtlogo.jpg");
gui::IGUIImage* image = gui->addImage(core::recti(0,0,64,64));
image->setScaleImage(true);
image->setImage(tex);
image->setUseAlphaChannel(true);
gui::IGUIImage* image = gui->addImage(core::recti(0,0,64,64));
image->setScaleImage(true);
image->setImage(tex);
image->setUseAlphaChannel(true);
driver->getMaterial2D().TextureLayer[0].BilinearFilter=true;
driver->getMaterial2D().TextureLayer[0].TrilinearFilter=true;
{
driver->beginScene(true, true, irr::video::SColor(255,255,255,255));
{
driver->beginScene(true, true, irr::video::SColor(255,255,255,255));
// all three logos should be with filtering
driver->enableMaterial2D();
driver->enableMaterial2D();
driver->getMaterial2D().setTexture(0, 0);
driver->draw2DImage(tex, irr::core::rect<irr::s32>(64, 64, 128, 128), irr::core::rect<irr::s32>(0, 0, 88, 31));
driver->getMaterial2D().setTexture(0, 0);
driver->draw2DImage(tex, irr::core::rect<irr::s32>(64, 64, 128, 128), irr::core::rect<irr::s32>(0, 0, 88, 31));
driver->getMaterial2D().setTexture(0, tex);
driver->draw2DImage(tex, irr::core::rect<irr::s32>(64, 0, 128, 64), irr::core::rect<irr::s32>(0, 0, 88, 31));
driver->draw2DImage(tex, irr::core::rect<irr::s32>(64, 0, 128, 64), irr::core::rect<irr::s32>(0, 0, 88, 31));
gui->drawAll();
gui->drawAll();
// the next gui image should be without filter
driver->enableMaterial2D(false);
driver->enableMaterial2D(false);
image->setRelativePosition(core::recti(0,64,64,128));
gui->drawAll();
gui->drawAll();
driver->endScene();
}
}
bool result = takeScreenshotAndCompareAgainstReference(driver, "-2dmatFilter.png");
device->closeDevice();
device->run();
device->drop();
return result;
return result;
}
bool twodmaterial()

View File

@ -41,7 +41,7 @@ bool testShots(video::E_DRIVER_TYPE type)
smgr->drawAll();
driver->endScene();
for (u32 i=0; i<video::ECF_UNKNOWN; ++i)
for (s32 i=0; i<video::ECF_UNKNOWN; ++i)
{
video::IImage* img = driver->createScreenShot((video::ECOLOR_FORMAT)i);
logTestString("Color Format %d %ssupported\n", i, (img && img->getColorFormat() == i)?"":"un");

View File

@ -10,41 +10,41 @@ namespace
// test camera changes with terrain scene node recalculation
bool terrainRecalc(void)
{
IrrlichtDevice *device =
createDevice(video::EDT_BURNINGSVIDEO, dimension2du(160, 120), 32);
IrrlichtDevice *device =
createDevice(video::EDT_BURNINGSVIDEO, dimension2du(160, 120), 32);
if (!device)
return true;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../media/terrain-heightmap.bmp");
terrain->setScale(core::vector3df(40.f, .1f, 40.f));
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../media/terrain-heightmap.bmp");
terrain->setScale(core::vector3df(40.f, .1f, 40.f));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("../media/terrain-texture.jpg"));
terrain->setDebugDataVisible(scene::EDS_FULL);
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("../media/terrain-texture.jpg"));
terrain->setDebugDataVisible(scene::EDS_FULL);
scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
const core::vector3df center(terrain->getBoundingBox().getCenter());
camera->setTarget(center);
const core::vector3df center(terrain->getBoundingBox().getCenter());
camera->setTarget(center);
// yes, Y is intentionally being set to X here
const core::vector3df above (center.X, center.X, center.Z);
camera->setPosition (above);
// yes, Y is intentionally being set to X here
const core::vector3df above (center.X, center.X, center.Z);
camera->setPosition (above);
camera->setUpVector(vector3df(1.f, 0.f, 0.f));
camera->setFarValue(above.Y);
camera->setFarValue(above.Y);
device->run();
smgr->drawAll();
device->run();
smgr->drawAll();
// This shouldn't cause a recalc
camera->setUpVector(vector3df(1.f, 0.f, .01f).normalize());
device->run();
device->run();
driver->beginScene(true, true, video::SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
@ -58,7 +58,7 @@ bool terrainRecalc(void)
// This is big enough to cause a recalc
camera->setUpVector(vector3df(1.f, 0.f, .1f).normalize());
device->run();
device->run();
driver->beginScene(true, true, video::SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
@ -72,7 +72,7 @@ bool terrainRecalc(void)
device->closeDevice();
device->run();
device->drop();
return result;
return result;
}
bool terrainGaps()
@ -114,7 +114,7 @@ bool terrainGaps()
device->closeDevice();
device->run();
device->drop();
return true;
return result;
}
}
@ -124,4 +124,5 @@ bool terrainSceneNode()
bool result = terrainRecalc();
result &= terrainGaps();
return result;
}
}