如何为Android加载FTGLES(或任何其他文本呈现)

时间:2012-03-08 17:00:09

标签: android text opengl-es rendering

我的任务是编写一个使用OpenGL ES 1.0(或必要时为1.1)的应用程序,我需要能够在屏幕上呈现文本。位图文本和纹理字体在这里不是真正的选择。我知道对于iOS有FTGLES,它表明android支持是在“不久的将来”,但考虑到我的项目的最后期限,我需要一个答案(它是否可行/可以工作/不工作/等)比不幸的是,“不久的将来”。

我已经在这里和其他地方搜索了帖子,并没有找到任何有用的东西。我已经尝试在Eclipse中使用JNI和NDK,但也没有任何用处。如果有人能指出我正确的方向,我将不胜感激。我也试过跳线,但应用程序不是本机代码,它全部用Java编写。我有点惊讶,有人还没有解决这个问题(以我现在可以找到的方式)。感谢所有帮助我找到解决方案。

修改

在JNI文件夹中,我将源(每个都在自己的子文件夹中)放置为freetype和ftgles。我还必须编译不同版本的sqlite来启用RTREE。我最初陷入困境,因为我正在编译错误的文件。希望这证明是有帮助的。

这是本机代码的FTGLES部分的Make文件:

include $(CLEAR_VARS)

include $(JNI_DIR)/freetype/Android.mk

LOCAL_PATH := $(JNI_DIR)

include $(CLEAR_VARS)

GLES_PATH := $(JNI_DIR)/include/
FTGL_PATH := ftgles
FREETYPE_PATH := freetype
GLU_PATH := $(FTGL_PATH)/src/iGLU-1.0.0

FULL_FTGL_PATH := $(LOCAL_PATH)/$(FTGL_PATH)
FULL_FT_PATH := $(LOCAL_PATH)/$(FREETYPE_PATH)
FULL_GLU_PATH := $(LOCAL_PATH)/$(GLU_PATH)

FTGL_INCLUDE := -I$(FULL_FTGL_PATH) -I$(FULL_FTGL_PATH)/src -I$(FULL_FTGL_PATH)/src/FTGL -I$(FULL_FTGL_PATH)/src/FTFont -I$(FULL_FTGL_PATH)/src/FTGlyph -I$(FULL_FTGL_PATH)/src/FTLayout
FREETYPE_INCLUDE := -I$(FULL_FT_PATH) -I$(FULL_FT_PATH)/include -I$(FULL_FT_PATH)/include/freetype -I$(FULL_FT_PATH)/include/freetype/config -I$(FULL_FT_PATH)/include/freetype/internal -I$(FULL_FT_PATH)/include/freetype/internal/services -I$(FULL_FT_PATH)/freetype/include/freetype2/freetype -I$(FULL_FT_PATH)/freetype/include/freetype2/freetype/config
GLU_INCLUDE := -I$(FULL_GLU_PATH) -I$(FULL_GLU_PATH)/include -I$(FULL_GLU_PATH)/libtess -I$(FULL_GLU_PATH)/libutil -I$(GLES_PATH)

FTGL_FTFONT_SRC := $(FTGL_PATH)/src/FTFont/FTFont.cpp $(FTGL_PATH)/src/FTFont/FTFontGlue.cpp $(FTGL_PATH)/src/FTFont/FTOutlineFont.cpp $(FTGL_PATH)/src/FTFont/FTPolygonFont.cpp $(FTGL_PATH)/src/FTFont/FTTextureFont.cpp
FTGL_FTGLYPH_SRC := $(FTGL_PATH)/src/FTGlyph/FTGlyph.cpp $(FTGL_PATH)/src/FTGlyph/FTGlyphGlue.cpp $(FTGL_PATH)/src/FTGlyph/FTOutlineGlyph.cpp $(FTGL_PATH)/src/FTGlyph/FTPolygonGlyph.cpp $(FTGL_PATH)/src/FTGlyph/FTTextureGlyph.cpp
FTGL_FTLAYOUT_SRC := $(FTGL_PATH)/src/FTLayout/FTLayout.cpp $(FTGL_PATH)/src/FTLayout/FTLayoutGlue.cpp $(FTGL_PATH)/src/FTLayout/FTSimpleLayout.cpp

