Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 2 3 4 5 … 18 Next »
rendertarget issue when drawing text before polys / lines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
rendertarget issue when drawing text before polys / lines
11-06-2021, 10:30 AM,
#1
The17thDoctor Offline
TSCM Average Enjoyer
****
Posts: 1,100
Threads: 249
Joined: Oct 2015
rendertarget issue when drawing text before polys / lines
This one was pretty hard to nail down quite precisely but I found out that when creating fonts and then drawing first a text then polygons, the polygons in a rendertarget, they would not render. 
I also noticed artifacts on lines. When trying to create a line with extreme width, I found out that the line was actually textured like text.

Here is a piece of code illustrating what I found out :

--@name RenderTarget issue
--@author
--@highres

local font = render.createFont("Arial", 27) --Change the size
local rt = rendertarget.create(true, 1024, 1024)

function render.drawRegPoly(x, y, r, s, a)
    local polyTable = {}
    local delta_angle = 360 / s

    a = a or 0
    s = math.floor(s)

    for i = 1, s do
        local vertex_table = {}
        local vec = Vector(0, r):Rotate(Angle(0,(delta_angle*(i-0.5) + a)))
        vertex_table.x = x + vec.x
        vertex_table.y = y + vec.y
        polyTable[#polyTable+1] = vertex_table
    end

    render.drawPoly(polyTable)
end

hook("render", "Render RT", function()
    rt:drawToTexture(function()
        render.clear()
        render.setColor(255, 255, 255)
        render.drawText(font, 10, 10, "This is a sample text")
        for x = 0, 10 do
            for y = 5, 10 do
                render.drawRegPoly(x*102.4 - 51.2, y*102.4 - 51.2, 40, 5, 0)
            end
        end
        render.drawLine(20, 200, 1004, 200, 200)
    end)

    hook("render", "Render RT")
end)

hook("render", "Main Renderer", function()
    render.clear()
    rt:draw(0, 0, 1024, 1024)
end)


I also noticed that the post editor would not support TABs as indentation inside code.

The17thDoctor: Server take me to the most handsome person
srcds_linux: I cant send people to themselves...
Website Find
Reply
11-06-2021, 04:03 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: rendertarget issue when drawing text before polys / lines
You need to reset the texture before rendering a polygon. It's trying to use the last set texture which internally will be the texture used for the text rendering.
-- Reset the current texture to the default.
render.setTexture()
for x = 0, 10 do
    for y = 5, 10 do
        render.drawRegPoly(x*102.4 - 51.2, y*102.4 - 51.2, 40, 5, 0)
    end
end

Also as a side note, drawToTexture() doesn't need to be in a render hook. It's an asynchronous operation that renders separately (hence the function argument).
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread:
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.