Hi, i need some help with a compiler issue. I'm using android native development kit revision 10 which uses gcc 4.8 to do compilation. I have created two files JNIWrapper.cpp (contains C code that meant to bridge java) and game.h (contains all C++ classes, variable declarations and logic code). The problem i have is that i cannot separate the classes into a separate file for each (c++ header and c++ source). If i do separate game.h into separate files I get "SIGSEGV 0x0000" (null pointer) for the classes i try to use. What on earth could be the problem?? Regards, Shomari Sharpe
#ifndef GAME_H #define GAME_H #include "MadGenius/Core/GLog.h" #include "MadGenius/Core/GUtil.h" #include <vector> #include <jni.h> #include <pthread.h> #include <math.h> #include <GLES2/gl2.h> #include "MadGenius/FileIO/GLIBPNGFileIO.h" #include "MadGenius/FileIO/GAAssetFileIO.h" #include <png.h> #include <pnginfo.h> #include "MadGenius/Core/GLog.h" #include "defines.h" #include "graphics.h" //sprite verts, etc static short indices[] = { 0, 1, 2, 1, 3, 2 }; static float vertices[] = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f }; static float texcoords[] = {0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; static float defaultcolor[4] = { 1,1,1,1}; class sprite { public: float scale; int program; int textures[4]; int current_tex; float color[4]; float alpha; float x; float y; float xsize; float ysize; sprite() : scale(1), program(0), alpha(1), x(0), y(0), xsize(5), ysize(5), current_tex(0) { color[0] = defaultcolor[0]; color[1] = defaultcolor[1]; color[2] = defaultcolor[2]; color[3] = defaultcolor[3]; textures[0] = 0; textures[1] = 0; textures[2] = 0; textures[3] = 0; } //end function void drawcolor() { GLint attrloc; glUseProgram(program); attrloc = glGetAttribLocation(program, "aVertex"); glEnableVertexAttribArray(attrloc); glVertexAttribPointer(attrloc, 3, GL_FLOAT, 0, 0, vertices); model.Identity(); model.Translate(x, y, 0); model.Scale(xsize, ysize, 0); glUniformMatrix4fv( glGetUniformLocation(program, "uProjectionMatrix"), 1, GL_FALSE, proj.GetTranspose()); glUniformMatrix4fv( glGetUniformLocation(program, "uViewMatrix"), 1, GL_FALSE, view.GetTranspose()); glUniformMatrix4fv( glGetUniformLocation(program, "uModelMatrix"), 1, GL_FALSE, model.GetTranspose()); glUniform4fv(glGetUniformLocation(program, "uColour"), 1, color); glUniform1f(glGetUniformLocation(program, "uAlpha"), alpha); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); } //end function void drawtexture() { GLint attrloc; glUseProgram(program); attrloc = glGetAttribLocation(program, "aVertex"); glEnableVertexAttribArray(attrloc); glVertexAttribPointer(attrloc, 3, GL_FLOAT, 0, 0, vertices); attrloc = glGetAttribLocation(program, "aTexture"); glEnableVertexAttribArray(attrloc); glVertexAttribPointer(attrloc, 2, GL_FLOAT, 0, 0, texcoords); //enable the normalized flag model.Identity(); model.Translate(x, y, 0); model.Scale(xsize, ysize, 0); glBindTexture(GL_TEXTURE_2D, textures[current_tex]); glUniformMatrix4fv( glGetUniformLocation(program, "uProjectionMatrix"), 1, GL_FALSE, proj.GetTranspose()); glUniformMatrix4fv( glGetUniformLocation(program, "uViewMatrix"), 1, GL_FALSE, view.GetTranspose()); glUniformMatrix4fv( glGetUniformLocation(program, "uModelMatrix"), 1, GL_FALSE, model.GetTranspose()); glUniform1f(glGetUniformLocation(program, "uAlpha"), alpha); glUniform1i(glGetUniformLocation(program, "uTexture"), 0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); } //end function }; enum enemy_state { ENEMY_STATE_ALIVE, ENEMY_STATE_DYING, ENEMY_STATE_DEAD }; enum enemy_direction { ENEMY_DIRECTION_UP, ENEMY_DIRECTION_DOWN, ENEMY_DIRECTION_LEFT, ENEMY_DIRECTION_RIGHT }; class enemy : public sprite { public: float speed; int type; enemy_state state; float minx; float maxx; float oldx; float oldy; enemy_direction direction; enemy_direction new_direction; enemy() : speed(5), type(0), minx(0), maxx(0), oldx(0), oldy(0), state(ENEMY_STATE_ALIVE), direction(ENEMY_DIRECTION_RIGHT), new_direction(ENEMY_DIRECTION_RIGHT) { xsize = 20; ysize = 20; } //end function }; /**************************************************************************** * BULLETS ****************************************************************************/ class bullet : public sprite { public: bullet() : type(0), speed(8), dead(true) { xsize = 5; ysize = 5; } //end function int type; float speed; bool dead; }; //end class //VARIABLES ********************************** static bullet bullet_list[150]; //VARIABLES ********************************** enum powerup_type { POWERUP_NONE, POWERUP_DOUBLE_SHOT, POWERUP_LASER_SHOT, POWERUP_SPREAD_SHOT, POWERUP_BOMB, POWERUP_SHIELD, POWERUP_RAPID_SHOT }; class powerup : public sprite { public: powerup() : type(POWERUP_NONE), speed(4), dead(false) { } int type; float speed; bool dead; }; //end class enum player_weapon { PLAYER_WEAPON_SINGLE_SHOT, PLAYER_WEAPON_DOUBLE_SHOT, PLAYER_WEAPON_SPREAD, PLAYER_WEAPON_BOMB, PLAYER_WEAPON_LASER, PLAYER_WEAPON_SHIELD, PLAYER_WEAPON_RAPID_SINGLE_SHOT, PLAYER_WEAPON_RAPID_DOUBLE_SHOT }; class player : public sprite { public: player() : speed(5), moveleft(false), moveright(false), dead(false), shooting(false), shield(false), weapon(PLAYER_WEAPON_SINGLE_SHOT) { xsize = 30; ysize = 30; } //end function void move_left() { if (!shield) { moveright = false; moveleft = true; } } //end function void move_left_stop() { moveleft = false; } //end function void move_right() { if (!shield) { moveright = true; moveleft = false; } } //end function void move_right_stop() { moveright = false; } //end function void shoot() { if (!shield) shooting = true; } //end function void shoot_stop() { shooting = false; } //end function void stop() { moveright = false; moveleft = false; shooting = false; } //end function void activate_shield() { if (!shield) { shield = true; moveleft = false; moveright = false; shooting = false; } } //end function void add_bullet() { int shotcount = 0; switch(weapon) { case PLAYER_WEAPON_SINGLE_SHOT: for (int i=0; i < 150; i++) { if (bullet_list[i].dead) { bullet_list[i].dead = false; bullet_list[i].x = x; bullet_list[i].y = y - (ysize /2); playsound(SFX_PLAYER_SHOOT); //vibrate(1); break; } } break; case PLAYER_WEAPON_DOUBLE_SHOT: for (int i=0; i < 150; i+= 2) { if (bullet_list[i].dead) { bullet_list[i].dead = false; bullet_list[i].x = x - (xsize /2); bullet_list[i].y = y - (ysize /2); shotcount++; } if (bullet_list[i+1].dead) { bullet_list[i+1].dead = false; bullet_list[i+1].x = x + (xsize /2); bullet_list[i+1].y = y - (ysize /2); shotcount++; } if (shotcount == 2) { playsound(SFX_PLAYER_SHOOT); break; } } break; } //end switch //GLog::WriteLog("add_player_bullet()"); } //end function float speed; int weapon; bool dead; bool moveleft; bool moveright; bool shooting; bool shield; }; //VARIABLES ********************************** static player human_player; static graphic graphics[20]; static enemy enemy_list[150]; static sprite graphics_sprite_data[20]; static powerup powerup_list[5]; //static bullet bullet_list[150]; //VARIABLES ********************************** static void wait_vsync() { pthread_mutex_lock(&s_vsync_mutex); pthread_cond_wait(&s_vsync_cond, &s_vsync_mutex); pthread_mutex_unlock(&s_vsync_mutex); } //end function static void vibrate(int seconds) { JNIEnv* env = javavm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6); javavm->AttachCurrentThread( &env, NULL); //required to prevent crash jclass vibrator_class = env->FindClass("android/os/Vibrator"); jobject vibrator_obj = env->AllocObject(vibrator_class); jmethodID vibrator_method = env->GetMethodID(vibrator_class, "vibrate", " ([JI)V;"); jobject vibrator_call = env->CallObjectMethod(vibrator_obj, vibrator_method, seconds); env->DeleteLocalRef( vibrator_obj ); javavm->DetachCurrentThread(); } void load_graphic(const std::string filename, graphic& g) { png_structp png_ptr; png_infop info_ptr; unsigned int sig_read = 0; GAAssetFileIO* assetfile = new GAAssetFileIO(filename); g.data = NULL; if (assetfile) { /* Create and initialize the png_struct * with the desired error handler * functions. If you want to use the * default stderr and longjump method, * you can supply NULL for the last * three parameters. We also supply the * the compiler header file version, so * that we know if the application * was compiled with a compatible version * of the library. REQUIRED */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { assetfile->Close(); return; } //png_set_read_fn(png_structp read_ptr, voidp read_io_ptr, png_rw_ptr read_data_fn) assetfile->Open(); png_set_read_fn(png_ptr, (void*) assetfile, &LIBPNG_read); /* Allocate/initialize the memory * for image information. REQUIRED. */ info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { assetfile->Close(); png_destroy_read_struct(&png_ptr, NULL, NULL); return; } /* Set error handling if you are * using the setjmp/longjmp method * (this is the normal method of * doing things with libpng). * REQUIRED unless you set up * your own error handlers in * the png_create_read_struct() * earlier. */ if (setjmp(png_jmpbuf(png_ptr))) { /* Free all of the memory associated * with the png_ptr and info_ptr */ png_destroy_read_struct(&png_ptr, &info_ptr, NULL); assetfile->Close(); /* If we Get here, we had a * problem reading the file */ return; } /* If we have already * read some of the signature */ png_set_sig_bytes(png_ptr, sig_read); /* * If you have enough memory to read * in the entire image at once, and * you need to specify only * transforms that can be controlled * with one of the PNG_TRANSFORM_* * bits (this presently excludes * dithering, filling, setting * background, and doing gamma * adjustment), then you can read the * entire image (including pixels) * into the info structure with this * call * * PNG_TRANSFORM_STRIP_16 | * PNG_TRANSFORM_PACKING forces 8 bit * PNG_TRANSFORM_EXPAND forces to * expand a palette into RGB */ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, NULL); g.width = info_ptr->width; g.height = info_ptr->height; switch (info_ptr->color_type) { case PNG_COLOR_TYPE_RGBA: g.hasalpha = true; break; case PNG_COLOR_TYPE_RGB: g.hasalpha = false; break; default: png_destroy_read_struct(&png_ptr, &info_ptr, NULL); assetfile->Close(); return; } unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr); g.data = (unsigned char*) malloc(row_bytes * g.height); g.datasize = row_bytes * g.height; png_bytepp row_pointers = png_get_rows(png_ptr, info_ptr); for (int i = 0; i < g.height; i++) { // note that png is ordered top to // bottom, but OpenGL expect it bottom to top // so we rearrange the order memcpy(g.data+(row_bytes * (g.height-1-i)), row_pointers[i], row_bytes); } /* Clean up after the read, * and free any memory allocated */ png_destroy_read_struct(&png_ptr, &info_ptr, NULL); /* Close the file */ assetfile->Close(); SAFE_DELETE(assetfile); } //end asset file read //load for opengles glGenTextures(1, &g.texunit); glBindTexture(GL_TEXTURE_2D, g.texunit); // Load texture, set filter and wrap modes glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //store pixel data glTexImage2D(GL_TEXTURE_2D, 0, g.hasalpha ? GL_RGBA : GL_RGB, g.width, g.height, 0, g.hasalpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, g.data); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); GLog::WriteLog("texture unit %d", g.texunit); SAFE_FREE(g.data); } //end function void load_textures() { load_graphic("textures/brick_yellowstripes.png", graphics[GFX_PLAYER] ); load_graphic("textures/brick_foursquare.png", graphics[GFX_ENEMY1] ); //buttons in-game load_graphic("textures/left_button.png", graphics[GFX_CONTROLLER_LEFT] ); load_graphic("textures/right_button.png", graphics[GFX_CONTROLLER_RIGHT] ); load_graphic("textures/a_button.png", graphics[GFX_CONTROLLER_A] ); load_graphic("textures/b_button.png", graphics[GFX_CONTROLLER_B] ); load_graphic("textures/exit_button.png", graphics[GFX_CONTROLLER_EXIT] ); } //end function /*-------------------------------------------------------------------------- SHADERS ---------------------------------------------------------------------------*/ static int compile_shader(char* frag, char* vert ) { GLint program, fshader, vshader; program = glCreateProgram(); fshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fshader, 1, &frag, NULL); glCompileShader(fshader); int logsize = 0; glGetShaderiv(fshader, GL_INFO_LOG_LENGTH, &logsize); if (logsize > 0) { char log[logsize]; glGetShaderInfoLog(fshader, logsize, NULL, log); GLog::WriteLog("%s", log); } vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, 1, &vert, NULL); glCompileShader(vshader); glGetShaderiv(vshader, GL_INFO_LOG_LENGTH, &logsize); if (logsize > 0) { char log[logsize]; glGetShaderInfoLog(vshader, logsize, NULL, log); GLog::WriteLog("%s", log); } glAttachShader(program, vshader); glAttachShader(program, fshader); glLinkProgram(program); GLint infoLogSize = 0; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogSize); if (infoLogSize) { GLchar infoLog[infoLogSize]; glGetProgramInfoLog(program, infoLogSize, NULL, infoLog); GLog::WriteLog(infoLog); } GLog::WriteLog("program id %d", program); return program; } //end function static void compile_programs() { //color only renderer ----------------------------------------------------------- char basic_notexvert[] = "precision highp float; " "attribute vec3 aVertex; " "uniform mat4 uModelMatrix; " "uniform mat4 uViewMatrix; " "uniform mat4 uProjectionMatrix; " "void main() " "{" " gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(aVertex, 1); " "} \0"; char basic_notexfrag[] = "precision highp float; " "uniform vec4 uColour; " "uniform float uAlpha; " "void main() " "{ " " gl_FragColor = vec4(uColour.r, uColour.g, uColour.b, 1 ) * uAlpha; " "} \0"; //------------------------------------------------------------------------------ //texture only renderer char basic_texvert[] = "precision highp float; " "attribute vec3 aVertex; " "attribute vec2 aTexture; " "uniform mat4 uModelMatrix; " "uniform mat4 uViewMatrix; " "uniform mat4 uProjectionMatrix; " "varying vec2 vTextureCoord; " "void main() " "{" " gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(aVertex, 1); " " vTextureCoord = aTexture; " "} \0"; char basic_texfrag[] = "precision highp float; " "uniform sampler2D uTexture; " "uniform vec4 uColour; " "uniform float uAlpha; " "varying vec2 vTextureCoord; " "void main() " "{ " " gl_FragColor = texture2D(uTexture, vTextureCoord) * uAlpha; " "} \0"; program_texture = compile_shader(basic_texfrag, basic_texvert); program_color = compile_shader(basic_notexfrag, basic_notexvert); } //end function /*----------------------------------------------------------- GAME SPECIFIC ------------------------------------------------------------*/ static void draw_controller() { //draw buttons graphics_sprite_data[GFX_CONTROLLER_LEFT].drawtexture(); graphics_sprite_data[GFX_CONTROLLER_RIGHT].drawtexture(); graphics_sprite_data[GFX_CONTROLLER_A].drawtexture(); graphics_sprite_data[GFX_CONTROLLER_B].drawtexture(); graphics_sprite_data[GFX_CONTROLLER_EXIT].drawtexture(); } //end function static void update_player_bullets() { for (int i=0; i < 150; i++) { if (!bullet_list[i].dead) { bullet_list[i].y -= bullet_list[i].speed; if (bullet_list[i].y <= -bullet_list[i].ysize /2) bullet_list[i].dead = true; } } } //end function static void draw_player_bullets() { for (int i=0; i < 150; i++) { if (!bullet_list[i].dead) bullet_list[i].drawcolor(); } } //end function /* * GAME LOGIC */ static void process_collisions() { for (int i=0; i < 150; i++) { if (!bullet_list[i].dead) { for (int e=0; e < 50; e++) { if (bullet_list[i].x >= enemy_list[e].x - (enemy_list[e].xsize /2) && bullet_list[i].x <= enemy_list[e].x + (enemy_list[e].xsize /2) && bullet_list[i].y >= enemy_list[e].y - (enemy_list[e].ysize /2) && bullet_list[i].y <= enemy_list[e].y + (enemy_list[e].ysize /2) ) { //based on the type of bullet kill it if ( enemy_list[e].state == ENEMY_STATE_ALIVE ) { bullet_list[i].dead = true; enemy_list[e].state = ENEMY_STATE_DYING; playsound(SFX_ENEMY_EXPLODE); } } //end if } //end for } //end if } } //end function static void init_enemies() { float x = 40, y = 40; int num_across = 10; int x_count = 0; int spacing = 15; int index = 0; GLog::WriteLog("init_enemies()"); for (int i=0; i < 50; i++) { enemy_list[i].program = program_texture; enemy_list[i].textures[0] = graphics[GFX_ENEMY1].texunit; enemy_list[i].x = x; enemy_list[i].y = y; enemy_list[i].xsize = 20; enemy_list[i].ysize = 20; GLog::WriteLog("enemy pos %f,%f", enemy_list[i].x, enemy_list[i].y ); x_count++; x += (enemy_list[i].xsize) + spacing; if (x_count == num_across) { x_count = 0; x = 40; y += (enemy_list[i].ysize) + spacing; } } } //end function static void update_enemies() { float vel = 0.5; float spacing = 10; for (int i=0; i < 50; i++) { if (enemy_list[i].state != ENEMY_STATE_ALIVE ) continue; switch(enemy_list[i].direction) { case ENEMY_DIRECTION_RIGHT: enemy_list[i].x += vel; if (enemy_list[i].x >= game_width - (enemy_list[i].xsize/2)) { enemy_list[i].new_direction = ENEMY_DIRECTION_LEFT; enemy_list[i].direction = ENEMY_DIRECTION_DOWN; enemy_list[i].x = game_width - (enemy_list[i].xsize/2); enemy_list[i].oldy = enemy_list[i].y; } break; case ENEMY_DIRECTION_LEFT: enemy_list[i].x -= vel; if (enemy_list[i].x <= (enemy_list[i].xsize/2)) { enemy_list[i].new_direction = ENEMY_DIRECTION_RIGHT; enemy_list[i].direction = ENEMY_DIRECTION_DOWN; enemy_list[i].x = (enemy_list[i].xsize/2); enemy_list[i].oldy = enemy_list[i].y; } break; case ENEMY_DIRECTION_DOWN: enemy_list[i].y += vel; if (enemy_list[i].y >= enemy_list[i].oldy + spacing + (enemy_list[i].ysize)) enemy_list[i].direction = enemy_list[i].new_direction; break; } //end switch } //end for } //end function static void draw_enemies() { for (int i=0; i < 50; i++) { if (enemy_list[i].state == ENEMY_STATE_ALIVE) enemy_list[i].drawtexture(); } } //end function static void game_loop() { playmusic(0); while (1) { if (human_player.moveleft) { human_player.x -= 5; int minx = human_player.xsize /2; if (human_player.x < minx) human_player.x = minx; //GLog::WriteLog("move_left()"); } if (human_player.moveright) { human_player.x += 5; int maxx = game_width - (human_player.xsize /2); if (human_player.x > maxx) human_player.x = maxx; //GLog::WriteLog("move_right()"); } human_player.y = game_height - (human_player.ysize /2); human_player.program = program_texture; human_player.textures[0] = graphics[GFX_PLAYER].texunit; //player shooting if (human_player.shooting) human_player.add_bullet(); update_player_bullets(); update_enemies(); process_collisions(); wait_vsync(); //sleep(10); } } #endif
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> #include <GLES2/gl2.h> #include <android/asset_manager_jni.h> #include "game.h" /* Header for class com_glapp_JNIWrapper */ #ifndef _Included_com_technoid_JNIWrapper #define _Included_com_technoid_JNIWrapper #ifdef __cplusplus extern "C" { #endif jint JNI_OnLoad(JavaVM* vm, void* reserved) { GLog::WriteLog("JNIWrapper::OnLoad()"); JNIEnv* env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { return -1; } //store a reference to the java vm for later use javavm = vm; //cached sound method mainactivity_class = env->FindClass("com/technoid/MainActivity"); playsoundid = env->GetStaticMethodID( mainactivity_class, "PlaySound", "(I)V"); playmusicid = env->GetStaticMethodID( mainactivity_class, "PlayMusic", "(I)V"); return JNI_VERSION_1_6; } //end function /* * Class: com_glapp_JNIWrapper * Method: on_surface_created * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_on_1surface_1created (JNIEnv * jenv, jclass clazz) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //must compile programs here compile_programs(); //must reload all game textures load_textures(); //link all objects to the appropriate shader program here for (int i =0; i < 150; i++) bullet_list[i].program = program_color; //link sprites to programs human_player.program = program_texture; GLog::WriteLog("player program %d", human_player.program ); GLog::WriteLog("program color %d", program_color ); //controller buttons graphics_sprite_data[GFX_CONTROLLER_LEFT].program = program_texture; graphics_sprite_data[GFX_CONTROLLER_LEFT].textures[0] = graphics[GFX_CONTROLLER_LEFT].texunit; graphics_sprite_data[GFX_CONTROLLER_RIGHT].program = program_texture; graphics_sprite_data[GFX_CONTROLLER_RIGHT].textures[0] = graphics[GFX_CONTROLLER_RIGHT].texunit; graphics_sprite_data[GFX_CONTROLLER_A].program = program_texture; graphics_sprite_data[GFX_CONTROLLER_A].textures[0] = graphics[GFX_CONTROLLER_A].texunit; graphics_sprite_data[GFX_CONTROLLER_B].program = program_texture; graphics_sprite_data[GFX_CONTROLLER_B].textures[0] = graphics[GFX_CONTROLLER_B].texunit; graphics_sprite_data[GFX_CONTROLLER_EXIT].program = program_texture; graphics_sprite_data[GFX_CONTROLLER_EXIT].textures[0] = graphics[GFX_CONTROLLER_EXIT].texunit; //link other data init_enemies(); //testing } /* * Class: com_glapp_JNIWrapper * Method: on_surface_changed * Signature: (II)V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_on_1surface_1changed (JNIEnv * jenv, jclass clazz, jint width, jint height) { glViewport(0, 0, width, height); //link our game height/width game_width = width; game_height = height; game_width_center = width / 2; game_height_center = height / 2; GLog::WriteLog("width %d, height %d", width, height ); float w, h; if(width > height) { h = height; w = width * h / height; } else { w = width; h = height * w / width; } //set the perspective correction proj.Identity(); proj.SetOrtho2D(0, w, h, 0); glDisable(GL_DEPTH_TEST); //no depth } /* * Class: com_glapp_JNIWrapper * Method: on_draw_frame * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_on_1draw_1frame (JNIEnv * jenv, jclass clazz) { glClear(GL_COLOR_BUFFER_BIT); draw_controller(); human_player.drawtexture(); draw_enemies(); draw_player_bullets(); /* tell the other thread to carry on */ pthread_cond_signal(&s_vsync_cond); } //end function /* * Class: com_technoid_JNIWrapper * Method: GameLoop * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_GameLoop (JNIEnv *jenv, jclass clazz) { /* init conditions */ game_loop(); } //end function /* * Class: com_glapp_JNIWrapper * Method: setAssetManager * Signature: (Landroid/content/res/AssetManager;)V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_setAssetManager (JNIEnv * jenv, jclass clazz, jobject object) { GFileIO::SetAssetManager(AAssetManager_fromJava(jenv, object)); } //end function /* * Class: com_technoid_JNIWrapper * Method: playerMoveLeft * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerMoveLeft (JNIEnv *jenv, jclass clazz) { human_player.move_left(); } //end function JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerMoveLeftStop (JNIEnv *jenv, jclass clazz) { human_player.move_left_stop(); } //end function /* * Class: com_technoid_JNIWrapper * Method: playerMoveRight * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerMoveRight (JNIEnv *jenv, jclass clazz) { human_player.move_right(); } //end function JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerMoveRightStop (JNIEnv *jenv, jclass clazz) { human_player.move_right_stop(); } //end function /* * Class: com_technoid_JNIWrapper * Method: playerShoot * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerStop (JNIEnv *jenv, jclass clazz) { human_player.stop(); } //end function /* * Class: com_technoid_JNIWrapper * Method: playerShoot * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerShoot (JNIEnv *jenv, jclass clazz) { human_player.shoot(); } //end function JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerShootStop (JNIEnv *jenv, jclass clazz) { human_player.shoot_stop(); } //end function /* * Class: com_technoid_JNIWrapper * Method: playerActivateShield * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_playerActivateShield (JNIEnv *jenv, jclass clazz) { human_player.activate_shield(); } //end function /* * Class: com_glapp_JNIWrapper * Method: setGraphicSize * Signature: (III)V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_setGraphicSize (JNIEnv * jenv, jclass clazz, jint graphic, jint width, jint height) { graphics_sprite_data[graphic].xsize = width; graphics_sprite_data[graphic].ysize = height; GLog::WriteLog("SetGraphicSize(%d,%d)", graphics_sprite_data[graphic].xsize, graphics_sprite_data[graphic].ysize ); } //end function /* * Class: com_glapp_JNIWrapper * Method: setGraphicPosition * Signature: (III)V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_setGraphicPosition (JNIEnv * jenv, jclass clazz, jint graphic, jint x, jint y) { graphics_sprite_data[graphic].x = x; graphics_sprite_data[graphic].y = y; GLog::WriteLog("SetGraphicPosition(%d,%d)", graphics_sprite_data[graphic].x, graphics_sprite_data[graphic].y ); } //end function /* * Class: com_technoid_JNIWrapper * Method: getGraphicXSize * Signature: (I)I */ JNIEXPORT jint JNICALL Java_com_technoid_JNIWrapper_getGraphicXSize (JNIEnv *jenv, jclass clazz, jint graphic) { //GLog::WriteLog("getGraphicXSize(%f)", graphics_sprite_data[graphic].xsize); return graphics_sprite_data[graphic].xsize; } //end function /* * Class: com_technoid_JNIWrapper * Method: getGraphicYSize * Signature: (I)I */ JNIEXPORT jint JNICALL Java_com_technoid_JNIWrapper_getGraphicYSize (JNIEnv *jenv, jclass clazz, jint graphic) { //GLog::WriteLog("getGraphicYSize(%f)", graphics_sprite_data[graphic].ysize); return graphics_sprite_data[graphic].ysize; } //end function /* * Class: com_technoid_JNIWrapper * Method: getGraphicXPosition * Signature: (I)I */ JNIEXPORT jint JNICALL Java_com_technoid_JNIWrapper_getGraphicXPosition (JNIEnv *jenv, jclass clazz, jint graphic) { return graphics_sprite_data[graphic].x; } //end function /* * Class: com_technoid_JNIWrapper * Method: getGraphicYPosition * Signature: (I)I */ JNIEXPORT jint JNICALL Java_com_technoid_JNIWrapper_getGraphicYPosition (JNIEnv *jenv, jclass clazz, jint graphic) { return graphics_sprite_data[graphic].y; } //end function /* * Class: com_technoid_JNIWrapper * Method: Initialize * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_Initialize (JNIEnv *jenv, jclass clazz) { /* init conditions */ pthread_cond_init(&s_vsync_cond, NULL); pthread_mutex_init(&s_vsync_mutex, NULL); } //end function /* * Class: com_technoid_JNIWrapper * Method: Initialize * Signature: ()V */ JNIEXPORT void JNICALL Java_com_technoid_JNIWrapper_Deinitialize (JNIEnv *jenv, jclass clazz) { } //end function #ifdef __cplusplus } #endif #endif