|
Project Information
Featured
Downloads
Links
|
GLES2.0 2D Render Engine For AndroidSRPGLESEngine is a 2D render engine of opengl ES2.0 for android. It is written in c++ language, and based on common language extension(cle). The advantage is that the engine can be called from c++, java, lua or python language, or make mixed-language games with them. SRPGLESEngine has also win32 version, for developers, they can make and compile games on win32 environment and run on android. Especially for games programmed with c++ language, which is more difficult to debug on android directly than win32. In SRPGLESEngine, many high level classes are defined for developers to construct their games. Such as Frame2DFaceClass, Basic2DObjectClass,GUI classes, and a particle system. These classes has rich attributes and functions to control their appearance to build kinds of games. SRPGLESEngine supports android version android 2.2/3.0/3.2/4.0. SRPGLESEngine using SRPSAGGLibEngine and SRPFSEngine Using GLES : First Methodcopy share libraries of cle into libs/armeabi directory of your project. As follows:
Using template in download page to create your games. Simple_templateActivity public class Simple_templateActivity extends Activity {
private GLSurfaceView mGLView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StarCoreFactoryPath.InitDefault(Runtime.getRuntime(),"/data/data/com.srpgles.simple_template");
AssetManager assetManager = getAssets();
try{
InputStream dataSource = assetManager.open("SRPFSEngine.zip");
StarCoreFactoryPath.InstallDefault(dataSource, false);
dataSource = assetManager.open("SRPSAGGLibEngine.zip");
StarCoreFactoryPath.InstallDefault(dataSource, false);
dataSource = assetManager.open("SRPGLESEngine_SCP.zip");
StarCoreFactoryPath.InstallDefault(dataSource, false);
}
catch(IOException e ){
}
mGLView = new GLESRenderView(this,getApplication());
setContentView(mGLView);
}
@Override protected void onPause() {
super.onPause();
// The following call pauses the rendering thread.
// If your OpenGL application is memory intensive,
// you should consider de-allocating objects that
// consume significant memory here.
mGLView.onPause();
}
@Override protected void onResume() {
super.onResume();
// The following call resumes a paused rendering thread.
// If you de-allocated graphic objects for onPause()
// this is a good place to re-allocate them.
mGLView.onResume();
}
}GLESRenderView package com.srpgles.simple_template;
...
import com.srplab.www.starcore.*;
class GLESRenderView extends GLSurfaceView {
GLESRender _renderer;
public GLESRenderView(Context context,Application application){
super(context);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
_renderer = new GLESRender(this,application);
setRenderer(_renderer);
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
this.requestFocus();
this.setFocusableInTouchMode(true);
}
...
}
public class GLESRender implements GLSurfaceView.Renderer {
...
//--------------------------------------------------------------------------------
//--your code begin here
private void InitGame(GL10 unused, EGLConfig config) {
}
}
Using GLES : Second MethodDownload share libraries of cle from network dynamically. Using this method, install package will be smaller. As follows: import com.srplab.www.starcore.*;
import com.srplab.netinst.*;
public class Simple_templateActivity extends Activity {
private GLSurfaceView mGLView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
starcore_net_inst.InstallZipFile(this,"libstarcore.so","http://www.srplab.com/android/starcore_armeabi_r3.zip", "/data/data/com.srpgles.simple_template/files");
starcore_net_inst.InstallZipFile(this,"SRPGLESEngine/SRPGLESEngineBasicModule_android.so","http://www.srplab.com/android/SRPGLESEngineLib_r1.zip", "/data/data/com.srpgles.simple_template/files");
StarCoreFactoryPath.StarCoreShareLibraryPath = "/data/data/com.srpgles.simple_template/files";
StarCoreFactoryPath.StarCoreOperationPath = "/data/data/com.srpgles.simple_template/files";
mGLView = new GLESRenderView(this,getApplication());
setContentView(mGLView);
}
@Override protected void onPause() {
super.onPause();
// The following call pauses the rendering thread.
// If your OpenGL application is memory intensive,
// you should consider de-allocating objects that
// consume significant memory here.
mGLView.onPause();
}
@Override protected void onResume() {
super.onResume();
// The following call resumes a paused rendering thread.
// If you de-allocated graphic objects for onPause()
// this is a good place to re-allocate them.
mGLView.onResume();
}
}starcore_netinst_r3.jar can be downloaded from http://code.google.com/p/cle-for-android Examplestestgles
StarObjectClass BasicMemoObject,BasicMemoObject1;
StarObjectClass FaceObject,Agg,Font;
StarObjectClass Object2DSimple;
StarObjectClass par,ParFaceObject,Curve,ButtonObject;
private void InitGame(GL10 unused, EGLConfig config) {
BasicMemoObject = Service._GetObject("GUI2DMemoClass")._New();
BasicMemoObject._Set("InitText","aal");
BasicMemoObject._Set("Pos",new Object[]{100,100});
BasicMemoObject._Set("CanvasAlpha",255);
BasicMemoObject._Set("CursorColor",255);
BasicMemoObject._Set("BkTextureFile",ImagePath+"pic.jpg");
BasicMemoObject._Set("FontColor",255);
BasicMemoObject._Set("ShowCursorFlag",true);
BasicMemoObject._Active();
BasicMemoObject._Call("Lua_RegToDevice");
BasicMemoObject1 = Service._GetObject("GUI2DMemoClass")._New();
BasicMemoObject1._Set("InitText","aal");
BasicMemoObject1._Set("Pos",new Object[]{400,200});
BasicMemoObject1._Set("CanvasAlpha",255);
BasicMemoObject1._Set("CursorColor",255);
BasicMemoObject1._Set("BkTextureFile",ImagePath+"pic.jpg");
BasicMemoObject1._Set("FontColor",255);
BasicMemoObject1._Set("ShowCursorFlag",true);
BasicMemoObject1._Active();
BasicMemoObject1._Call("Lua_RegToDevice");
FaceObject = Service._GetObject("Basic2DFaceClass")._New("","Width=256;Height=256;Pos={400,50};_Active();Lua_RegToDevice();");
Agg = Service._GetObject("SAggCanvasClass")._New("","_Active()");
Font = Service._GetObject("SAggFontClass")._New("","Height=24;FontName=\"/system/fonts/DroidSansFallback.ttf\"");
FaceObject._Call("Lua_AttachAGGObject",Agg);
Agg._Call("FillBack");
Agg._Call("DrawText",Font,0,50,0,255,255,true,false,true,"http://www.srplab.com");
FaceObject._Call("Lua_DetachAGGObject",Agg);
Object2DSimple = Service._GetObject("Object2DSimpleClass")._New("","TextureFile=\""+ImagePath+"pic.jpg\";StaticTextureFlag=false;Pos={300,300};ObjOri={100,100};_Active();Lua_RegToDevice();FrameMoveEvent=true;Rotate=45;")._Assign(new StarObjectClass(){
public void OnFrameMove(StarObjectClass self,int TickCount){
self._Set("Rotate",self._Getdouble("Rotate")+1);
if( self._Getdouble("Rotate") > 360 )
self._Set("Rotate",0);
};
});
//--particle
ParFaceObject = Service._GetObject("Basic2DFaceClass")._New("","Width=256;Height=256;Pos={700,150};_Active();Lua_RegToDevice();Lua_Clear(0);");
par=Service._GetObject("SRP2DParticleClass")._New(ParFaceObject,"","TextureFile=\""+ImagePath+"particles.png,32,32,32,32\";Lua_LoadPsi(\""+ImagePath+"trail.psi\");AutoUpdate = true;AutoFire = true;fParticleLifeMax=3;RelativePos = false;_Active();");
Curve = Service._GetObject("SRP2DCurvePathClass")._New("","Points=\"28,28,184,28,184,184,28,184,50,50\";_Active()");
par._Call("Lua_MoveParOnPath2D",Curve,100,2,30,0.01);
ButtonObject = Service._GetObject("GUI2DButtonClass")._New("","TextColor=255;_Active();Pos={100,300};InitTest=\"Button\";Lua_RegToDevice()")._Assign(new StarObjectClass(){
public Object[] OnClick(StarObjectClass self, Hashtable Event){
System.out.println("Button Click");
return null;
}
});
} particleedit
private void InitGame(GL10 unused, EGLConfig config) {
StarObjectClass PathObj = Service._New("ImagePathObj");
PathObj._Set("Path","/data/data/com.srpgles.particleedit/files/images/");
System.out.println(PathObj._Get("Path"));
Object[] Result = Service._DoFile("lua",ImagePath+"ParticleEdit.lua","");
System.out.println(Result[1]);
}FishDemo
StarObjectClass BackGround,ForeGround,Distort,BackWave,FishSurface,Fish0,Fish1[];
StarObjectClass FishImg0,FishImg1;
private void InitGame(GL10 unused, EGLConfig config) {
//load background
BackGround = Service._GetObject("Basic2DFaceClass")._New("","_Active();Lua_RegToDevice();ImgAniFile=\""+ImagePath+"background.jpg\";AlignType=5;");
//load forground
ForeGround = Service._GetObject("Basic2DFaceClass")._New("","_Active();Lua_RegToDevice();ImgAniFile=\""+ImagePath+"rocksfar.png\";AlignType=5;EnableAlpha=true;SceneLayer=32");
//create distort mesh
Distort = Service._GetObject("DistortionMeshClass")._New(ForeGround,"","Cols=4;Rows=3;_Active();AutoType=1;AutoParameter=0.02");
//load fish img
FishImg0 = Service._GetObject("Basic2DFaceClass")._New("","Width=32;Height=32;ImgAniFile=\""+ImagePath+"Fish.Ani\";_Active()");
FishImg1 = Service._GetObject("Basic2DFaceClass")._New("","Width=32;Height=32;ImgAniFile=\""+ImagePath+"FishFlip.Ani\";_Active()");
//create fish surface
FishSurface = Service._GetObject("Basic2DFaceClass")._New("FishSurface","_Active();Lua_RegToDevice();AlignType=5;EnableAlpha=true;UnPaintFlag=true;SceneLayer=10;");
FishSurface._Call("Lua_Clear",0,0);
//create fish object
Fish0 = Service._GetObject("Basic2DObjectClass")._New(FishSurface,"Fish0","_Active();EnableAlpha=true;SceneLayer=16;Lua_PlayAni(0,200,true,\"\")")._Assign(new StarObjectClass(){
public Object[] _OnCreate(Hashtable Ev){
StarObjectClass _DesObject = (StarObjectClass)Ev.get("_DesObject");
_DesObject._Set("TextureFile","@"+FishImg0._Get("_ID"));
_DesObject._Set("Pos",new Object[]{Math.random()*600+100,Math.random()*300+10});
_DesObject._Set("Direct",1);
_DesObject._Set("TickCount",0);
_DesObject._Set("Speed",Math.random()*150+50);
_DesObject._Call("Lua_Move",0, 800,((StarStructClass)_DesObject._Get("Pos"))._Get("Y"), _DesObject._Getdouble("Speed"),30,0,false );
return null;
}
public Object[] OnMoveEvent(StarObjectClass self,Hashtable Ev,int ActionID, int PathIndex){
StarObjectClass _SrcObject = (StarObjectClass)Ev.get("_SrcObject");
if( ActionID == Service._Getint("SRPACTION_STOP") ){
if(_SrcObject._Getint("Direct") == 1 ){
_SrcObject._Set("Direct",0);
_SrcObject._Set("TextureFile","@"+FishImg1._Get("_ID"));
_SrcObject._Call("Lua_Move",0, 0,((StarStructClass)_SrcObject._Get("Pos"))._Get("Y"), _SrcObject._Getdouble("Speed"),30,0,false );
}else{
_SrcObject._Set("Direct",1);
_SrcObject._Set("TextureFile","@"+FishImg0._Get("_ID"));
_SrcObject._Call("Lua_Move",0, 800,((StarStructClass)_SrcObject._Get("Pos"))._Get("Y"), _SrcObject._Getdouble("Speed"),30,0,false );
}
}
return null;
}
});
Fish1 = new StarObjectClass[50];
for(int i=1; i< 20; i++ ){
Fish1[i] = Fish0._New(FishSurface);
Fish1[i]._Active();
Fish1[i]._Call("Lua_PlayAni",0,300,true,"");
}
}Example in c++gles can be called using c++ language. You can download header files from download page ,or create header files using star2h tools of cle. command line : star2h http://www.srplab.com/starservice/SRPGLESEngine java code private void InitGame(GL10 unused, EGLConfig config) {
StarObjectClass PathObj = Service._New("ImagePathObj");
PathObj._Set("Path",ImagePath);
Service._CheckPassword(false);
Service._DoFile("","/data/data/com.srpgles.crender/lib/libCRender.so","");
}c++ code #include "SRPGLESEngine_VSClass.h"
VS_BOOL StarCoreService_Init(class ClassOfStarCore *starcore)
{
class ClassOfBasicSRPInterface *BasicSRPInterface;
class ClassOfSRPInterface *SRPInterface;
VS_CHAR Buf[256];
//--init star core
BasicSRPInterface = starcore ->GetBasicInterface();
SRPInterface = BasicSRPInterface ->GetSRPInterface(BasicSRPInterface->QueryActiveService(NULL),"","");
//---Get Image Path
void *PathObj;
VS_CHAR *ImgPath;
PathObj = SRPInterface ->GetObjectEx(NULL,"ImagePathObj");
VS_INT32 Stack = SRPInterface ->ScriptGetStack();
ImgPath = SRPInterface ->ScriptGetStr(PathObj,"Path");
sprintf(Buf,"%spic.jpg",ImgPath);
SRPInterface ->ScriptSetStack(Stack);
//---Create
class ClassOfGUI2DBasicMemoClass *Memo1;
struct StructOfSRP3DPoint2 Pointer2;
Memo1 = new ClassOfGUI2DBasicMemoClass(SRPInterface);
Memo1 ->Put_InitText("aal");
Pointer2.X = 100; Pointer2.Y = 100;
Memo1 ->Put_Pos(&Pointer2);
Memo1 ->Put_CanvasAlpha(255);
Memo1 ->Put_CursorColor(255);
Memo1 ->Put_BkTextureFile(Buf);
Memo1 ->Put_FontColor(255);
Memo1 ->Put_ShowCursorFlag(VS_TRUE);
Memo1 ->Active();
Memo1 ->RegToDevice(0);
SRPInterface -> Release();
return VS_TRUE;
}
void StarCoreService_Term(class ClassOfStarCore *starcore)
{
return;
}Android.mk LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and sourcefile(s)
LOCAL_CFLAGS += -Wno-write-strings -DENV_ANDROID
LOCAL_CPPFLAGS += -Wno-write-strings -fexceptions -DENV_ANDROID
LOCAL_LDFLAGS += -Wno-write-strings -DENV_ANDROID
LOCAL_C_INCLUDES += ../../../../../source/include
#--------source file
MODULE_CXXSRCS := main.cpp SRPGLESEngine_UUIDDef.cpp SRPGLESEngine_VSClass.cpp
LOCAL_SRC_FILES := ${MODULE_CXXSRCS}
LOCAL_LDLIBS := ../../../../../android/workspace/libs/armeabi/libstarlib.a
LOCAL_MODULE := CRender
include $(BUILD_SHARED_LIBRARY) Run on Win32Games can be written with c++,java, or lua. For any language, glesloader.dll is used to init window environment. Source code of glesloader.dll can be got from download page. java template for win32 import com.srplab.www.starcore.*;
import java.util.Hashtable;
public class simple_template{
static int RenderWnd;
static WindowsRender _render;
public static void main(String[] args){
if( args != null && args.length != 0 && args[0].indexOf('=') != -1 )
RenderWnd = Integer.valueOf(args[0].substring(args[0].indexOf('=')+1));
else
RenderWnd = 0;
simple_template renderobj;
renderobj = new simple_template();
renderobj.Init();
}
public void Init(){
_render = new WindowsRender(RenderWnd);
_render.onSurfaceCreated();
_render.onSurfaceChanged(800,480);
_render.Win32Run();
}
//--sub class
class WindowsRender{
...
//--------------------------------------------------------------------------------
//--your code begin here
private void InitGame() {
}
} //end of subclass
}
you can also use glesloader.exe to run game command line example: glesloader 800 480 particleedit.class?script=java 123 |