Bonjou tout moun. Jodi a nou pral gade ki jan yo prepare yon pwojè lè l sèvi avèk bibliyotèk sdl2 pou kouri yon jwèt sou android.
Premye ou bezwen telechaje Android Studio, enstale li ak tout sa ki nesesè nan anviwònman devlopman sa a. Pou egzanp, kounye a mwen gen Kde Neon, ak sou sistèm sa a gen yon dosye /etc/environment, menm dosye a egziste nan ubuntu. Varyab sa yo bezwen antre nan la.
ANDROID_HOME=/home/username/Android/Sdk
ANDROID_NDK_HOME=/home/username/ndk
Ou bezwen tou telechaje NDK nan sit entènèt ofisyèl la, depake li nan anyè lakay ou epi chanje non li an NDK. Apre sa, ou bezwen telechaje bibliyotèk SDL2 la sou sit entènèt la
Pou li fichye nan android soti nan byen, ou bezwen sèvi ak fonksyon yo SDL_RWops. Isit la se yon egzanp itilizasyon nan kòd pou travay ak yon font. Nan ka sa a, nou pa ka sèvi ak FT_New_Face, men nou pral pito itilize FT_New_Memory_Face pou sèvi ak done yo te deja li yo.
#ifdef __ANDROID__
snprintf ( path, 254, "fonts/%s", file );
SDL_RWops *rw = SDL_RWFromFile(path, "r" );
char *memory = ( char * ) calloc ( rw->hidden.androidio.size, 1 );
SDL_RWread(rw, memory, 1, rw->hidden.androidio.size );
FT_New_Memory_Face(*this->ft_library, ( const FT_Byte * )memory, rw->hidden.androidio.size, 0, &this;->face );
SDL_RWclose(rw);
free ( memory );
#else
snprintf ( path, 254, "%s/fonts/%s", DEFAULT_ASSETS, file );
if ( access ( path, F_OK ) ) {
fprintf ( stderr, "not found font: %sn", path );
exit ( EXIT_FAILURE );
}
struct stat st;
stat ( path, &st; );
FILE *rw = fopen ( path, "r" );
char *memory = ( char * ) calloc ( st.st_size, 1 );
fread ( memory, 1, st.st_size, rw );
FT_New_Memory_Face ( *this->ft_library, ( const FT_Byte * ) memory, st.st_size, 0, &this;->face );
fclose ( rw );
free ( memory );
#endif
Mwen menm mwen te kreye yon dosye header konekte headers SDL2. NO_SDL_GLEXT nesesè pou konpilasyon reyisi sou Android.
#ifdef __ANDROID__
#include "SDL.h"
#include "SDL_video.h"
#include "SDL_events.h"
#define NO_SDL_GLEXT
#include "SDL_opengl.h"
#include "SDL_opengles2.h"
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_opengles2.h>
#endif
Se konsa, pwojè a pare, shaders yo pare pou Opengl Es 3.0. Koulye a, nou bezwen kreye yon android-pwojè. Pou fè sa, depake achiv SDL2 la. Ale nan bati-scripts. Epi nou fè l konsa.
./androidbuild.sh com.xverizex.test main.cpp
Mesaj sa a ap parèt.
To build and install to a device for testing, run the following:
cd /home/cf/programs/SDL2-2.0.10/build/com.xverizex.test
./gradlew installDebug
Ale nan com.xverizex.test. Ale nan com.xverizex.test/app/jni/src. Nou kopye pwojè jwèt nou an. Epi nou chanje dosye a Android.mk, nan ka mwen an li sanble sa a.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := ../SDL
FREETYPE_PATH := ../Freetype2
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include $(LOCAL_PATH)/$(FREETYPE_PATH)/include
# Add your application source files here...
LOCAL_SRC_FILES := ./engine/lang.cpp ./engine/actor.cpp ./engine/sprite.cpp ./engine/shaders.cpp ./engine/box.cpp ./engine/menubox.cpp ./engine/load_manager.cpp ./engine/main.cpp ./engine/font.cpp ./engine/model.cpp ./engine/button.cpp ./theme.cpp ./level_manager.cpp ./menu/menu.cpp
LOCAL_SHARED_LIBRARIES := SDL2 Freetype2
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
Kòm ou ka deja remake, mwen enkli bibliyotèk Freetype2 la. Mwen te jwenn yon sèl pare sou github pou android, men li pa t 'travay, mwen te bezwen chanje yon bagay. Nou menm tou nou kreye yon anyè app/src/main/assets. Nou mete resous nou yo ladan l (polices, sprites, modèl 3D).
Koulye a, kite a konfigirasyon Freetype2 pou android. Telechaje soti nan github mwen an
Sous: www.habr.com