Jump to content

dxDrawImageSection


Recommended Posts

Hello guys! I'm back again with another problem. Here we go:

I'm trying to create a little screenshot of a GUI window with dxUpdateScreenSource. Unfortunately, i think that the screen source doens't render the GUI element even if it is visible. Is there's a way to create a texture element of just the GUI element (not the hole screen) with dxDrawImageSection?

Thank you in advance :D

Link to comment
  
local root = getRootElement ();  
local resourceRoot = getResourceRootElement (getThisResource ()); 
local screenWidth, screenHeight = guiGetScreenSize ();  
local screenSource, windowCapture;  
local yourWindow = guiCreateWindow (...); -- this will be your window. ok?  
  
addEventHandler ("onClientResourceStart", resourceRoot,  
     function ()  
           screenSource = dxCreateScreenSource (screenWidth, screenHeight);  
           assert (screenSource, "Fail to create screen source");  
     end);  
  
-- F7 will capture your window. 
 bindKey ("F7", "down", 
    function ()  
        -- we don´t capture the window if it´s not visible ... 
        if not guiGetVisible (yourWindow) then return; end;  
         
        -- get a capture of the screen. 
        dxUpdateScreenSource (screenSource); 
  
        local posX, posY = guiGetPosition (yourWindow, false); 
        local sizeX, sizeY = guiGetSize (yourWindow, false);   
  
         windowCapture = dxCreateRenderTarget (sizeX, sizeY, true);  
         assert (windowCapture, "Fail to create render target");  
  
        dxSetRenderTarget (windowCapture, true); 
        dxDrawImageSection (0, 0, sizeX, sizeY, posX, posY, sizeX, sizeY, screenSource); 
        dxSetRenderTarget ();  
  
        -- now windowCapture is the capture of your window. 
        -- do whatever you want with it ....  
    end);  
  
  

Link to comment

It didn't work xD I think that it really impossible to take a screenshot of a window! D:

Look at my test, please. It has some comments:

http://i.imgur.com/pSptEMJ.jpg

Edit: Oh i forgot the code:

local root = getRootElement () 
local resourceRoot = getResourceRootElement (getThisResource ()) 
local screenWidth, screenHeight = guiGetScreenSize () 
local screenSource, windowCapture 
local yourWindow = guiCreateWindow (0.5, 0.5, 0.25, 0.3, "Test", true) -- my window is here 
  
-- I've created some scrollbars for controlling the image section u,v when rending! 
local scroll =  guiCreateScrollBar ( 30, 20, 200, 20, true, false, yourWindow) 
local scroll2 =  guiCreateScrollBar ( 30, 55, 200, 20, true, false, yourWindow) 
  
  
addEventHandler ("onClientResourceStart", resourceRoot, 
     function () 
           screenSource = dxCreateScreenSource (screenWidth, screenHeight) 
           assert (screenSource, "Fail to create screen source") 
     end) 
  
-- F7 captured my window 
 bindKey ("F7", "down", 
    function () 
        -- of course it will 
        if not guiGetVisible (yourWindow) then return end 
        
        -- got 
        dxUpdateScreenSource (screenSource) 
  
        posX, posY = guiGetPosition (yourWindow, false) 
        sizeX, sizeY = guiGetSize (yourWindow, false) 
  
        windowCapture = dxCreateRenderTarget (sizeX, sizeY, true) 
        assert (windowCapture, "Fail to create render target") 
        showCursor(true) 
         
        -- set those variables for security reasons 
        prog = 0 
        prog2 = 0 
    end) 
  
     
addEventHandler( "onClientGUIScroll", getRootElement(), function () 
if source == scroll then 
prog =  guiScrollBarGetScrollPosition ( scroll ) 
elseif source == scroll2 then 
prog2 =  guiScrollBarGetScrollPosition ( scroll2 ) 
end 
end) 
  
addEventHandler( "onClientRender", root, 
    function() 
    if windowCapture then 
         dxSetRenderTarget (windowCapture) 
         dxDrawImageSection (0, 0, sizeX, sizeY, prog/100 * (3*sizeX), prog2/100 * (3*sizeY), sizeX, sizeY, screenSource) 
         dxSetRenderTarget () 
          
         dxDrawImage( 50,  50,  sizeX, sizeY, windowCapture ) 
    end 
end) 

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