Esempio n. 1
0
/***
__Work in progress__. Create a render target. Don't use it.
@function target
@tparam integer width
@tparam integer height
@treturn target
*/
static int gfx_target(lua_State *L) {
	int width = luaL_checkinteger(L, 1);
	int height = luaL_checkinteger(L, 2);
	int wpo2 = 0, hpo2 = 0;
	for (;width>pow(2,wpo2);wpo2++);
	width = pow(2,wpo2);
	for (;height>pow(2,hpo2);hpo2++);
	height = pow(2,hpo2);
	
	target_userdata *target;
	target = (target_userdata*)lua_newuserdata(L, sizeof(*target));
	
	luaL_getmetatable(L, "LTarget");
	lua_setmetatable(L, -2);
	
	target->target = sf2d_create_rendertarget(width, height);
	
	return 1;
}
Esempio n. 2
0
static int gfx_target___index(lua_State *L) {
	target_userdata *target = luaL_checkudata(L, 1, "LTarget");
	const char* name = luaL_checkstring(L, 2);
	
	if (strcmp(name, "texture") == 0) {
		texture_userdata *texture;
		texture = (texture_userdata*)lua_newuserdata(L, sizeof(*texture));
		luaL_getmetatable(L, "LTexture");
		lua_setmetatable(L, -2);
		
		texture->texture = &(target->target->texture);
		texture->scaleX = 1.0f;
		texture->scaleY = 1.0f;
		texture->blendColor = 0xffffffff;
		
		return 1;
	} else if (strcmp(name, "duck") == 0) {
		sf2d_rendertarget *target = sf2d_create_rendertarget(64, 64);
		for(int i=0;;i++) {
			sf2d_clear_target(target, 0xff000000);
			sf2d_start_frame_target(target);
			sf2d_draw_fill_circle(i%380, i%200, 10, 0xff0000ff);
			sf2d_end_frame();
			//sf2d_texture_tile32(&target->texture);
			
			sf2d_start_frame(GFX_TOP, GFX_LEFT);
			sf2d_draw_texture(&target->texture, 10, 10);
			sf2d_end_frame();
			sf2d_swapbuffers();
		}
	} else {
		for (u8 i=0;target_methods[i].name;i++) {
			if (strcmp(target_methods[i].name, name) == 0) {
				lua_pushcfunction(L, target_methods[i].func);
				return 1;
			}
		}
	}
	
	lua_pushnil(L);
	return 1;
}
Esempio n. 3
0
STATIC mp_obj_t mod_sf2d_RenderTarget_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) {
    mp_arg_check_num(n_args, n_kw, 2, NEW_ARG_COUNT, true);

    static const mp_arg_t allowed_args[] = {
            {MP_QSTR_width,  MP_ARG_INT | MP_ARG_REQUIRED},
            {MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED},
    };

    mp_arg_val_t args[NEW_ARG_COUNT];
    mp_arg_parse_all_kw_array(n_args, n_kw, args_in, NEW_ARG_COUNT, allowed_args, args);

    mod_sf2d_RenderTarget_t *obj = m_new_obj(mod_sf2d_RenderTarget_t);
    obj->base.type = (mp_obj_t) &mod_sf2d_RenderTarget_type;

    int width = args[NEW_ARG_WIDTH].u_int;
    int height = args[NEW_ARG_HEIGHT].u_int;

    obj->target = sf2d_create_rendertarget(width, height);
    //obj->texture = _mod_sf2d_Texture_from_ptr(&obj->target->texture);

    return obj;
}