Jump to content

Draw image mirror options

Recommended Posts

I have some image effect and i need the X mirror version so i need to create a second texture.


Context Draw image would be great to have image options like :

- mirror X

- mirror Y

- scaling

Why not rotate ?

Share this post

Link to post

Context:DrawImage() already gives you the ability to scale the image. For mirrored images, you just need to use the negative of the image's vertex X and/or Y coords. Rotating an image requires a little more shader programming - I have used this several times myself as shown here: http://www.leadwerks.com/werkspace/page/viewitem?fileid=317982413


A modified drawimage shader that does what you are asking for:



Example of how to use:

window = Window:Create("draw mirrored or rotated image",0,0,800,600)

context = Context:Create(window)


imageshader = Shader:Load("Shaders/Drawing/drawimage_enhanced.shader")

image = Texture:Load("Materials/Developer/leadwerks.tex")

angle = 0


while window:KeyDown(Key.Escape)==false do

angle = angle +1






oldshader = context:GetShader() -- capture default context shader

context:SetShader(imageshader) -- set the image shader


imageshader:SetFloat("angle", 0) -- set angle to default

imageshader:SetVec2("pivotposition", Vec2(0.0,0.0)) -- set pivot to default

imageshader:SetInt("flip", 0) -- set flip to default

context:DrawImage(image,0,0,400,300) -- draw normal image


imageshader:SetInt("flip", 3) -- mirror in X&Y

context:DrawImage(image,400,300,400,300) --draw flipped image


imageshader:SetFloat("angle", angle) -- set varying angle

imageshader:SetVec2("pivotposition", Vec2(100.0,100.0)) --set pivot to center of image

imageshader:SetInt("flip", 0) -- set flip for normal drawing

context:DrawImage(image,300,200,200,200) -- draw rotating image


context:SetShader(oldshader) -- set back to default context shader





Options for "flip":

  • 0 = normal
  • 1 = X flipped
  • 2 = Y flipped
  • 3 = X & Y flipped


Note: use un-clamped textures if flipping the image with this shader.

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.

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...