Pārlūkot izejas kodu

Add draw_image_uv()

Daniele Bartolini 11 gadi atpakaļ
vecāks
revīzija
7431d1e70d
3 mainītis faili ar 29 papildinājumiem un 8 dzēšanām
  1. 11 0
      engine/lua/LuaGui.cpp
  2. 14 8
      engine/renderers/Gui.cpp
  3. 4 0
      engine/renderers/Gui.h

+ 11 - 0
engine/lua/LuaGui.cpp

@@ -91,6 +91,16 @@ static int gui_draw_image(lua_State* L)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+static int gui_draw_image_uv(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Gui* gui = stack.get_gui(1);
+	gui->draw_image_uv(stack.get_string(2), stack.get_vector3(3), stack.get_vector2(4), stack.get_vector2(5), stack.get_vector2(6), stack.get_color4(7));
+	return 0;
+}
+
 //-----------------------------------------------------------------------------
 static int gui_draw_text(lua_State* L)
 {
@@ -110,6 +120,7 @@ void load_gui(LuaEnvironment& env)
 
 	env.load_module_function("Gui", "draw_rectangle",	gui_draw_rectangle);
 	env.load_module_function("Gui", "draw_image",		gui_draw_image);
+	env.load_module_function("Gui", "draw_image_uv",	gui_draw_image_uv);
 	env.load_module_function("Gui", "draw_text",		gui_draw_text);
 }
 

+ 14 - 8
engine/renderers/Gui.cpp

@@ -188,6 +188,12 @@ void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4&
 
 //-----------------------------------------------------------------------------
 void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color)
+{
+	draw_image_uv(material, pos, size, Vector2(0, 0), Vector2(1, 1), color);
+}
+
+//-----------------------------------------------------------------------------
+void Gui::draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color)
 {
 	Renderer* r = device()->renderer();
 	TransientVertexBuffer tvb;
@@ -199,23 +205,23 @@ void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& si
 	float* verts = (float*) tvb.data;
 	verts[0] = pos.x;
 	verts[1] = pos.y;
-	verts[2] = 0;
-	verts[3] = 0;
+	verts[2] = uv0.x;
+	verts[3] = uv0.y;
 
 	verts[4] = pos.x + size.x;
 	verts[5] = pos.y;
-	verts[6] = 1;
-	verts[7] = 0;
+	verts[6] = uv1.x;
+	verts[7] = uv0.y;
 
 	verts[8] = pos.x + size.x;
 	verts[9] = pos.y + size.y;
-	verts[10] = 1;
-	verts[11] = 1;
+	verts[10] = uv1.x;
+	verts[11] = uv1.y;
 
 	verts[12] = pos.x;
 	verts[13] = pos.y + size.y;
-	verts[14] = 0;
-	verts[15] = 1;
+	verts[14] = uv0.x;
+	verts[15] = uv1.y;
 
 	uint16_t* inds = (uint16_t*) tib.data;
 	inds[0] = 0;

+ 4 - 0
engine/renderers/Gui.h

@@ -58,6 +58,10 @@ struct Gui
 	/// @note Higher values of pos.z make the object appear in front of other objects.
 	void draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color = Color4::WHITE);
 
+	/// Draws an image with the given @a material and @a uv0 and @a uv1 coordinates.
+	/// @note Higher values of pos.z make the object appear in front of other objects.	
+	void draw_image_uv(const char* material, const Vector3& pos, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color4& color = Color4::WHITE);
+
 	/// Draws the text @a str with the given @a font and @a font_size.
 	/// @note Higher values of pos.z make the object appear in front of other objects.
 	void draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color = Color4::WHITE);