Parcourir la source

Getting started on render textures

Karl Zylinski il y a 3 mois
Parent
commit
a764c46a36
4 fichiers modifiés avec 80 ajouts et 1 suppressions
  1. 6 1
      .sublime/karl2d.sublime-project
  2. 54 0
      examples/render_target/render_target.odin
  3. 2 0
      karl2d.doc.odin
  4. 18 0
      karl2d.odin

+ 6 - 1
.sublime/karl2d.sublime-project

@@ -21,6 +21,11 @@
 					"shell_cmd": "odin run . -vet -strict-style -keep-executable -debug",
 					"working_dir": "$project_path/../examples/fonts"
 				},
+				{
+					"name": "render_target",
+					"shell_cmd": "odin run . -vet -strict-style -keep-executable -debug",
+					"working_dir": "$project_path/../examples/render_target"
+				},
 				{
 					"name": "snake",
 					"shell_cmd": "odin run . -vet -strict-style -keep-executable -debug",
@@ -55,7 +60,7 @@
 					"name": "api_doc_builder",
 					"shell_cmd": "odin run api_doc_builder",
 					"working_dir": "$project_path/.."
-				}
+				},
 			]
 		}
 	],

+ 54 - 0
examples/render_target/render_target.odin

@@ -0,0 +1,54 @@
+package karl2d_minimal_example
+
+import k2 "../.."
+import "core:mem"
+import "core:log"
+import "core:fmt"
+
+_ :: fmt
+_ :: mem
+
+main :: proc() {
+	context.logger = log.create_console_logger()
+
+	when ODIN_DEBUG {
+		track: mem.Tracking_Allocator
+		mem.tracking_allocator_init(&track, context.allocator)
+		context.allocator = mem.tracking_allocator(&track)
+
+		defer {
+			if len(track.allocation_map) > 0 {
+				for _, entry in track.allocation_map {
+					fmt.eprintf("%v leaked: %v bytes\n", entry.location, entry.size)
+				}
+			}
+			mem.tracking_allocator_destroy(&track)
+		}
+	}
+
+	k2.init(1080, 1080, "Karl2D Minimal Program")
+	k2.set_window_position(300, 100)
+	tex := k2.load_texture_from_file("sixten.jpg")
+
+	render_target := k2.create_texture(200, 200, .RGBA_32_Float)
+
+	log.info(render_target)
+
+	for !k2.shutdown_wanted() {
+		k2.process_events()
+		k2.clear(k2.BLUE)
+
+		k2.draw_rect({10, 10, 60, 60}, k2.GREEN)
+		k2.draw_rect({20, 20, 40, 40}, k2.BLACK)
+		k2.draw_circle({120, 40}, 30, k2.BLACK)
+		k2.draw_circle({120, 40}, 20, k2.GREEN)
+		k2.draw_text("Hellöpe!", {10, 100}, 64, k2.WHITE)
+		k2.draw_texture_ex(tex, {0, 0, f32(tex.width), f32(tex.height)}, {10, 200, 900, 500}, {}, 0)
+
+		k2.present()
+		free_all(context.temp_allocator)
+	}
+
+	k2.destroy_texture(tex)
+	k2.shutdown()
+}

+ 2 - 0
karl2d.doc.odin

@@ -150,6 +150,8 @@ draw_text_ex :: proc(font: Font_Handle, text: string, pos: Vec2, font_size: f32,
 //--------------------//
 // TEXTURE MANAGEMENT //
 //--------------------//
+create_texture :: proc(width: int, height: int, format: Pixel_Format) -> Texture
+
 load_texture_from_file :: proc(filename: string) -> Texture
 
 // TODO should we have an error here or rely on check the handle of the texture?

+ 18 - 0
karl2d.odin

@@ -757,6 +757,16 @@ draw_text_ex :: proc(font: Font_Handle, text: string, pos: Vec2, font_size: f32,
 // TEXTURE MANAGEMENT //
 //--------------------//
 
+create_texture :: proc(width: int, height: int, format: Pixel_Format) -> Texture {
+	h := rb.create_texture(width, height, format)
+
+	return {
+		handle = h,
+		width = width,
+		height = height,
+	}
+}
+
 load_texture_from_file :: proc(filename: string) -> Texture {
 	img, img_err := image.load_from_file(filename, options = {.alpha_add_if_missing}, allocator = s.frame_allocator)
 
@@ -823,6 +833,14 @@ set_texture_filter_ex :: proc(
 	rb.set_texture_filter(t.handle, scale_down_filter, scale_up_filter, mip_filter)
 }
 
+//-----------------//
+// RENDER TEXTURES //
+//-----------------//
+
+/*create_render_texture :: proc(width: int, height: int) -> Render_Texture {
+
+}*/
+
 //-------//
 // FONTS //
 //-------//