Page 1 of 1

Get basic shader wroking on a text

Posted: Thu Nov 08, 2018 12:22 am
by Valdaria
Hi,

I wondered how the texture from Texts are created because I tried to apply a really basic shader on a text and it's a total mess.
It applies as intended on an image


https://prnt.sc/lfoddt
The same shader is applied to the text and image

I'm using love 11.1

Code: Select all

function love.load()
  img = love.graphics.newImage("img.png") 
  myShader = love.graphics.newShader[[
    vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
        if(texture_coords.x > 0.5){
          return vec4(1.0,0.0,0.0,Texel(texture, texture_coords).a);//red
        }
        else
        {
          return vec4(0.0,0.0,1.0,Texel(texture, texture_coords).a);//blue
        }

    }
    ]]
  f = love.graphics.newFont("font.ttf" )
  t = love.graphics.newText(f, "It will probably not working")
end


function love.draw()
  love.graphics.setShader(myShader)
  love.graphics.draw(img, 300, 200, 0, 5, 5)
  love.graphics.draw(t, 300, 400)
  
  love.graphics.setShader()
end


Re: Get basic shader wroking on a text

Posted: Thu Nov 08, 2018 2:52 am
by pgimeno
Hello, Valdaria, welcome to the forums.

AFAIK, text objects are basically like a SpriteBatch. I don't know how the image is generated, but I know the characters are basically quads of that image.

I think that the effect you're trying to accomplish can be obtained by drawing the text to a canvas in advance.