我的任务是编写一个使用OpenGL ES 1.0(或必要时使用1.1)的应用程序,我需要能够在屏幕上呈现文本。位图文本和纹理字体在这里并不是真正的选择。我知道iOS上有FTGLES,它表明android支持在“不久的将来”,但是鉴于我的项目的最后期限,我需要一个比它早得多的答案(是否可行/是否可行/不可行/等)。不幸的是,“不久的将来”。
我在这里和其他地方浏览过帖子,但没有发现任何有用的东西。我曾尝试在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)
最佳答案
我认为您不需要编写所有这些包装。
看一看。
我的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