Ver código fonte

Vec2 instead of Vec3 where applicable

Karl Zylinski 7 meses atrás
pai
commit
58e2cba111
2 arquivos alterados com 17 adições e 19 exclusões
  1. 15 17
      karl2d_windows.odin
  2. 2 2
      shader.hlsl

+ 15 - 17
karl2d_windows.odin

@@ -116,7 +116,7 @@ _init :: proc(width: int, height: int, title: string,
 	device->CreateVertexShader(vs_blob->GetBufferPointer(), vs_blob->GetBufferSize(), nil, &vertex_shader)
 
 	input_element_desc := [?]D3D11.INPUT_ELEMENT_DESC{
-		{ "POS", 0, .R32G32B32_FLOAT, 0, 0, .VERTEX_DATA, 0 },
+		{ "POS", 0, .R32G32_FLOAT, 0, 0, .VERTEX_DATA, 0 },
 		{ "COL", 0, .R8G8B8A8_UNORM , 0, D3D11.APPEND_ALIGNED_ELEMENT, .VERTEX_DATA, 0 },
 	}
 
@@ -169,12 +169,10 @@ _init :: proc(width: int, height: int, title: string,
 
 VERTEX_BUFFER_MAX :: 10000
 
-Vec3 :: [3]f32
-
 shader_hlsl :: #load("shader.hlsl")
 
 Vertex :: struct {
-	pos: Vec3,
+	pos: Vec2,
 	color: Color,
 }
 
@@ -321,7 +319,7 @@ _draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE) {
 	)
 }
 
-add_vertex :: proc(v: Vec3, color: Color) {
+add_vertex :: proc(v: Vec2, color: Color) {
 	s.vertex_buffer_map[s.vertex_buffer_count] = {
 		pos = v,
 		color = color,
@@ -337,21 +335,21 @@ _draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rot:
 
 	p -= origin
 
-	add_vertex({p.x, p.y, 0.1}, tint)
-	add_vertex({p.x + dst.w, p.y, 0.1}, tint)
-	add_vertex({p.x + dst.w, p.y + dst.h, 0.1}, tint)
-	add_vertex({p.x, p.y, 0.1}, tint)
-	add_vertex({p.x + dst.w, p.y + dst.h, 0.1}, tint)
-	add_vertex({p.x, p.y + dst.h, 0.1}, tint)
+	add_vertex({p.x, p.y}, tint)
+	add_vertex({p.x + dst.w, p.y}, tint)
+	add_vertex({p.x + dst.w, p.y + dst.h}, tint)
+	add_vertex({p.x, p.y}, tint)
+	add_vertex({p.x + dst.w, p.y + dst.h}, tint)
+	add_vertex({p.x, p.y + dst.h}, tint)
 }
 
 _draw_rectangle :: proc(r: Rect, color: Color) {
-	add_vertex({r.x, r.y, 0.1}, color)
-	add_vertex({r.x + r.w, r.y, 0.1}, color)
-	add_vertex({r.x + r.w, r.y + r.h, 0.1}, color)
-	add_vertex({r.x, r.y, 0.1}, color)
-	add_vertex({r.x + r.w, r.y + r.h, 0.1}, color)
-	add_vertex({r.x, r.y + r.h, 0.1}, color)
+	add_vertex({r.x, r.y}, color)
+	add_vertex({r.x + r.w, r.y}, color)
+	add_vertex({r.x + r.w, r.y + r.h}, color)
+	add_vertex({r.x, r.y}, color)
+	add_vertex({r.x + r.w, r.y + r.h}, color)
+	add_vertex({r.x, r.y + r.h}, color)
 }
 
 _draw_rectangle_outline :: proc(rect: Rect, thickness: f32, color: Color) {

+ 2 - 2
shader.hlsl

@@ -2,7 +2,7 @@ cbuffer constants : register(b0) {
 	float4x4 projection;
 }
 struct vs_in {
-	float3 position : POS;
+	float2 position : POS;
 	float4 color    : COL;
 };
 struct vs_out {
@@ -11,7 +11,7 @@ struct vs_out {
 };
 vs_out vs_main(vs_in input) {
 	vs_out output;
-	output.position = mul(projection, float4(input.position, 1.0f));
+	output.position = mul(projection, float4(input.position, 0, 1.0f));
 	output.color = input.color;
 	return output;
 }