Jump to content
Leadwerks Community

Recommended Posts

Posted

How i can rotate 2d image? I have this code, but it rotates viewport not image.

Script.Tx = Texture:Load("Materials/Compass/compass.tex")
function Script:Start()
self.camera = Camera:Create()
self.camera:SetRotation(self.entity:GetRotation(true))
self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,1.8,0))
end
function Script:PostRender()
local context=Context:GetCurrent()
local rot=Vec3()
rot=self.entity:GetRotation(true)
context:SetRotation(rot.y)
context:DrawImage(self.Tx,100,100,10,100)
end

Posted

Thanks for reply. I tried the code, downloaded the shader, but it didnt worked for me as it should. Dont know why, but the shader wouldnt load into engine. I copied the shader contents into "drawimage.shader" that comes with engine, and then it worked. Theres my code:

Script.Tx = Texture:Load("Materials/Compass/compass.tex")
function Script:Start()
self.camera = Camera:Create()
self.camera:SetRotation(self.entity:GetRotation(true))
self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,1.8,0))
self.imageshader = Shader:Load("Shaders/Drawing/drawimage.shader")
end
function Script:PostRender()
local context=Context:GetCurrent()
context:SetShader(imageshader)
self.imageshader:SetVec2("pivotposition", Vec2(100.0,100.0))
self.imageshader:SetFloat("angle",45)
local rot=Vec3()
rot=self.entity:GetRotation(true)
--context:SetRotation(rot.y)
context:DrawImage(self.Tx,100,100,200,200)
context:DrawLine(100,100,200,200)
end

 

Any ideas what could be wrong?

Posted

Two things off the bat that I see is that you didn't load the custom shader and then you did not set the context's shader to it.

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

should be:

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

 

and

 

context:SetShader(imageshader)

should be:

context:SetShader(self.imageshader)

 

Also, the correct syntax for the PostRender is:

function Script:PostRender(context)

 

Also I would recommend capturing the current context shader prior to setting to the custom and then setting it back prior to ending the PostRender:

Script.Tx = Texture:Load("Materials/Compass/compass.tex")

 

function Script:Start()

self.camera = Camera:Create()

self.camera:SetRotation(self.entity:GetRotation(true))

self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,1.8,0))

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

end

 

function Script:PostRender(context)

local oldshader = context:GetShader()

context:SetShader(self.imageshader)

self.imageshader:SetVec2("pivotposition", Vec2(100.0,100.0))

self.imageshader:SetFloat("angle",45)

context:DrawImage(self.Tx,100,100,200,200)

context:SetShader(oldshader)

context:DrawLine(100,100,200,200)

end

 

EDIT: I see you edited your post. I do not recommend that you overwrite an existing standard shader that comes with the engine as there are possiblities of it getting overwritten from engine updates. If you use the code i posted, it will work without the need to overwrite existing shaders.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

Nice shader macklebee. Just made a (really) simple compass in PS for anyone to use/play with.

I wrote the instructions out so new people can follow it.

Extract the zip file into the Materials directory.

 

This goes at the top of FPSPlayer.lua:

 

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

Script.Tx = Texture:Load("Materials/compass.tex")

Script.Tx2 = Texture:Load("Materials/compasspointer.tex")

 

This goes in FPSPlayer.lua's PostRender function after context:SetBlendMode(Blend.Alpha)

 

context:DrawImage(self.Tx,100,100,200,200)

local oldShader = context:GetShader()

context:SetShader(self.imageshader)

local angle = self.entity:GetRotation(true)

self.imageshader:SetVec2("pivotposition", Vec2(100.0,100.0))

self.imageshader:SetFloat("angle", angle.y)

context:DrawImage(self.Tx2,100,100,200,200)

context:SetShader(oldShader)

 

If you're using the release version (4.2) where the SetInput bug exists change the following line or player rotation won't be updated when standing still:

self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true)

 

to

 

self.entity:SetInput(self.camRotation.y, playerMovement.z + 0.0000001, playerMovement.x, jump , false, 1.0, 0.5, true)

compass.zip

post-12583-0-04642200-1485121050.gif

  • Upvote 3

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

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.

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