YouGroove Posted October 16, 2015 Share Posted October 16, 2015 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 ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
macklebee Posted October 17, 2015 Share Posted October 17, 2015 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: drawimage_enhanced.zip 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 context:SetColor(1,0,1) context:Clear() context:SetColor(1,1,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 context:Sync(true) end 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. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
YouGroove Posted October 17, 2015 Author Share Posted October 17, 2015 This shader should be part of LE3. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
shadmar Posted October 17, 2015 Share Posted October 17, 2015 This might help for rotate http://www.leadwerks.com/werkspace/topic/13045-rotating-shader-help/#entry92578 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.