Jump to content

Help with a "simple" DX issue


Tonyx97

Recommended Posts

Posted

Yes, it's I saw it in a script but I want to re-script it to my way, I don't find exactly the part of the code...

-Advanced programmer C++, openGL, JS, Java y C# 

me :)

Posted

Can be done with a render target (by drawing a bit outside it) or overlapped by a screen source.. No idea which one is more efficient :P

Previously known as MrTasty.

Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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) 

-Advanced programmer C++, openGL, JS, Java y C# 

me :)

Posted

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) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

I still can see the full text when I put alpha if render target on true. I don't know anything about this dx mechanic, so I don't have any conclusions about this issue...

-Advanced programmer C++, openGL, JS, Java y C# 

me :)

Posted

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

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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

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

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