2012-03-08 49 views
1

我的任務是編寫使用OpenGL ES 1.0(或1.1,如果需要)的應用程序,並且我需要能夠在屏幕上呈現文本。位圖文本和紋理字體在這裏並不是真正的選擇。我知道iOS上有FTGLES,其中規定Android支持處於「不遠的將來」,但鑑於我的項目最後期限,我需要一個答案(無論是否有效/可能工作/不工作/等)比不幸的是「不久的將來」。如何爲Android加載FTGLES(或任何其他文本呈現)

我搜遍了這裏和其他地方的帖子,並沒有發現任何有用的東西。我已經嘗試在Eclipse中使用JNI和NDK,但也沒有任何用處。如果有人能指出我正確的方向,我將不勝感激。我也嘗試了jumpcore,但應用程序不是本地代碼,它全部用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) 
+0

我結束了我自己解決這一點。我必須將freetype和ftgles C++源代碼放入Eclipse中的項目中,並使用Android NDK一次編譯它。我創建了一個非常複雜的Android.mk,然後不得不編寫自己的包裝器來合併我想要的功能。缺點是本地調用速度較慢,所以當有大量文本時,它會增加一些額外的時間來渲染每一幀。我的普通OpenGL幀需要大約400-600毫秒的渲染時間,當有文本時,它可能需要1秒鐘(有時2-3秒)才能渲染。這不是理想的,但它的工作原理。 – s0n1c 2012-04-04 11:18:44

回答

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) 

你可能會得到一些找不到冰川。 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

+0

@ s0n1c我認爲你不得不編寫包裝,因爲你使用eclipse來製作java代碼?你需要Android NDK來使用C++庫,我是否正確? – aquawicket 2012-06-05 06:46:17

+0

我只用一個包裝器來打電話。我也沒有任何問題調整我的文字。我希望我知道如何讓你指向正確的方向。實際上,我所做的大部分工作是反覆試驗和更多錯誤。我很幸運,碰巧遇到了一些有效的工作。 – s0n1c 2012-06-14 16:42:28

相關問題