(Solved)I made a shader but only works on image

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Dashchan
Prole
Posts: 4
Joined: Sun Sep 15, 2013 10:46 am

(Solved)I made a shader but only works on image

Post by Dashchan »

Code: Select all

function love.load()
	love.window.setMode(800,450)

	local src = [[    
      vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc)
      {
      	return vec4(tc.x, tc.y, 1.0, 1.0);
      }
	]]

	effect = love.graphics.newShader(src)

	img = love.graphics.newImage("img.png")
end

function love.draw()
	love.graphics.setShader()
  love.graphics.setColor(255, 255, 255)

	--love.graphics.draw(bg, 0, 0)

	love.graphics.setShader(effect)
  love.graphics.draw(img, 400, 200)  
  love.graphics.rectangle('fill',0, 0, 200, 200)

end

function love.update(dt)
	if love.keyboard.isDown('escape') then
		 love.event.quit()
	end
end
http://puu.sh/6gT59.jpg

it works on img but doesnt work on rectangle
can anyone help me? :shock:
Last edited by Dashchan on Sun Jan 12, 2014 11:29 am, edited 1 time in total.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: I made a shader but only works on image

Post by veethree »

Draw the image and the rectangle to a canvas, Apply the shader to the canvas.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: I made a shader but only works on image

Post by slime »

The texture coordinates for primitive shapes (rectangles, etc.) are always 0,0.
User avatar
Dashchan
Prole
Posts: 4
Joined: Sun Sep 15, 2013 10:46 am

Re: I made a shader but only works on image

Post by Dashchan »

Thank you guys!
I'll try using a canvas.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests