obs_scene_t obs_scene_create(const char *name) { struct obs_source *source = bmalloc(sizeof(struct obs_source)); struct obs_scene *scene; memset(source, 0, sizeof(struct obs_source)); if (!obs_source_init_handlers(source)) { bfree(source); return NULL; } source->settings = obs_data_create(); scene = scene_create(source->settings, source); source->data = scene; assert(scene); if (!scene) { obs_data_release(source->settings); bfree(source); return NULL; } source->name = bstrdup(name); source->type = SOURCE_SCENE; scene->source = source; obs_source_init(source, &scene_info); memcpy(&source->callbacks, &scene_info, sizeof(struct source_info)); return scene; }
void init() { heightfield hf; heightfieldinfo hfi; skybox sb; object3d plan = create_plan_xy(100, 100, 1, 1); material mat = material_create(NULL, 0, &color_red, 0, 0); matrix4 tmp; vector3 cam_pos = {0,50,0}; vector3 cam_up = {0,1,0}; vector3 cam_look = {0,50,-1}; viewport vp = viewport_create(0, 0, display_width(screen), display_height(screen)); /* Camera */ camfps = camera_create(60, ZFAR, ZNEAR, &cam_pos, &cam_look, &cam_up, vp); /* Heightfied creation */ hf = heightfield_create_from_file("data/height.png", 1000, 1000, 100); heightfield_set_textures_from_file(hf, "data/land.jpg", "data/detail.jpg"); heightfield_set_detail_scale(hf, 50, 50); matrix4_to_rot_x(tmp, -90); heightfield_set_world_matrix(hf, tmp); /* Heightfield infos*/ hfi = heightfieldinfo_create("data/land.jpg", hf, camfps, screen, 250, 250); /* Skybox */ sb = skybox_create(camfps, "data/left.jpg", "data/right.jpg", "data/front.jpg", "data/back.jpg", "data/top.jpg", "data/bottom.jpg", 10); /* Test plane */ object3d_set_material(plan, mat); /* Populate the scene */ scn = scene_create(); scene_set_camera(scn, camfps); scene_set_display(scn, screen); scene_add_object(scn, sb, (void *)skybox_to_opengl, NULL); scene_add_object(scn, hf, (void *)heightfield_to_opengl, NULL); scene_add_object(scn, plan, (void *)object3d_to_opengl, NULL); scene_add_object2d(scn, hfi, (void *)heightfieldinfo_to_opengl, NULL); fontgl_init(); font = fontgl_create("data/vera.ttf", 800, 600, 16); fontgl_set_color(font, 1,0,0); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); SDL_WarpMouse(CENTERX,CENTERY); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); }
Game* game_create(int width, int height) { srand(time(NULL)); Game* game = malloc(sizeof(*game)); game->run = 0; game->window = window_create(width, height); game->gl = glcontext_create(game->window); game->timer = timer_create(); glGenVertexArrays(1, &game->vao_id); glBindVertexArray(game->vao_id); check_gl_errors("VAO creation"); game->scene = scene_create(); return game; }
TrayObject *rayscene(TrayLangState *state, int arg_num) { TrayObject *camera = traylang_get_obj(state); check(camera, "scene camera arg error"); TrayObject *config = traylang_get_obj(state); check(config, "scene config arg error"); TrayObject *lights = traylang_get_obj(state); check(lights, "scene lights arg error"); List *light_list = tlist_to_clist(lights->list); TrayObject *shapes = traylang_get_obj(state); check(shapes, "scene shapes arg error"); List *shape_list = tlist_to_clist(shapes->list); return traylang_new_cdata( state, scene_create(camera->cdata, config->cdata, light_list, shape_list) ); error: return NULL; }
void game_reload(Game* game, const char* tmp_path) { scene_save(game->scene, tmp_path); scene_destroy(game->scene); game->scene = scene_create(); scene_load(game->scene, tmp_path); }