Przeglądaj źródła

Added get_texture_rect

Karl Zylinski 5 miesięcy temu
rodzic
commit
9f90e0d715
3 zmienionych plików z 17 dodań i 2 usunięć
  1. 6 2
      examples/minimal/minimal.odin
  2. BIN
      examples/minimal/sixten.jpg
  3. 11 0
      karl2d.odin

+ 6 - 2
examples/minimal/minimal.odin

@@ -5,16 +5,20 @@ import "core:log"
 
 main :: proc() {
 	context.logger = log.create_console_logger()
-	k2.init(1280, 720, "Karl2D Minimal Program")
+	k2.init(1080, 1080, "Karl2D Minimal Program")
 	k2.set_window_position(300, 100)
 
+	img := k2.load_texture_from_file("sixten.jpg")
+	
 	for !k2.shutdown_wanted() {
 		k2.process_events()
 		k2.clear(k2.BLUE)
 		k2.draw_text("Hellope!", {10, 10}, 32, k2.WHITE)
+
+		k2.draw_texture(img, {50, 50}, k2.WHITE)
 		k2.present()
 		free_all(context.temp_allocator)
 	}
 
 	k2.shutdown()
-}
+}

BIN
examples/minimal/sixten.jpg


+ 11 - 0
karl2d.odin

@@ -12,6 +12,7 @@ import "core:reflect"
 import tt "vendor:stb/truetype"
 
 import "core:image"
+import "core:image/jpeg"
 import "core:image/bmp"
 import "core:image/png"
 import "core:image/tga"
@@ -696,6 +697,15 @@ load_texture_from_bytes :: proc(bytes: []u8, width: int, height: int, format: Pi
 	}
 }
 
+// Get a rectangle that spans the whole texture. Coordinates will be (x, y) = (0, 0) and size
+// (w, h) = (texture_width, texture_height)
+get_texture_rect :: proc(t: Texture) -> Rect {
+	return {
+		0, 0,
+		f32(t.width), f32(t.height),
+	}
+}
+
 destroy_texture :: proc(tex: Texture) {
 	rb.destroy_texture(tex.handle)
 }
@@ -1487,6 +1497,7 @@ load_default_font :: proc() -> (Font, Load_Font_Error) {
 	}, .OK
 }
 
+_ :: jpeg
 _ :: bmp
 _ :: png
 _ :: tga