Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorial:framebuffer_graphics [2020/11/12 21:45] iridescence [C/C++] |
tutorial:framebuffer_graphics [2021/03/12 16:10] (current) neo Bounds copy and paste errors |
||
---|---|---|---|
Line 59: | Line 59: | ||
x = 480; | x = 480; | ||
} | } | ||
- | if(y > 480) { | + | if(y > 272) { |
- | y = 480; | + | y =272; |
} | } | ||
Line 81: | Line 81: | ||
**gfx.hpp** | **gfx.hpp** | ||
- | < | + | < |
#include < | #include < | ||
Line 93: | Line 93: | ||
**gfx.cpp** | **gfx.cpp** | ||
- | < | + | < |
#include " | #include " | ||
#include < | #include < | ||
Line 173: | Line 173: | ||
pub struct Renderer { | pub struct Renderer { | ||
draw_buffer: | draw_buffer: | ||
- | disp_buffer: | + | disp_buffer: |
} | } | ||
impl Renderer { | impl Renderer { | ||
pub unsafe fn new() -> Self { | pub unsafe fn new() -> Self { | ||
- | let res = Self{ | + | let draw_buffer |
- | draw_buffer: | + | |
- | disp_buffer: (psp:: | + | |
- | }; | + | |
psp:: | psp:: | ||
- | psp:: | + | psp:: |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | | + | |
+ | draw_buffer, | ||
+ | disp_buffer, | ||
+ | } | ||
} | } | ||
- | pub fn clear(self: &Self, color: u32) { | + | pub fn clear(&self, color: u32) { |
- | unsafe{ | + | unsafe { |
- | for i in 0..(512 * 272) { | + | for i in 0..512 * 272 { |
*self.draw_buffer.add(i as usize) = color; | *self.draw_buffer.add(i as usize) = color; | ||
} | } | ||
Line 197: | Line 203: | ||
} | } | ||
- | pub fn swap_buffers(self: & | + | pub fn swap_buffers(& |
- | | + | |
- | let tmp = self.disp_buffer; | + | |
- | self.disp_buffer = self.draw_buffer; | + | |
- | self.draw_buffer = tmp; | + | |
+ | unsafe { | ||
psp:: | psp:: | ||
- | psp:: | + | psp:: |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
} | } | ||
- | pub fn draw_rect(self: &Self, x: usize, y: usize, w: usize, h: usize, color: u32) { | + | pub fn draw_rect(&self, x: usize, y: usize, w: usize, h: usize, color: u32) { |
- | | + | for y1 in 0..h { |
- | | + | for x1 in 0..w { |
- | for x1 in 0..w { | + | if let Some(ptr) = self.calculate_offset(x + x1, y + y1) { |
- | match calculate_offset(self.draw_buffer, | + | unsafe |
- | | + | *ptr = color; |
- | None => {} | + | |
} | } | ||
} | } | ||
Line 220: | Line 228: | ||
} | } | ||
} | } | ||
- | } | ||
- | #[inline] | + | |
- | unsafe | + | fn calculate_offset(&self, x: usize, y: usize) -> Option< |
- | if x <= 480 && y <= 272 { | + | |
- | | + | |
- | }else{ | + | Some(self.draw_buffer.add(x + y * 512) as *mut u32) |
- | | + | } else { |
+ | None | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } |