来自未命名命名空间的取消引用指针不起作用
对于我正在开发的 Wii 自制游戏引擎,我有这个(缩短的)脚本来处理打印文本:
#include <grrlib.h>
#include "graphics.hpp"
#include "Vera_ttf.h"
namespace {
GRRLIB_ttfFont *font = GRRLIB_LoadTTF(Vera_ttf, Vera_ttf_size);
}
namespace graphics {
namespace module {
void print(const char *str, int x, int y) {
GRRLIB_PrintfTTF(x, y, font, str, 12, 0xFFFFFFFF);
}
} // module
} // graphics
该代码可以编译,但是,当尝试调用上面的 print
函数时,不会呈现任何内容。奇怪的是,删除未命名的命名空间并将 print
函数更改为:
void print(const char *str, int x, int y) {
static GRRLIB_ttfFont *font = GRRLIB_LoadTTF(Vera_ttf, Vera_ttf_size);
GRRLIB_PrintfTTF(x, y, font, str, 12, 0xFFFFFFFF);
}
效果很好。但是,我希望字体变量可以通过另一个 setFont 函数进行更改。我怎样才能实现这个目标?
如果有人需要的话,这是 GRRLIB_PrintfTTF 函数代码: https://github.com/GRRLIB/GRRLIB/blob/master/GRRLIB/GRRLIB/GRRLIB_ttf.c
For a Wii homebrew game engine I'm working on, I have this (shortened) script that handles printing text:
#include <grrlib.h>
#include "graphics.hpp"
#include "Vera_ttf.h"
namespace {
GRRLIB_ttfFont *font = GRRLIB_LoadTTF(Vera_ttf, Vera_ttf_size);
}
namespace graphics {
namespace module {
void print(const char *str, int x, int y) {
GRRLIB_PrintfTTF(x, y, font, str, 12, 0xFFFFFFFF);
}
} // module
} // graphics
This code compiles, however, when trying to call the print
function above, nothing is rendered. Weirdly enough, removing the unnamed namespace and changing the print
function to this:
void print(const char *str, int x, int y) {
static GRRLIB_ttfFont *font = GRRLIB_LoadTTF(Vera_ttf, Vera_ttf_size);
GRRLIB_PrintfTTF(x, y, font, str, 12, 0xFFFFFFFF);
}
works fine. However, I would like the font variable to be changeable by another setFont
function. How can I achieve this?
Here's is the GRRLIB_PrintfTTF
function code if anyone needs it: https://github.com/GRRLIB/GRRLIB/blob/master/GRRLIB/GRRLIB/GRRLIB_ttf.c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您必须使用 GRRLIB_Init() 初始化库,因此您可以提供类似的 init 函数来确保您的变量在库之后初始化。
调用 GRRLIB_Init() 后调用graphics::InitGraphics()
Since you have to initialize the library with GRRLIB_Init(), you can provide a similar init function to ensure that your variables are initialized after the library.
Call graphics::InitGraphics() after you call GRRLIB_Init()