Ruki Posted May 2, 2015 Share Posted May 2, 2015 Hi, I recently upgrading from LE2 to LE3. I'd like to draw a section of a texture directly onto the screen for my GUI. My GUI texture contains lots of elements that I need to draw individually. I achieved this in LE2 using an OpenGL extension where I could set vertices and their texture coordinates, but I can't access OpenGL with LE3 can I? I'm using Context->DrawImage(...) but it has no parameters for texture UV.. So how do I do this? With a shader? I've never used shaders before so I'm completely baffled by them :| Please help! Thank you Quote Link to comment Share on other sites More sharing options...
gamecreator Posted May 2, 2015 Share Posted May 2, 2015 Shadmar can do miracles with shaders and I think he helped someone in the last few months with them so I'd search the forums. But the other option is to copy texture pixels yourself. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/texture/texturesetpixels-r338 The examples are down at the moment and oddly this is one of the functions that can really use it. Hope they come back soon. Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 3, 2015 Share Posted May 3, 2015 If you are using c++, I believe you can still use opengl commands. Or you can do it via a shader. Unzip and place this shader in your project's 'Shaders/Drawing' folder: drawimageparts.zip To Use: shader = Shader:Load("Shaders/Drawing/drawimageparts.shader") shader:SetVec2("uvcoords", Vec2(#,#)) shader:SetVec2("zoom", Vec2(#,#)) oldshader = context:GetShader() context:SetShader(shader) context:DrawImage(LoadedImageToDraw, x , y, w, h) context:SetShader(oldshader) Example code showing usage: function App:Start() self.window = Window:Create("Part of Image Example",0,0,800,600) self.context = Context:Create(self.window) self.world = World:Create() self.camera = Camera:Create() self.texture = Texture:Load("Materials/Developer/bluegrid.tex") self.shader = Shader:Load("Shaders/Drawing/drawimageparts.shader")--load shader uvcoords = 1.0 zoom = 2.0 return true end function App:Loop() if (self.window:Closed() or self.window:KeyDown(Key.Escape)) then return false end uvcoords = uvcoords + ((self.window:KeyHit(Key.Up) and 1 or 0) - (self.window:KeyHit(Key.Down) and 1 or 0)) * 0.1 zoom = zoom + ((self.window:KeyHit(Key.Right) and 1 or 0) - (self.window:KeyHit(Key.Left) and 1 or 0)) * 0.1 self.shader:SetVec2("uvcoords", Vec2(uvcoords))--set uvcoords in shader self.shader:SetVec2("zoom", Vec2(zoom))--set zoom in shader Time:Update() self.world:Update() self.world:Render() self.oldshader = self.context:GetShader()--get current shader self.context:SetBlendMode(Blend.Alpha) self.context:SetShader(self.shader)--set new shader self.context:DrawImage(self.texture,405,150,300,300)--clipped/scaled image self.context:SetShader(self.oldshader)--set back to previous shader self.context:DrawImage(self.texture,100,150,300,300)--normal drawimage self.context:DrawText("Press Up/Down to change uvcoords", 0, 2) self.context:DrawText("UVCoords: "..uvcoords..", "..uvcoords, 0, 22) self.context:DrawText("Press Right/Left to change zoom", 0, 42) self.context:DrawText("Zoom: "..zoom..", "..zoom, 0, 62) self.context:SetBlendMode(Blend.Solid) self.context:Sync(); return true end 4 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...
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.