Windows/Linux雙平臺下OpenGL字符串輸出的實現(使用QuesoGLC庫)

The Implementation of OpenGL Character String Output on Both Windows and Linux

 

    To render 2D characters in OpenGL 3D applications(especially the cross-platform applications) is always quite complicated and boring. One can use the bitmap or texture, but it's hard to handle and need many codes. And the most important, hard to achieve the expected effect.

    Fortunately, there are some tools could do this tough work for us. We can just configure the tools, and then use them in our program. The most popular and powerful and free(really free) tool is QuesoGLC . It's an implementation of GLC(OpenGL Character Renderer).

    QuesoGLC is easy to use and import into our project. It's corss-platform. And it supports the unicode characters which means you can render Chinese, Japaness, Russian characters perfectly with the local fonts.

    Now, we'll introduce how to install, configure and use QuesoGLC in our own projects.

 

 

ONE. INSTALLATION:

    QuesoGLC is based on FreeType2 and Fontconfig . We need to install these two dependencies before we compile the QuesoGLC.

 

    In Linux platforms, it'll be easy to do that. Just use: "sudo apt-get install quesoglc" or something like that. The system will deal with the dependencies for you automatically.

 

    In Windows platforms, just go to the download page of QuesoGLC . Download "quesoglc-0.7-win32-deps.zip " and "quesoglc-0.7.2-bin.zip ". The first package is the windows dependencies which is all you need to compile QuesoGLC (Which means you have no need to download and compile freetype2 and fontconfig).Then do as follows:

    1. Ooooh, by the way, of course you need a compiler. QuesoGLC have a makefile for MinGW compiler, and a .sln file for Visual Studio. I have not tested the .sln solution.

    2. Be sure the MinGW binaries path ( something like  D:/Develop/CodeBlocks/MinGW/bin ) have been added into the "PATH" environment variable. If you don't know how to do that, just google "set windows environment viriables".

    3. Extract the quesoglc package and the win32-deps package. Copy files and folders from the win32-deps folder to the quesoglc folder according to the folder name. Like: "build" to "build","src" to "src" etc.

    4. Important step: Open the "makefile.mgw" with notepad. Edit MINGW_INCLUDE, FREETYPE_INCLUDE, GLUT_LIBS path according to your system. For example, mine is:

 

MINGW_INCLUDE=D:/Develop/CodeBlocks/MinGW/include

FREETYPE_INCLUDE=D:/Develop/quesoglc-0.7.2/src/freetype
GLUT_LIBS=D:/Develop/CodeBlocks/MinGW/lib/libglut32.a

 

    5. Still in makefile.mgw, scroll to the bottom of the file. Last line, between "$(LIB_OBJECTS)" and "$(SUBLIBRARIES)", add the path where the libfreetype.lib and libfontconfig.lib stand in, with "-L" ahead. This step is to avoid the compiler cannot find these two necessary libraries when linking. For example, mine is :


$(LIB_OBJECTS) -LD:/Develop/quesoglc-0.7.2/build $(SUBLIBRARIES)

 

    6. Ok, you can compile the QuesoGLC now. Open the cmd, get into quesoglc directory, and type:

 

mingw32-make -f makefile.mgw

 

    7. wait a little while, if every thing goes right, you will not get any error. Get into the "build" folder, you should see two files appear: libglc32.a and glc32.dll. If you don't get them, double check the steps you have done.

    8. Now you can run the examples to check the installation.

 

 

TWO. CONFIGURATION:

    In Linux platforms, you always need no more configurations. If some warnings appear when you run the QuesoGLC examples, just google the warning, you will get the excellent answer.

 

    In Windows platforms, you need these steps:

    1. Copy libglc32.a to your compiler's lib directory( mine is D:/Develop/CodeBlocks/MinGW/lib ).

    2. Copy include/GL/glc.h to your compiler's include directory( mine is mine is D:/Develop/CodeBlocks/MinGW/inlcude/GL ).

    3. Copy glc32.dll to /windows/system32 or your application's directory.

    4. Copy the six .dlls and "etc" folder from BUILD/DEBUG or RELEASE/ to your application's according directory.

 

    Because windows will not construct the fonts cache itself, so you should assign a cache directory manually to avoid the "no cache warning". Do as follows:

    1. Get into etc/fonts;

    2. Open "fonts.conf" with wordpad;

    3. Find this line:

 

<dir>~/.fonts</dir>

 

    4. Add a line after this to assign the cache file directory as you want, for example, I can add is:

 

<cachedir>C:/fontconfig/fontcache</cachedir>

 

 

THREE. USING QUESOGLC IN APPLICATIONS:

    1. First of all, you should include the glc header in your program like:

 

#include <GL/glc.h>

 

    2. Add libglc.a(in Linux)/libglc32.a(in Windows) to your Linker.

    3. Initialize the QuesoGLC(NOTE: the initialization should be done for only once. You can do it in your OpenGL initialization function for example):

 

    If you wanna render Unicode characters like Chinese or Japaness, you should add these codes in initialization:

 

    NOTE: Don't forget to convert the source-code file into UTF-8 encoding if it contains Chinese characters or something like that!!!

 

    4. In OpenGL rendering functions, add these code to simply render the characters:

 

    Ok, hweeee, that's all. Now you can see the code is very simple. QuesoGLC did everything for you. There are some advance usage of QuesoGLC, like assign the font. You could just read the specification on the website.

 

    Don't hesitate to send me a mail(gomu dot wang at gmail dot com) if you cannot get it right.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章