Get basic shader wroking on a text

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Valdaria
Prole
Posts: 1
Joined: Thu Nov 08, 2018 12:10 am

Get basic shader wroking on a text

Post 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

User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Get basic shader wroking on a text

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

Who is online

Users browsing this forum: Ahrefs [Bot] and 168 guests