Jump to content
Roland

LUA - Drawing a tiled image

Recommended Posts

Is there any draw texture function that can tile the texture, or do I have to make a loop drawing my texture to create the effect. Context:DrawTexture does not seem to handle tiling.

Share this post


Link to post

For this I would just make a slight change to the existing shader used for DrawImage by adding a scale uniform to it since the command GraphicsDriver::TileImage is not official and is not available for lua. Also the post that TJ links to asked about clipping a drawn image. It could be done via drawing to a buffer but you could also just make another slight modification to the 'drawimage.shader' by adding another uniform to set the X&Y start of the clipped image used in conjunction with the scale uniform.

 

Fragment portion of the 'drawimage.shader':

#version 400

uniform vec4 drawcolor;
uniform sampler2D texture0;
uniform vec2 scale = vec2(1.0,1.0); //added for tiling
uniform vec2 clipcoords = vec2(0.0,0.0); //added for clipping

in vec2 vTexCoords0;

out vec4 fragData0;

void main(void)
{
   fragData0 = drawcolor * texture(texture0, vTexCoords0 *scale + clipcoords);
}

 

 

Then to use:

  • shader = Shader:Load("Shaders/Drawing/drawimage.shader")
  • shader:SetVec2("scale", Vec2(#,#)) --the default is vec2(1.0,1.0) so it doesn't effect the normal drawimage command
  • shader:SetVec2("clipcoords", Vec2(#,#)) --the default is vec2(0.0,0.0) so it doesn't effect the normal drawimage command
  • context:DrawImage()

 

Edit -- I changed the above shader code to make the scale a Vec2 value in case you only wished to tile the image in one direction.

 

Edit2 - I changed the fragData0 line to multiply by scale prior to adding the clipccords.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...