Example #1
0
static int load_resources(void* unused) {
  
  folder_load(P("./resources/terrain/"));
  folder_load(P("./resources/vegetation/"));
  
  static_object* skydome = entity_new("skydome", static_object);
  skydome->renderable = asset_hndl_new_load(P("./resources/terrain/skydome.obj"));
  ((renderable*)asset_hndl_ptr(skydome->renderable))->material = asset_hndl_new_load(P("$CORANGE/shaders/skydome.mat"));
  skydome->position = vec3_new(512, 0, 512);
  skydome->scale = vec3_new(1024, 1024, 1024);
  
  landscape* world = entity_new("world", landscape);
  world->terrain = asset_hndl_new_load(P("./resources/terrain/heightmap.raw"));
  world->normalmap = asset_hndl_new_load(P("./resources/terrain/normalsmap.dds"));
  world->colormap = asset_hndl_new_load(P("./resources/terrain/colormap.dds"));
  world->attributemap = asset_hndl_new_load(P("./resources/terrain/attributemap.dds"));

  landscape_set_textures(world, asset_hndl_new_load(P("./resources/terrain/surface.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_bump.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_far.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_far_bump.dds")));
  
  vegetation_init();
  //vegetation_add_type(asset_get("./resources/terrain/heightmap.raw"), 
  //                    asset_get("./resources/vegetation/grass.obj"), 
  //                    4.0);
  
  ui_button* loading = ui_elem_get("loading");
  ui_spinner* load_spinner = ui_elem_get("load_spinner");
  ui_button* framerate = ui_elem_get("framerate");
  ui_button* wireframe = ui_elem_get("wireframe");
  ui_button* freecam = ui_elem_get("freecam");
  loading->active = false;
  load_spinner->active = false;
  framerate->active = true;
  wireframe->active = true;
  freecam->active = true;
  
  loading_resources = false;
  return 1;
}
Example #2
0
int main(int argc, char **argv) {

#ifdef _WIN32
    FILE* ctt = fopen("CON", "w" );
    FILE* fout = freopen( "CON", "w", stdout );
    FILE* ferr = freopen( "CON", "w", stderr );
#endif

    corange_init("../../assets_core");

    graphics_viewport_set_size(1280, 720);
    graphics_viewport_set_title("Noise");

    folder_load(P("./"));
    file_load(P("$CORANGE/textures/random.dds"));

    glClearColor(1.0, 0.0, 0.0, 1.0);

    ui_button* info_button = ui_elem_new("info_button", ui_button);
    ui_button_move(info_button, vec2_new(10, 10));
    ui_button_resize(info_button, vec2_new(460,25));
    ui_button_set_label(info_button, "Procedural texture from perlin noise and feedback functions");

    ui_button* save_button = ui_elem_new("save_button", ui_button);
    ui_button_move(save_button, vec2_new(480, 10));
    ui_button_resize(save_button, vec2_new(380,25));
    ui_button_set_label(save_button, "Click Here to save tileable perlin noise to file");
    ui_button_set_onclick(save_button, save_noise_to_file);

    ui_button* spinner_box = ui_elem_new("spinner_box", ui_button);
    ui_button_resize(spinner_box, vec2_new(32, 32));
    ui_button_move(spinner_box, vec2_new(870, 7));
    ui_button_set_label(spinner_box, "");

    ui_spinner* save_spinner = ui_elem_new("save_spinner", ui_spinner);
    save_spinner->color = vec4_new(1,1,1,0);
    save_spinner->top_left = vec2_new(874, 11);
    save_spinner->bottom_right = vec2_add(save_spinner->top_left, vec2_new(24,24));

    srand(time(NULL));
    shader_time = (float)rand() / (RAND_MAX / 1000);

    bool running = true;
    while(running) {
        frame_begin();

        SDL_Event event;
        while(SDL_PollEvent(&event)) {

            switch(event.type) {
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if (event.key.keysym.sym == SDLK_ESCAPE) {
                    running = 0;
                }
                if (event.key.keysym.sym == SDLK_PRINTSCREEN) {
                    graphics_viewport_screenshot();
                }
                break;
            case SDL_QUIT:
                running = 0;
                break;
                break;
            }

            ui_event(event);

        }

        shader_time += frame_time();
        ui_update();

        noise_render();
        ui_render();

        graphics_swap();

        frame_end();

    }

    SDL_WaitThread(save_thread, NULL);

    corange_finish();

    return 0;
}
Example #3
0
void folder_reload(fpath folder) {
  folder_unload(folder);
  folder_load(folder);
  asset_cache_flush();
}
Example #4
0
void platformer_init() {
  
  /* Set the viewport title */
  graphics_viewport_set_title("Platformer");
  
  /* Register functions for loading/unloading files with the extension .level */
  asset_handler(level, "level", level_load_file, level_delete);
  
  /* Load Assets */
  folder_load(P("./tiles/"));
  folder_load(P("./backgrounds/"));
  folder_load(P("./sounds/"));
  folder_load(P("./levels/"));
  
  /* Register some handlers for creating and destroying entity types */
  entity_handler(character, character_new, character_delete);
  entity_handler(coin, coin_new, coin_delete);
  
  /* Create our main character */
  character* main_char = entity_new("main_char", character);
  
  /* Add some UI elements */
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, vec2_new(10,10));
  ui_button_resize(framerate, vec2_new(30,25));
  ui_button_set_label(framerate, " ");
  ui_button_disable(framerate);
  
  ui_button* score = ui_elem_new("score", ui_button);
  ui_button_move(score, vec2_new(50, 10));
  ui_button_resize(score, vec2_new(120, 25));
  ui_button_set_label(score, "Score 000000");
  ui_button_disable(score);
  
  ui_button* time = ui_elem_new("time", ui_button);
  ui_button_move(time, vec2_new(180, 10));
  ui_button_resize(time, vec2_new(110, 25));
  ui_button_set_label(time, "Time 000000");
  ui_button_disable(time);
  
  ui_button* victory = ui_elem_new("victory", ui_button);
  ui_button_move(victory, vec2_new(365, 200));
  ui_button_resize(victory, vec2_new(70, 25));
  ui_button_set_label(victory, "Victory!");
  ui_button_disable(victory);
  
  ui_button* new_game_but = ui_elem_new("new_game", ui_button);
  ui_button_move(new_game_but, vec2_new(365, 230));
  ui_button_resize(new_game_but, vec2_new(70, 25));
  ui_button_set_label(new_game_but, "New Game");
  
  
  void on_newgame(ui_button* b, void* unused) {
    reset_game();
  }
  
  ui_button_set_onclick(new_game_but, on_newgame);
  
  /* Reset all the game variables */
  reset_game();
  
}
Example #5
0
void sea_init() {
  
  graphics_viewport_set_dimensions(1280, 720);
  graphics_viewport_set_title("Sea");

  camera* cam = entity_new("camera", camera);
  cam->position = vec3_new(50.0, 50.0, 50.0);
  cam->target = vec3_new(0, 5, 0);
  cam->near_clip = 0.1;
  
  light* sun = entity_new("sun", light);
  light_set_type(sun, light_type_spot);
  sun->position = vec3_new(20,23,16);
  sun->ambient_color = vec3_new(0.5, 0.5, 0.5);
  sun->diffuse_color = vec3_new(1.0,  0.894, 0.811);
  sun->specular_color = vec3_mul(vec3_new(1.0,  0.894, 0.811), 4);
  sun->power = 5;
  
  light* backlight = entity_new("backlight", light);
  light_set_type(backlight, light_type_point);
  backlight->position = vec3_new(-22,10,-13);
  backlight->ambient_color = vec3_new(0.2, 0.2, 0.2);
  backlight->diffuse_color = vec3_new(0.729, 0.729, 1.0);
  backlight->specular_color = vec3_mul(vec3_new(0.729, 0.729, 1.0), 1);
  backlight->power = 2;
  
  shadow_mapper_init(sun);  
  
  forward_renderer_init();
  forward_renderer_set_camera(cam);
  forward_renderer_set_shadow_light(sun);
  forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
  forward_renderer_add_light(sun);
  forward_renderer_add_light(backlight);
  
  folder_load(P("./resources/"));
  
  renderable* r_seaplane = asset_get(P("./resources/seaplane.obj"));
  r_seaplane->material = asset_hndl_new(P("./resources/seaplane.mat"));
  
  static_object* s_seaplane = entity_new("seaplane", static_object);
  s_seaplane->renderable = asset_hndl_new_ptr(r_seaplane);
  s_seaplane->scale = vec3_new(3,1,3);
  
  renderable* r_skydome = asset_get(P("./resources/skydome.obj"));
  r_skydome->material = asset_hndl_new_load(P("$CORANGE/shaders/skydome.mat"));
  
  static_object* skydome = entity_new("skydome", static_object);
  skydome->renderable = asset_hndl_new_ptr(r_skydome);
  skydome->position = vec3_new(0, -512, 0);
  skydome->scale = vec3_new(1024, 1024, 1024);
  
  folder_load(P("./resources/corvette/"));
  
  renderable* r_corvette = asset_get(P("./resources/corvette/corvette.obj"));
  r_corvette->material = asset_hndl_new_load(P("./resources/corvette/corvette.mat"));
  
  static_object* s_corvette = entity_new("corvette", static_object);
  s_corvette->renderable = asset_hndl_new_ptr(r_corvette);
  //s_corvette->collision_body = collision_body_new_mesh(asset_get("./resources/corvette/corvette.col"));
  s_corvette->scale = vec3_new(1.5, 1.5, 1.5);
  s_corvette->position = vec3_new(0, 0.5, 0);
  
  static_object* center_sphere = entity_new("center_sphere", static_object);
  center_sphere->position = vec3_new(0, 5, 0);
  //center_sphere->renderable = asset_get("./resources/ball.obj");
  //center_sphere->collision_body = collision_body_new_sphere(sphere_new(v3_zero(), 1.0f));
  
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, vec2_new(10,10));
  ui_button_resize(framerate, vec2_new(30,25));
  ui_button_set_label(framerate, "FRAMERATE");
  ui_button_disable(framerate);
  
}