render.Capture

From Garry's Mod
Jump to: navigation, search
 render.Capture( )

Contents

Description

Captures a part of the current render target and returns the data as a binary string in the given format.

Since the pixel buffer clears itself every frame, this will return a black screen outside of render hooks. To capture the user's final view, use GM:PostRender. This will not capture the Steam overlay or third-party injections (such as the Discord overlay, Overwolf, and advanced cheats) on the user's screen.

BUG

This sets the alpha channel incorrectly in PNG mode, causing the foreground to be rendered almost completely transparent.

Issue Tracker: #2571

Arguments

table captureData

Parameters of the capture. See RenderCaptureData structure.

Returns

string

binaryData

Examples

Example

How you could use this to save a picture of your screen.

local ScreenshotRequested = false
function RequestAScreenshot()
	ScreenshotRequested = true
end

-- For the sake of this example, we use a console command to request a screenshot
concommand.Add( "make_screenshot", RequestAScreenshot )

hook.Add( "PostRender", "example_screenshot", function()
	if ( !ScreenshotRequested ) then return end
	ScreenshotRequested = false

	local data = render.Capture( {
		format = "jpeg",
		quality = 70, //100 is max quality, but 70 is good enough.
		h = ScrH(),
		w = ScrW(),
		x = 0,
		y = 0,
	} )
	local f = file.Open( "Image.jpg", "wb", "DATA" )
	f:Write( data )
	f:Close()
end )

Output:

You should now have Image.jpg in your garrysmod/garrysmod/data folder, containing a screenshot.
Personal tools
Navigation