remove arena, replaced by temp
also free'd SDL.Surfce
This commit is contained in:
parent
62a5cab38e
commit
9e1721f58b
34
main.odin
34
main.odin
@ -1,7 +1,7 @@
|
|||||||
|
#+vet explicit-allocators
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import vmem "core:mem/virtual"
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import SDL "vendor:sdl2"
|
import SDL "vendor:sdl2"
|
||||||
|
|
||||||
@ -18,24 +18,21 @@ print_usage :: proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
arena: vmem.Arena
|
|
||||||
arena_err := vmem.arena_init_growing(&arena)
|
|
||||||
ensure(arena_err == nil)
|
|
||||||
arena_allocator := vmem.arena_allocator(&arena)
|
|
||||||
defer vmem.arena_destroy(&arena) //clean up everything!
|
|
||||||
|
|
||||||
file := Ppm_file{}
|
|
||||||
|
|
||||||
if len(os.args) > 3 || len(os.args) < 2 {
|
if len(os.args) > 3 || len(os.args) < 2 {
|
||||||
print_usage()
|
print_usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file := Ppm_file{}
|
||||||
filename := os.args[1]
|
filename := os.args[1]
|
||||||
if ok, err := load_ppm(&file, filename, arena_allocator); !ok {
|
if ok, err := load_ppm(&file, filename, context.temp_allocator); !ok {
|
||||||
fmt.eprintfln("ERROR: Failed to load file '%s': %s ", filename, os.error_string(err))
|
fmt.eprintfln("ERROR: Failed to load file '%s': %s ", filename, os.error_string(err))
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
ppm_parse(&file, arena_allocator)
|
ppm_parse(&file, context.temp_allocator)
|
||||||
|
defer free_all(context.temp_allocator) //clear the temp
|
||||||
|
|
||||||
|
// Set the window size within the minimum or
|
||||||
|
// if the image is bigger, set the window size to that!
|
||||||
window_width: i32 = i32(
|
window_width: i32 = i32(
|
||||||
file.width,
|
file.width,
|
||||||
); if i32(file.width) < WINDOW_WIDTH_MIN {window_width = WINDOW_WIDTH_MIN}
|
); if i32(file.width) < WINDOW_WIDTH_MIN {window_width = WINDOW_WIDTH_MIN}
|
||||||
@ -43,10 +40,11 @@ main :: proc() {
|
|||||||
file.width,
|
file.width,
|
||||||
); if i32(file.height) < WINDOW_WIDTH_MIN {window_height = WINDOW_HEIGHT_MIN}
|
); if i32(file.height) < WINDOW_WIDTH_MIN {window_height = WINDOW_HEIGHT_MIN}
|
||||||
|
|
||||||
|
// SDL Init
|
||||||
sdl_init_error := SDL.Init(SDL.INIT_VIDEO)
|
sdl_init_error := SDL.Init(SDL.INIT_VIDEO)
|
||||||
assert(sdl_init_error == 0, SDL.GetErrorString())
|
assert(sdl_init_error == 0, SDL.GetErrorString())
|
||||||
|
defer SDL.Quit() // Defer quit at scope end
|
||||||
|
|
||||||
defer SDL.Quit()
|
|
||||||
window := SDL.CreateWindow(
|
window := SDL.CreateWindow(
|
||||||
WINDOW_TITLE,
|
WINDOW_TITLE,
|
||||||
SDL.WINDOWPOS_CENTERED,
|
SDL.WINDOWPOS_CENTERED,
|
||||||
@ -55,26 +53,22 @@ main :: proc() {
|
|||||||
window_height,
|
window_height,
|
||||||
WINDOW_FLAGS,
|
WINDOW_FLAGS,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(window != nil, SDL.GetErrorString())
|
assert(window != nil, SDL.GetErrorString())
|
||||||
defer SDL.DestroyWindow(window)
|
defer SDL.DestroyWindow(window)
|
||||||
|
|
||||||
surface := SDL.GetWindowSurface(window)
|
surface := SDL.GetWindowSurface(window)
|
||||||
|
defer SDL.FreeSurface(surface)
|
||||||
|
|
||||||
colour_bg := SDL.MapRGB(surface.format, 42, 42, 42)
|
colour_bg := SDL.MapRGB(surface.format, 42, 42, 42)
|
||||||
SDL.FillRect(surface, nil, colour_bg)
|
SDL.FillRect(surface, nil, colour_bg)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
pixel := SDL.Rect{0, 0, 1, 1}
|
pixel := SDL.Rect{0, 0, 1, 1}
|
||||||
|
|
||||||
for y: i32 = 0; y < i32(file.height); y += 1 {
|
for y: i32 = 0; y < i32(file.height); y += 1 {
|
||||||
for x: i32 = 0; x < i32(file.width); x += 1 {
|
for x: i32 = 0; x < i32(file.width); x += 1 {
|
||||||
red: u8
|
red: u8 = file.pixels[i].red
|
||||||
green: u8
|
green: u8 = file.pixels[i].green
|
||||||
blue: u8
|
blue: u8 = file.pixels[i].blue
|
||||||
red = file.pixels[i].red
|
|
||||||
green = file.pixels[i].green
|
|
||||||
blue = file.pixels[i].blue
|
|
||||||
pixel.x = x
|
pixel.x = x
|
||||||
pixel.y = y
|
pixel.y = y
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user