Skip to content

Instantly share code, notes, and snippets.

@emberian
Forked from ttdonovan/gist:8bb2c4c7a09e8bbb9cea
Last active August 29, 2015 14:12
Show Gist options
  • Save emberian/e7535354210ef55f5185 to your computer and use it in GitHub Desktop.
Save emberian/e7535354210ef55f5185 to your computer and use it in GitHub Desktop.
use std::os;
#[allow(unused_variables)]
fn main() {
let width = 2u8;
let height = 3u8;
let size = 4u8;
let pitch = width * size;
let (mut x_offset, mut y_offset) = (0u8, 0u8);
let chunk = match os::MemoryMap::new((width * height * size) as uint, &[
os::MapOption::MapReadable,
os::MapOption::MapWritable
]) {
Ok(chunk) => chunk,
Err(msg) => panic!("{}", msg)
};
let base = chunk.ptr as *mut u32;
for y in range(0u8, height) {
for x in range(0u8, width) {
let red: u8 = 0u8;
let green: u8 = y + y_offset;
let blue: u8 = x + x_offset;
*base.offset_mut(y * height + width) = (green << 8) | blue;
}
};
}
internal void
RenderWeirdGradient(int BlueOffset, int GreenOffset)
{
int Width = BitmapWidth;
int Height = BitmapHeight;
int Pitch = Width*BytesPerPixel;
uint8 *Row = (uint8 *)BitmapMemory;
for(int Y = 0;
Y < BitmapHeight;
++Y)
{
uint32 *Pixel = (uint32 *)Row;
for(int X = 0;
X < BitmapWidth;
++X)
{
uint8 Blue = (X + BlueOffset);
uint8 Green = (Y + GreenOffset);
*Pixel++ = ((Green << 8) | Blue);
}
Row += Pitch;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment