Jump to content

Help with a "simple" DX issue


Tonyx97

Recommended Posts

You don't need a screen source at all. A render target will do just fine.

Create the target once (not on render), set it as the target on render, draw the text to it, reset the target and then draw the render target with dxDrawImageSection.

Link to comment

I tried your steps JR but I didn't get it... in this image http://gyazo.com/13bf30d452c051438817a2919bbf94c2 I put the box over the text like I want, when I change the dxCreateRenderTarget alpha to true the text is still shown. Here the little code:

target = dxCreateRenderTarget ( 100, 100, false ) 
  
function onClientRendere () 
  
    dxSetRenderTarget (target, true) 
     
    dxDrawText ( "TEEEEEEEEEEEEEST", 500, 550, 500, 500, tocolor(255,255,255,255), 2, "sans", "left", "center", false, false, true, false ) 
     
    dxSetRenderTarget() 
  
    dxSetBlendMode("modulate_add") 
    dxDrawImageSection(650, 500, 50, 50, 0, 0, 50, 50, target, 0, 0, 0, tocolor(255,255,255,255), true) 
    dxSetBlendMode("blend") 
     
end 
addEventHandler ("onClientRender", getRootElement(), onClientRendere) 

Link to comment

You're using the full width and height in dxDrawImageSection that's why it's drawing the full text, try this:

target = dxCreateRenderTarget ( 100, 100, false ) 
  
function onClientRendere () 
  
    dxSetRenderTarget (target, true) 
    dxSetBlendMode("modulate_add") 
    dxDrawText ( "TEEEEEEEEEEEEEST", 500, 550, 500, 500, tocolor(255,255,255,255), 2, "sans", "left", "center", false, false, true, false ) 
    dxSetRenderTarget() 
    dxSetBlendMode("add") 
    dxDrawImageSection(650, 500, 50, 50, 0, 0, 50, 25, target, 0, 0, 0, tocolor(255,255,255,255), true) 
    dxSetBlendMode("blend") 
end 
addEventHandler ("onClientRender", getRootElement(), onClientRendere) 

Link to comment

After experimenting with it, I figured it out. For some reason, the postGUI parameter in dxDrawText causes the text to be drawn to the screen and not the render target. I also tweaked dxDrawImageSection to achieve the effect you want.

Here's the code:

target = dxCreateRenderTarget ( 500, 500, true ) 
function onClientRendere () 
    if (target) then 
        dxSetRenderTarget (target, true) 
        dxSetBlendMode("modulate_add") 
        dxDrawText ( "TEEEEEEEEEEEEEST", 0, 0, 500, 100, tocolor(255,255,255,255), 2, "sans", "left", "top", false, false, false, false ) 
        dxSetRenderTarget() 
        dxSetBlendMode("add") 
        dxDrawImage(500, 200, 500, 500, target); --Draw the full render target to check the diff, you can remove this after testing 
        dxDrawImageSection(500, 100, 500, 15, 0, 0, 500, 15, target, 0, 0, 0, tocolor(255,255,255,255), true) 
        dxSetBlendMode("blend") 
    end 
end 
addEventHandler ("onClientRender", getRootElement(), onClientRendere) 

Here's an image:

b8JgsYX.jpg?1

Link to comment

This is how I do it:

sWidth, sHeight = guiGetScreenSize() --Get the screen sizes X and Y 
X, Y = 150, 16 --Create a variable presenting the X and Y sizes 
cTarget = dxCreateRenderTarget(X, Y, true) --Create a render target (box) where the text should be drawn in 
  
function testFunction() 
    if (cTarget ~= false) and (cTarget ~= nil) then 
        dxSetRenderTarget(cTarget, true) --Set the render target to cTarget so we are going to draw in that box 
        dxSetBlendMode("modulate_add") --Set the blend mode to "modulate_add" 
        dxDrawText("This is a test message", 0, -20, X, Y, tocolor(0, 255, 0, 255), 1, "sans", "center", "center", true, false, false) --Create a text in the render target. Lets cut the text in half by setting the position to -20 
        dxSetBlendMode("blend") --Set the blend mode to "blend" 
        dxSetRenderTarget() --Stop drawing in the render target 
        dxSetBlendMode("add") --Set the blend mode to "add" 
        dxDrawImage((sWidth/2)-(X/2), ((sHeight/2)-(Y/2))+20, X, Y, cTarget, 0, 0, 0, tocolor(255, 255, 255, 255), true) --Now lets draw an image of our made render target. Lets put the text in the middle of the screen (Add +20 because we removed -20 by the text's position to cut it in half) 
        dxSetBlendMode("blend") --Set the blend mode to "blend" 
    end 
end 
  
addEventHandler("onClientRender", root, testFunction) 

EDIT: You were just earlier than me JR10 :P

Link to comment
@Et-win Why do you reset the blend mode twice? Also, this doesn't really address his issue, nor what caused the bug, he wants dxDrawImageSection not to draw the full image.

Ripped it out of my other script, I did draw other stuff between the first reset so that will explain why. Anyway, this would give the same effect as your script.

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