Got the basics of sprites working
This commit is contained in:
+49
-49
@@ -17,13 +17,13 @@ export fn main() void = {
|
||||
|
||||
const win = sdl3::CreateWindow(
|
||||
c::nulstr("Meadow\0"),
|
||||
WIDTH, HEIGHT, 0)!;
|
||||
WIDTH, HEIGHT, sdl3::WindowFlags::RESIZABLE)!;
|
||||
defer sdl3::DestroyWindow(win);
|
||||
|
||||
const render = sdl3::CreateRenderer(win, null)!;
|
||||
defer sdl3::DestroyRenderer(render);
|
||||
sdl3::SetRenderDrawColor(render, 0, 0, 128, 255)!;
|
||||
|
||||
sdl3::SetRenderVSync(render,1)!;
|
||||
// const img = image::LoadTexture(render, c::nulstr("./assets/mascot.jpg\0"))!;
|
||||
// defer sdl3::DestroyTexture(img);
|
||||
|
||||
@@ -58,8 +58,12 @@ export fn main() void = {
|
||||
let path = os::args[1];
|
||||
let state: *uxn::uxn = uxn::uxn_init(path)!;
|
||||
uxn::uxn_reset(state);
|
||||
let next_refresh: u64 = 0;
|
||||
const perf_freq: u64 = sdl3::GetPerformanceFrequency();
|
||||
const frame_interval = perf_freq / 60;
|
||||
const ms_interval = perf_freq / 1000;
|
||||
for (run) {
|
||||
//UXN stuff
|
||||
const now: u64 = sdl3::GetPerformanceCounter();
|
||||
if(state.running){
|
||||
// fmt::printf("Next Step!\n")!;
|
||||
uxn::uxn_step(state)!;
|
||||
@@ -115,25 +119,31 @@ export fn main() void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
if(now >= next_refresh){
|
||||
next_refresh = now + frame_interval;
|
||||
|
||||
if(state.screen_vector != 0){
|
||||
uxn::uxn_eval(state.screen_vector, state)!;
|
||||
};
|
||||
};
|
||||
if(state.screen_size_changed){
|
||||
let dims = uxn::get_window_size(state);
|
||||
// fmt::printfln("Setting window to width: {:x} height: {:x}", dims.width, dims.height)!;
|
||||
if((dims.width != 0) && (dims.height !=0)){
|
||||
//TODO, check current dims
|
||||
//
|
||||
sdl3::DestroyTexture(meadow_texture);
|
||||
let w: int = dims.width: int;
|
||||
let h: int = dims.height: int;
|
||||
|
||||
fmt::printfln("Setting window to width: {} height: {}", w, h)!;
|
||||
sdl3::SetWindowSize(win,w,h)!;
|
||||
|
||||
|
||||
meadow_texture = sdl3::CreateTexture(render,
|
||||
sdl3::PixelFormat::XRGB4444,
|
||||
sdl3::TextureAccess::STATIC,
|
||||
w,
|
||||
h)!;
|
||||
|
||||
|
||||
state.screen_update = true;
|
||||
};
|
||||
|
||||
@@ -142,34 +152,23 @@ export fn main() void = {
|
||||
};
|
||||
|
||||
if(state.screen_update){
|
||||
let pcount = 0;
|
||||
const dims = uxn::get_window_size(state);
|
||||
for(let y: u16 = 0; y <= dims.height: u16; y+=1 ){
|
||||
for(let x: u16 = 0; x <= dims.width: u16; x+=1 ){
|
||||
let colshort: u16 = uxn::get_color(x,y,state);
|
||||
//take 16-bit color and transform to 32-bit number
|
||||
//XRGB -> XXRXGXBX
|
||||
// const r = (colshort & 0x0F00): u32 << (3*4);
|
||||
// const g = (colshort & 0x00F0): u32 << (2*4);
|
||||
// const b = (colshort & 0x000F): u32 << (1*4);
|
||||
// const color: u32 = r | g | b;
|
||||
// const data = pixeldata: *[*]u32; //
|
||||
// if(colshort !=0x0fff){
|
||||
// fmt::printfln("Pixel x: {:x} y: {:x} color: {:x}", x, y, colshort)!;
|
||||
// };
|
||||
// fmt::printfln("Pixel x: {} y: {} color: {:x} pcount: {:x}", x, y, colshort, pcount)!;
|
||||
if(y == 0 && x < 64) colshort = 0;
|
||||
const index: u32 = y: u32 * dims.width: u32 + x: u32;
|
||||
// if(index < 10) fmt::printfln("pcount: {} index: {} x: {} y: {}", pcount, index, x, y)!;
|
||||
pixeldata[index] = colshort;
|
||||
pcount +=1;
|
||||
};
|
||||
// pixeldata[pcount] = 0;
|
||||
// pcount += 4096;
|
||||
};
|
||||
const pitch: int = dims.width: int * 2;
|
||||
fmt::printfln("Pitch is {}", pitch)!;
|
||||
// fmt::printfln("Pitch is {}", pitch)!;
|
||||
if(pitch > 0) sdl3::UpdateTexture(meadow_texture, null, pixeldata, pitch)!;
|
||||
sdl3::RenderClear(render)!;
|
||||
sdl3::RenderTexture(render, meadow_texture, null, null)!;
|
||||
|
||||
sdl3::RenderPresent(render)!;
|
||||
state.screen_update = false;
|
||||
};
|
||||
|
||||
@@ -178,38 +177,39 @@ export fn main() void = {
|
||||
for (sdl3::PollEvent(&ev)) {
|
||||
if (ev.event_type == sdl3::EventType::QUIT) {
|
||||
run = false;
|
||||
}else if(ev.event_type == sdl3::EventType::WINDOW_RESIZED){
|
||||
let dims = uxn::get_window_size(state);
|
||||
let w = ev.window.data1;
|
||||
let h = ev.window.data2;
|
||||
if((dims.width != w: u16) || (dims.height != h: u16)){
|
||||
// fmt::println("Dimensions not allowed!")!;
|
||||
//TODO handle this maybe
|
||||
sdl3::DestroyTexture(meadow_texture);
|
||||
let old_w: int = dims.width: int;
|
||||
let old_h: int = dims.height: int;
|
||||
|
||||
fmt::printfln("Setting window to width: {} height: {}", w, h)!;
|
||||
sdl3::SetWindowSize(win,w,h)!;
|
||||
|
||||
meadow_texture = sdl3::CreateTexture(render,
|
||||
sdl3::PixelFormat::XRGB4444,
|
||||
sdl3::TextureAccess::STATIC,
|
||||
w,
|
||||
h)!;
|
||||
|
||||
state.screen_update = true;
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
sdl3::RenderClear(render)!;
|
||||
|
||||
// sdl3::RenderClear(render)!;
|
||||
// sdl3::RenderTexture(render, meadow_texture, null, null)!;
|
||||
|
||||
sdl3::RenderTexture(render, meadow_texture, null, null)!;
|
||||
// sdl3::RenderPresent(render)!;
|
||||
// sdl3::Delay(1000 / 60);
|
||||
|
||||
// sdl3::RenderTexture(render, img, null, &sdl3::FRect {
|
||||
// x = x: f32,
|
||||
// y = y: f32,
|
||||
// w = w: f32,
|
||||
// h = h: f32,
|
||||
// })!;
|
||||
|
||||
sdl3::RenderPresent(render)!;
|
||||
sdl3::Delay(1000 / 60);
|
||||
|
||||
// x += xd;
|
||||
// y += yd;
|
||||
// if (x + w >= WIDTH) {
|
||||
// xd = -1;
|
||||
// };
|
||||
// if (x <= 0) {
|
||||
// xd = 1;
|
||||
// };
|
||||
// if (y + h >= HEIGHT) {
|
||||
// yd = -1;
|
||||
// };
|
||||
// if (y <= 0) {
|
||||
// yd = 1;
|
||||
// };
|
||||
|
||||
sdl3::get_error()!;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user