Page 1 of 1

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

Posted: Sat Jan 11, 2014 6:37 am
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:

Re: I made a shader but only works on image

Posted: Sat Jan 11, 2014 10:10 am
by veethree
Draw the image and the rectangle to a canvas, Apply the shader to the canvas.

Re: I made a shader but only works on image

Posted: Sat Jan 11, 2014 4:21 pm
by slime
The texture coordinates for primitive shapes (rectangles, etc.) are always 0,0.

Re: I made a shader but only works on image

Posted: Sun Jan 12, 2014 11:28 am
by Dashchan
Thank you guys!
I'll try using a canvas.