FTGL_SRC := $(FTGL_PATH)/src/FTBuffer.cpp $(FTGL_PATH)/src/FTCharmap.cpp $(FTGL_PATH)/src/FTContour.cpp $(FTGL_PATH)/src/FTFace.cpp $(FTGL_FTFONT_SRC) $(FTGL_PATH)/src/FTGL/ftglesglue.cpp $(FTGL_FTGLYPH_SRC) $(FTGL_PATH)/src/FTGlyphContainer.cpp $(FTGL_FTLAYOUT_SRC) $(FTGL_PATH)/src/FTLibrary.cpp $(FTGL_PATH)/src/FTPoint.cpp $(FTGL_PATH)/src/FTSize.cpp $(FTGL_PATH)/src/FTVectoriser.cpp
GLU_SRC := $(GLU_PATH)/libtess/dict.c $(GLU_PATH)/libtess/geom.c $(GLU_PATH)/libtess/memalloc.c $(GLU_PATH)/libtess/mesh.c $(GLU_PATH)/libtess/normal.c $(GLU_PATH)/libtess/priorityq.c $(GLU_PATH)/libtess/render.c $(GLU_PATH)/libtess/sweep.c $(GLU_PATH)/libtess/tess.c $(GLU_PATH)/libtess/tessmono.c
GLU_SRC2 := $(GLU_PATH)/libutil/error.c $(GLU_PATH)/libutil/glue.c $(GLU_PATH)/libutil/project.c $(GLU_PATH)/libutil/registry.c

#DEBUG MODE: Uncomment this and set android:debuggable in the manifest to true
# DEBUGMODE_FLAGS := -DSELF_EDIT
#RELEASE MODE: Comment the above line, uncomment below, android:debuggable false
DEBUGMODE_FLAGS := -DNDEBUG

LOCAL_MODULE    := ftgl
LOCAL_CFLAGS    := -Werror -DFT2_BUILD_LIBRARY=1 -DTARGET_ANDROID $(FTGL_INCLUDE) $(FREETYPE_INCLUDE) $(GLU_INCLUDE) $(DEBUGMODE_FLAGS)
LOCAL_SRC_FILES := $(FTGL_SRC) $(GLU_SRC) $(GLU_SRC2)   
LOCAL_LDLIBS    := -llog -lGLESv1_CM -lGLESv2 -landroid -lEGL -lOpenSLES 
LOCAL_STATIC_LIBRARIES := freetype2-static 

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := ftgles
LOCAL_CFLAGS    := -Werror -DFT2_BUILD_LIBRARY=1 -DTARGET_ANDROID $(FTGL_INCLUDE) $(FREETYPE_INCLUDE) $(GLU_INCLUDE) $(DEBUGMODE_FLAGS)
LOCAL_LDLIBS    := -llog -lGLESv1_CM -lGLESv2 -landroid -lEGL -lOpenSLES
LOCAL_SRC_FILES := ftgleswrapper.cpp
LOCAL_STATIC_LIBRARIES := ftgl freetype2-static

include $(BUILD_SHARED_LIBRARY)

1 个答案:

答案 0 :(得分:1)

我认为你不需要编写所有这些包装器。

看看。

我的freetype Android.Mk文件看起来像这样

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/builds \
    $(LOCAL_PATH)/include

LOCAL_SRC_FILES:= \
    src/base/ftbbox.c \
    src/base/ftbitmap.c \
    src/base/ftglyph.c \
    src/base/ftstroke.c \
    src/base/ftxf86.c \
    src/base/ftbase.c \
    src/base/ftsystem.c \
    src/base/ftinit.c \
    src/base/ftgasp.c \
    src/raster/raster.c \
    src/sfnt/sfnt.c \
    src/smooth/smooth.c \
    src/autofit/autofit.c \
    src/truetype/truetype.c \
    src/cff/cff.c \
    src/psnames/psnames.c \
    src/pshinter/pshinter.c \
    src/type1/type1.c \
    src/cid/type1cid.c \
    src/pfr/pfr.c \
    src/type42/type42.c \
    src/winfonts/winfnt.c \
    src/pcf/pcf.c \
    src/psaux/psaux.c \
    src/bdf/bdf.c \
    src/gzip/ftgzip.c \
    src/lzw/ftlzw.c

