查看: 7109|回复: 12

osgText如何显示中文

[复制链接]

该用户从未签到

发表于 2008-4-19 11:43:16 | 显示全部楼层 |阅读模式
以前用setText(L"你好")是可以的,但是现在在mingw下,osg2.3.7下编译的时候,说不合法的字符串
高手给点建议。谢谢。

该用户从未签到

发表于 2008-4-19 12:06:44 | 显示全部楼层
设置一下使用中文字体text->setFont( "fonts/simhei.ttf" );~~~~~~~~~~~~

该用户从未签到

发表于 2008-4-19 12:25:21 | 显示全部楼层
不过,没有设置字体应该不会出现非法字符串的~~~~有可能是你的编译配置问题~~~~~~
最好贴出一段代码或者把工程上传过来看看~~~~~~~~~~
  • TA的每日心情
    开心
    2019-11-11 10:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2008-4-19 14:01:42 | 显示全部楼层
    mingw下面前面不加L吧应该

    该用户从未签到

     楼主| 发表于 2008-4-19 14:27:46 | 显示全部楼层
    如果
            osg::ref_ptr<osgText::Text> text = new osgText::Text;
            text->setText(L"HELLO WORLD");
    正常能过,并能够正确显示

    如果
            osg::ref_ptr<osgText::Text> text = new osgText::Text;
            text->setText(L"HELLO WORLD 你好");
    则编译的时候会有如下错误:
    main.cpp:13:16: converting to execution character set: Illegal byte sequence

    如果为:
            osg::ref_ptr<osgText::Text> text = new osgText::Text;
            text->setText("HELLO WORLD 你好");
    那么编译通过,但只会显示HELLO WORLD ,但不会显示“你好”

    [ 本帖最后由 wontor 于 2008-4-19 14:55 编辑 ]

    该用户从未签到

    发表于 2008-4-19 14:38:24 | 显示全部楼层
    原帖由 wontor 于 2008-4-19 14:27 发表
    如果
            osg::ref_ptr text = new osgText::Text;
            text->setText(L"HELLO WORLD");
    正常能过,并能够正确显示

    如果
            osg::ref_ptr text = new osgText::Text;
            text->setText(L"HELLO WORLD 你好");
    则编译的 ...


    大概这是g++的问题
    试一试加上编译器参数-finput-charset=GB2312

    [ 本帖最后由 array 于 2008-4-19 14:39 编辑 ]

    该用户从未签到

    发表于 2008-4-19 15:33:03 | 显示全部楼层
    osg::ref_ptr<osgText::Text> text = new osgText::Text;
            text->setText("HELLO WORLD 你好");
    这种情况下你再设置一下使用中文字体simhei.ttf字体,否则中文无法正常显示:text->setFont( "fonts/simhei.ttf" );
    这样应该就可以了吧~~~~~~~~~~~~~···

    该用户从未签到

     楼主| 发表于 2008-4-19 16:14:54 | 显示全部楼层
    原帖由 array 于 2008-4-19 14:38 发表


    大概这是g++的问题
    试一试加上编译器参数-finput-charset=GB2312


    首先表示感谢。
    mingw上g++编译器的确有这个问题,我用一个最简单的语句测试了一下,用这个选项可以顺利编译,如用不用就会不通过。

    但是对于OSG代码,我加上-finput-charset=GB2312选项后,会有一大堆的错误,都是关于OSG的。

    晕了。

    该用户从未签到

     楼主| 发表于 2008-4-19 16:16:42 | 显示全部楼层
    原帖由 FlySky 于 2008-4-19 15:33 发表
    osg::ref_ptr text = new osgText::Text;
            text->setText("HELLO WORLD 你好");
    这种情况下你再设置一下使用中文字体simhei.ttf字体,否则中文无法正常显示:text->setFont( "fonts/simhei.ttf" );
    这样应 ...


    谢谢。
    我在代码中已经有text->setFont("fonts/simkai.ttf");
    换成text->setFont( "fonts/simhei.ttf" );以后效果一样,HELLOWORLD正常显示,像“你好”不显示。

    该用户从未签到

    发表于 2008-4-19 17:22:18 | 显示全部楼层
    原帖由 wontor 于 2008-4-19 16:14 发表


    首先表示感谢。
    mingw上g++编译器的确有这个问题,我用一个最简单的语句测试了一下,用这个选项可以顺利编译,如用不用就会不通过。

    但是对于OSG代码,我加上-finput-charset=GB2312选项后,会有一大堆的错误 ...


    呵呵,什么错误?能提供一点错误文字信息吗

    该用户从未签到

     楼主| 发表于 2008-4-19 20:28:45 | 显示全部楼层
    原帖由 array 于 2008-4-19 17:22 发表


    呵呵,什么错误?能提供一点错误文字信息吗


    以下是错误信息的一部分,我的OSG存放于D:/VR/OSG_devcpp下:

    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:62: error: expected `;' before '('
    token
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:65: error: expected `;' before "GLe
    num"
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:65: error: `GLenum' does not name a
    type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:79: error: variable or field `setCl
    earMask' declared void
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:79: error: expected `;' before '('
    token
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:82: error: expected `;' before "GLb
    itfield"
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:82: error: `GLbitfield' does not na
    me a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:135: error: variable or field `setI
    mageReadPixelFormat' declared void
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:135: error: expected `;' before '('
    token
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:136: error: expected `;' before "GL
    enum"
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:136: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:138: error: variable or field `setI
    mageReadPixelDataType' declared void
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:138: error: expected `;' before '('
    token
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:139: error: expected `;' before "GL
    enum"
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:139: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:207: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:208: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:227: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:228: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:229: error: `GLbitfield' does not n
    ame a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:244: error: `GLenum' does not name
    a type
    D:/VR/OSG_devcpp/include/osgUtil/RenderStage:245: error: `GLenum' does not name
    a type
    In file included from D:/VR/OSG_devcpp/include/osgViewer/View:22,
                     from D:/VR/OSG_devcpp/include/osgViewer/Viewer:21,
                     from main.cpp:3:
    D:/VR/OSG_devcpp/include/osgUtil/SceneView:314: error: variable or field `setDra
    wBufferValue' declared void
    D:/VR/OSG_devcpp/include/osgUtil/SceneView:314: error: expected `;' before '(' t
    oken
    D:/VR/OSG_devcpp/include/osgUtil/SceneView:317: error: expected `;' before "GLen
    um"
    D:/VR/OSG_devcpp/include/osgUtil/SceneView:317: error: `GLenum' does not name a
    type
    In file included from D:/VR/OSG_devcpp/include/osgText/Font:25,
                     from D:/VR/OSG_devcpp/include/osgText/Text:22,
                     from main.cpp:5:
    D:/VR/OSG_devcpp/include/osg/TexEnv:30: error: `GL_DECAL' was not declared in th
    is scope
    D:/VR/OSG_devcpp/include/osg/TexEnv:30: error: enumerator value for `DECAL' not
    integer constant
    D:/VR/OSG_devcpp/include/osg/TexEnv:31: error: `GL_MODULATE' was not declared in
    this scope
    D:/VR/OSG_devcpp/include/osg/TexEnv:31: error: enumerator value for `MODULATE' n
    ot integer constant
    D:/VR/OSG_devcpp/include/osg/TexEnv:32: error: `GL_BLEND' was not declared in th
    is scope
    D:/VR/OSG_devcpp/include/osg/TexEnv:32: error: enumerator value for `BLEND' not
    integer constant
    D:/VR/OSG_devcpp/include/osg/TexEnv:33: error: `GL_REPLACE' was not declared in
    this scope
    D:/VR/OSG_devcpp/include/osg/TexEnv:33: error: enumerator value for `REPLACE' no
    t integer constant
    D:/VR/OSG_devcpp/include/osg/TexEnv:35: error: `GL_ADD' was not declared in this
    scope
    D:/VR/OSG_devcpp/include/osg/TexEnv:35: error: enumerator value for `ADD' not in
    teger constant
    In file included from D:/VR/OSG_devcpp/include/osgText/Text:22,
                     from main.cpp:5:
    D:/VR/OSG_devcpp/include/osgText/Font:335: error: `GLuint' was not declared in t
    his scope
    D:/VR/OSG_devcpp/include/osgText/Font:335: error: template argument 1 is invalid

    D:/VR/OSG_devcpp/include/osgText/Font:335: error: ISO C++ forbids declaration of
    `GLObjectList' with no type
    main.cpp: In function `int main(int, char**)':
    main.cpp:25: error: 'class osg::Camera' has no member named 'setClearMask'
    main.cpp:25: error: `GL_DEPTH_BUFFER_BIT' undeclared (first use this function)
    main.cpp:27: error: `GL_LIGHTING' undeclared (first use this function)
    D:/VR/OSG_devcpp/include/osg/ref_ptr: In destructor `osg::ref_ptr<T>::~ref_ptr()
    [with T = osg::FloatArray]':
    D:/VR/OSG_devcpp/include/osg/Shape:433:   instantiated from here
    D:/VR/OSG_devcpp/include/osg/ref_ptr:30: error: request for member `unref' in `*
    ((osg::ref_ptr<osg::FloatArray>*)this)->osg::ref_ptr<osg::FloatArray>::_ptr', wh
    ich is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr: In copy constructor `osg::ref_ptr<T>::ref_
    ptr(const osg::ref_ptr<T>&) [with T = osg::FloatArray]':
    D:/VR/OSG_devcpp/include/osg/Shape:438:   instantiated from here
    D:/VR/OSG_devcpp/include/osg/ref_ptr:28: error: request for member `ref' in `*((
    osg::ref_ptr<osg::FloatArray>*)this)->osg::ref_ptr<osg::FloatArray>::_ptr', whic
    h is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr: In member function `osg::ref_ptr<T>& osg::
    ref_ptr<T>:perator=(T*) [with T = osg::FloatArray]':
    D:/VR/OSG_devcpp/include/osg/Shape:443:   instantiated from here
    D:/VR/OSG_devcpp/include/osg/ref_ptr:50: error: request for member `ref' in `*((
    osg::ref_ptr<osg::FloatArray>*)this)->osg::ref_ptr<osg::FloatArray>::_ptr', whic
    h is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr:54: error: request for member `unref' in `*
    tmp_ptr', which is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr: In constructor `osg::ref_ptr<T>::ref_ptr(T
    *) [with T = osg::FloatArray]':
    D:/VR/OSG_devcpp/include/osg/Geometry:105:   instantiated from here
    D:/VR/OSG_devcpp/include/osg/ref_ptr:27: error: request for member `ref' in `*((
    osg::ref_ptr<osg::FloatArray>*)this)->osg::ref_ptr<osg::FloatArray>::_ptr', whic
    h is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr: In member function `osg::ref_ptr<T>& osg::
    ref_ptr<T>::operator=(const osg::ref_ptr<T>&) [with T = osg::FloatArray]':
    D:/VR/OSG_devcpp/include/osg/Geometry:115:   instantiated from here
    D:/VR/OSG_devcpp/include/osg/ref_ptr:37: error: request for member `ref' in `*((
    osg::ref_ptr<osg::FloatArray>*)this)->osg::ref_ptr<osg::FloatArray>::_ptr', whic
    h is of non-class type `int'
    D:/VR/OSG_devcpp/include/osg/ref_ptr:41: error: request for member `unref' in `*
    tmp_ptr', which is of non-class type `int'
    make: *** [main.o] Error 1

    该用户从未签到

    发表于 2008-4-22 14:38:48 | 显示全部楼层
    明显是g++不认识宽字符

    该用户从未签到

     楼主| 发表于 2008-4-22 19:54:34 | 显示全部楼层
    是阿,换成了VC7下就没有问题了。郁闷。
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    OSG中国官方论坛-有您OSG在中国才更好

    网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

    联系我们

    • 工作时间:09:00--18:00
    • 反馈邮箱:1315785073@qq.com
    快速回复 返回顶部 返回列表