Jump to content

best way to slide content in renderTarget ?


Overkillz

Recommended Posts

Hello dear community today Im trying to work with renderTargets to make a list with some rows.

However, I want to limit it with the sizeY by screenSizeY *0.5, It is allow me to not to draw all the rows. But I want that if the player press some keys he is allowed to slide it up/down.

Sadly, while sliding it up/down, due to the renderTarget it causes a some draw problems. Just see the images. I tried to create the renderTarget again inside the drawFunction, but I already know that it will cause performance issues. So, thats why Im asking for the best way to fix it

I already tried to use 

dxSetBlendMode("modulate_add")
dxSetBlendMode("blend") 
local sX,sY = guiGetScreenSize()
local sizeX,sizeY,maxSizeY = sX*0.6,sY*0.25,sY*0.95
local font = "default-bold"
local fontHeight = dxGetFontHeight(1,font) + 5

local myRenderTarget = dxCreateRenderTarget(sizeX,maxSizeY) 

local fakePlayersTable = {}
local posY = 0

for i=1,50 do
	table.insert(fakePlayersTable,"FakePlayer_"..i)
end

function drawTest()
	if getKeyState( "lshift" ) == true then
		posY = posY + 3
	elseif getKeyState( "lctrl" ) == true then
		posY = posY - 3
	end
	dxSetRenderTarget( myRenderTarget ) 
	local n = 0
	for id,player in ipairs(fakePlayersTable) do
		dxDrawText(player,0,posY + fontHeight*(n) )
		n = n + 1
	end
	dxSetRenderTarget() 
	dxDrawImage( sX/2-sizeX/2,  sY/2 - maxSizeY / 2,  sizeX, maxSizeY, myRenderTarget )
end
addEventHandler("onClientRender",root,drawTest)

oHRx1eh.jpg

wnehvBG.jpg

Thanks for reading, bets regards.

Link to comment
  • Moderators

@Overkillz

dxSetRenderTarget( myRenderTarget, true ) 

Syntax:

bool dxSetRenderTarget ( [ element renderTarget, bool clear = false ] )

 

The stuff you have drawn before on the paper, will not just clear itself. A render target is like a piece of paper of the REAL WORLD. Once you have drawn on it, you need an eraser to clean it.

 


 

There are two things you can do.

  • Clear the render target
  • Or paint it black again with a rectangle.

 

If it is just text on it, clearing the render target will do the job. But if you have multiple components on it, which you do not want to re-draw very frame on the render-target, then it might be handy to paint selected area's black.

 

See also blend mode:

overwrite : The source textures are overwritten. This can be useful for clearing render targets

https://wiki.multitheftauto.com/wiki/DxSetBlendMode

(Haven't used it before.)

 


 

Also keep in minder that you can also use two render targets. One you can update when the text changes and one to move the frame.

 

 

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...