Skip to content

Blend mode fixes for renderer and texture #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use SdlResult;
use std::mem;
use std::ptr;
use std::raw;
use libc::{c_int, uint32_t, c_float, c_double, c_void};
use libc::{c_int, c_uint, uint32_t, c_float, c_double, c_void};
use rect::Point;
use rect::Rect;
use std::ffi::c_str_to_bytes;
Expand Down Expand Up @@ -195,6 +195,23 @@ impl Renderer {
}
}

pub fn set_blend_mode(&self, blend: BlendMode) -> SdlResult<()> {
let ret = unsafe { ll::SDL_SetRenderDrawBlendMode(self.raw, FromPrimitive::from_i64(blend as i64).unwrap()) };

if ret == 0 { Ok(()) }
else { Err(get_error()) }
}

pub fn get_blend_mode(&self) -> SdlResult<BlendMode> {
let blend: c_uint = 0;
let result = unsafe { ll::SDL_GetRenderDrawBlendMode(self.raw, &blend) == 0 };
if result {
Ok(FromPrimitive::from_i64(blend as i64).unwrap())
} else {
Err(get_error())
}
}

pub fn clear(&self) -> SdlResult<()> {
let ret = unsafe { ll::SDL_RenderClear(self.raw) };
if ret == 0 { Ok(()) }
Expand Down Expand Up @@ -579,8 +596,8 @@ impl Texture {
}

pub fn get_blend_mode(&self) -> SdlResult<BlendMode> {
let blend: i64 = 0;
let result = unsafe { ll::SDL_GetTextureBlendMode(self.raw, &FromPrimitive::from_i64(blend as i64).unwrap()) == 0 };
let blend: c_uint = 0;
let result = unsafe { ll::SDL_GetTextureBlendMode(self.raw, &blend) == 0 };
if result {
Ok(FromPrimitive::from_i64(blend as i64).unwrap())
} else {
Expand Down