Example #1
0
// Push texture pointer as userdata, followed by width and height of texture.
// This is currently used only by texture_from_font but could be used by other functions in future.
static int texture_from_surface(lua_State * L, SDL_Surface * surface) {
	SDL_Texture * texture;
	SDL_Texture ** ud;
	int w;
	int h;
	SDL_BlendMode blend_mode;
	
	texture = SDL_CreateTextureFromSurface(renderer, surface);
	SDL_FreeSurface(surface);
	if (!texture) {
		luaL_error(L, "%s", SDL_GetError());
	}

	if (SDL_GetTextureBlendMode(texture, &blend_mode)) {
		luaL_error(L, "%s", SDL_GetError());
	}
	SDL_assert_release(blend_mode == SDL_BLENDMODE_BLEND);

	ud = (SDL_Texture **) lua_newuserdata(L, sizeof(SDL_Texture *));
	if (ud == NULL) {
		luaL_error(L, "Failed to create userdata in texture_from_surface.");
	}

	*ud = texture;
	SDL_QueryTexture(texture, NULL, NULL, &w, &h);
	lua_pushinteger(L, w);
	lua_pushinteger(L, h);
	return 3;
}
Example #2
0
static VALUE sdl2r_get_texture_blend_mode(VALUE klass, VALUE vtexture)
{
    struct SDL2RTexture *tex = SDL2R_GET_TEXTURE_STRUCT(vtexture);
    SDL_BlendMode bm;

    if (SDL_GetTextureBlendMode(tex->texture, &bm)) {
        rb_raise(eSDLError, SDL_GetError());
    }

    return INT2NUM(bm);
}
Example #3
0
CAMLprim value
caml_SDL_GetTextureBlendMode(value texture)
{
    SDL_BlendMode blendMode;
    int r =
        SDL_GetTextureBlendMode(
            SDL_Texture_val(texture),
            &blendMode);
    if (r)
        caml_failwith("Sdltexture.get_blend_mode");
    return Val_SDL_BlendMode(blendMode);
}
Example #4
0
/** Gets the blend mode of the texture. */
GyBlendMode gytexture_blendmode(GyTexture * self) {
 SDL_BlendMode blendmode;
 int res = SDL_GetTextureBlendMode(GY_TEXTURE_UNWRAP(self), &blendmode);
  return (res < 0 ? GyBlendModeError : (GyBlendMode)blendmode);
}