Jump to content

Draw on buffer to apply to sprite


Rick
 Share

Recommended Posts

Rephrasing the question: How can I make the texture background transparent so the only thing I see is my text?

 

    local shader = Shader:Load("Shaders/model/diffuse.shader")
    local currentBuff = Buffer:GetCurrent()
    local mat = Material:Create()
    mat:SetShader(shader)
    local sprite = Sprite:Create()
    sprite:SetViewMode(0)
    sprite:SetMaterial(mat)
    local buffer = Buffer:Create(20, 20, 1, 1)
    
    -- draw the text on the buffer
    Buffer:SetCurrent(buffer)
    self.context:SetBlendMode(Blend.Alpha)
    self.context:SetColor(Vec4(1, 0, 0, 1))
    self.context:DrawText("Hello", 0, 0)
    local tex = buffer:GetColorTexture(0)
    mat:SetTexture(tex, 0)
    Buffer:SetCurrent(currentBuff)

 

Link to comment
Share on other sites

For me the text is red (given, it's a very dark red...). You should be able to make it more visible by using "diffuse+normal+emission+alphamask.shader" and binding the texture to both, channels 0 (diffuse) and 4 (emission):

i.e.:

    local shader = Shader:Load("Shaders/model/diffuse+normal+emission+alphamask.shader")
    local currentBuff = Buffer:GetCurrent()
    local mat = Material:Create()
    mat:SetShader(shader)
    local sprite = Sprite:Create()
    sprite:SetViewMode(0)
    sprite:SetMaterial(mat)
    local buffer = Buffer:Create(20, 20, 1, 1)
    
    -- draw the text on the buffer
    Buffer:SetCurrent(buffer)
    self.context:SetBlendMode(Blend.Alpha)
    self.context:SetColor(Vec4(1, 0, 0, 1))
    self.context:DrawText("Hello", 0, 0)
    local tex = buffer:GetColorTexture(0)
    mat:SetTexture(tex, 0)
    mat:SetTexture(tex, 4)
    Buffer:SetCurrent(currentBuff)

That should make it more crisp.

  • Upvote 1
Link to comment
Share on other sites

That worked thank you much.

Any ideas on how to fade out the text? I can change the alpha of SetColor() but currently I clear the buffer but that results in a white buffer it seems as the sprite goes all white when I call buffer:Clear(). It's like I need to clear it with no color. Currently I call Clear() then SetColor() where the alpha is going down from 1 to 0 and redrawing the text. However, as stated all I see is white.

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...