LOCAL_CFLAGS += -DFT2_BUILD_LIBRARY
LOCAL_MODULE := freetype
LOCAL_LDLIBS := -ldl -llog

include $(BUILD_STATIC_LIBRARY)

我的ftgles Android.mk文件看起来像这样

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := FTGLES
LOCAL_CFLAGS := -I$(LOCAL_PATH)/../freetype/include

LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \
$(LOCAL_PATH)/src/iGLU-1.0.0/include

LOCAL_SRC_FILES := \
src/FTBuffer.cpp \
src/FTCharmap.cpp \
src/FTContour.cpp \
src/FTFace.cpp \
src/FTFont/FTBitmapFont.cpp \
src/FTFont/FTBufferFont.cpp \
src/FTFont/FTFont.cpp \
src/FTFont/FTFontGlue.cpp \
src/FTFont/FTOutlineFont.cpp \
src/FTFont/FTPixmapFont.cpp \
src/FTFont/FTPolygonFont.cpp \
src/FTFont/FTTextureFont.cpp \
src/FTGL/ftglesGlue.cpp \
src/FTGlyph/FTBitmapGlyph.cpp \
src/FTGlyph/FTBufferGlyph.cpp \
src/FTGlyph/FTGlyph.cpp \
src/FTGlyph/FTGlyphGlue.cpp \
src/FTGlyph/FTOutlineGlyph.cpp \
src/FTGlyph/FTPixmapGlyph.cpp \
src/FTGlyph/FTPolygonGlyph.cpp \
src/FTGlyph/FTTextureGlyph.cpp \
src/FTGlyphContainer.cpp \
src/FTLayout/FTLayout.cpp \
src/FTLayout/FTLayoutGlue.cpp \
src/FTLayout/FTSimpleLayout.cpp \
src/FTLibrary.cpp \
src/FTPoint.cpp \
src/FTSize.cpp \
src/FTVectoriser.cpp \
src/iGLU-1.0.0/libtess/dict.c \
src/iGLU-1.0.0/libtess/geom.c \
src/iGLU-1.0.0/libtess/memalloc.c \
src/iGLU-1.0.0/libtess/mesh.c \
src/iGLU-1.0.0/libtess/normal.c \
src/iGLU-1.0.0/libtess/priorityq.c \
src/iGLU-1.0.0/libtess/render.c \
src/iGLU-1.0.0/libtess/sweep.c \
src/iGLU-1.0.0/libtess/tess.c \
src/iGLU-1.0.0/libtess/tessmono.c \
src/iGLU-1.0.0/libutil/error.c \
src/iGLU-1.0.0/libutil/glue.c \
src/iGLU-1.0.0/libutil/project.c \
src/iGLU-1.0.0/libutil/registry.c

LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DFTGL_LIBRARY_STATIC
LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog

LOCAL_STATIC_LIBRARIES := freetype

include $(BUILD_SHARED_LIBRARY)

你可能会得到一些找不到gl.h的错误。修复它们指向正确的位置。

现在我的主要Android.mk文件

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/../freetype/include \
$(LOCAL_PATH)/../ftgles/src \
../../../src/TestApp

LOCAL_CFLAGS := \
-DFTGL_LIBRARY_STATIC

LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \
../../../src/TestApp/app.cpp

LOCAL_SHARED_LIBRARIES := SDL2 FTGLES

LOCAL_LDLIBS := -lGLESv1_CM -llog

include $(BUILD_SHARED_LIBRARY)

所有东西都编译好并且效果很好。我可以在freetype和ftgles中调用所有c / c ++函数。但是我无法调整字体大小。 我在这里有一个主题。

Freetype FT_Request_Size() crashes on Android

DigitalKnob