Skip to content

Commit 68556ae

Browse files
committed
Texture pixels page
1 parent fccdc5c commit 68556ae

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

web/astro.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ export default defineConfig({
7676
{ label: "Lua API", link: "/reference/Lua_API" },
7777
{ label: "ID Lists", link: "/reference/ID_Lists" },
7878
{ label: "Meta.xml", link: "/reference/Meta.xml" },
79+
{label: 'Predefined variables', link: '/reference/Predefined_variables'},
7980
{
8081
label: "Resource Web Access",
8182
link: "/reference/Resource_Web_Access",
8283
},
83-
{label: 'Predefined variables', link: '/reference/Predefined_variables'},
84+
{label: "Texture pixels", link: '/reference/Pixels'},
8485
{
8586
label: "Functions",
8687
collapsed: true,
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
import AutoStarlightPage from '@src/components/AutoStarlightPage.astro';
3+
import { Code } from '@astrojs/starlight/components';
4+
import { getSeeAlsoLinksFromList } from '@src/utils/general';
5+
import SeeAlsoSection from '@src/components/SeeAlsoSection.astro';
6+
---
7+
8+
<AutoStarlightPage frontmatter={{
9+
template: 'doc',
10+
title: 'Texture pixels',
11+
tableOfContents: {
12+
maxHeadingLevel: 3
13+
}
14+
}}>
15+
16+
<div id="_top"/>
17+
18+
<h3>Pixels</h3>
19+
<hr/>
20+
21+
<ul>
22+
<li>MTA refers to the raw information that a <a href="/reference/texture/">texture</a> contains as <b>pixels</b>.</li>
23+
<li>Pixels can be retrieved from any <a href="/reference/texture/">texture</a> type including <a href="/reference/dxCreateRenderTarget">render targets</a> and <a href="/reference/dxCreateScreenSource">screen sources</a> by using the function <a href="/reference/dxGetTexturePixels">dxGetTexturePixels</a>.</li>
24+
<li>Pixels are just a <a href="/reference/string">string</a> to Lua, so they can be saved to a file or even sent over the internet.</li>
25+
</ul>
26+
27+
<h3>Pixels properties</h3>
28+
<hr/>
29+
<p>Pixels have two properties:</p>
30+
31+
<ul>
32+
<li><b>dimensions</b>: (width and height) which is retrieved by using the function <a href="/reference/dxGetPixelsSize">dxGetPixelsSize</a>.</li>
33+
<li><b>format</b>: (plain,jpeg,png,dds) which is retrieved by using the function <a href="/reference/dxGetPixelsFormat">dxGetPixelsFormat</a></li>
34+
<ul>
35+
<li><b>plain</b> - Fastest and simplest - It's default format of the pixels returned by <a href="/reference/dxGetTexturePixels/">dxGetTexturePixels</a> and the only one that can be used with <a href="/reference/dxSetTexturePixels">dxSetTexturePixels</a>, <a href="/reference/dxGetPixelColor">dxGetPixelColor</a> and <a href="/reference/dxSetPixelColor">dxSetPixelColor</a>. But it also uses a lot of bytes, so internet transfers will be longer. Also can't be read by Photoshop or browsers etc.</li>
36+
<li><b>png</b> - A few less bytes, still quite big for net transfers. Can be saved to a file and read by Photoshop and browsers etc.</li>
37+
<li><b>jpeg</b> - A lot less bytes, so best for net transfers. Can be saved to a file and read by Photoshop and browsers etc.</li>
38+
<li><b>dds</b> - DirectDraw Surface. Game's native texture format with various compressed and uncompressed options. Used to store standard, cube or volume textures. Compressed pixels in this format can be loaded nearly instantly by <a href="/reference/dxCreateTexture">dxCreateTexture</a>.</li>
39+
</ul>
40+
</ul>
41+
42+
<p>To convert between the 3 different formats, use the function <a href="/reference/dxConvertPixels">dxConvertPixels</a>.</p>
43+
44+
<h3>Pixels performance</h3>
45+
<hr/>
46+
47+
<p>Getting/setting pixels from textures is not quick and not something you want to be doing every frame (in <a href="/reference/onClientRender">onClientRender</a> for example).
48+
Setting pixels to a <a href="/reference/dxCreateRenderTarget">render target</a> is <b>especially slow</b>. Pixels are ideal however for transferring composite images built on a render target into a normal texture for later use.
49+
For example, making a custom radar map.</p>
50+
51+
<h3>Examples</h3>
52+
<hr/>
53+
54+
<p>Pixels can also be loaded from any png/jpeg file just like this:</p>
55+
<Code lang="lua" code=`local fileHandler = fileOpen("hello.jpg")
56+
57+
if (not fileHandler) then
58+
return false
59+
end
60+
61+
local fileSize = fileGetSize(fileHandler)
62+
local filePixels = fileRead(fileHandler, fileSize)
63+
64+
fileClose(fileHandler)` />
65+
66+
<p>Pixels can be used to create textures just like this:</p>
67+
<Code lang="lua" code=`local newTexture = dxCreateTexture(pixelsData)`/>
68+
69+
<p>Pixels can be used to save textures just like this:</p>
70+
<Code lang="lua" code=`local texturePixels = dxGetTexturePixels(myRenderTarget)
71+
local texturePixelsConverted = dxConvertPixels(texturePixels, "jpeg")
72+
local fileHandler = fileCreate("piccy.jpg")
73+
74+
if (not fileHandler) then
75+
return false
76+
end
77+
78+
fileWrite(fileHandler, texturePixelsConverted)
79+
fileClose(fileHandler)` />
80+
81+
<SeeAlsoSection seeAlsoLinks={getSeeAlsoLinksFromList([
82+
'reference:texture',
83+
'reference:dxCreateTexture',
84+
'reference:dxCreateRenderTarget',
85+
'reference:dxSetTexturePixels',
86+
'reference:dxGetTexturePixels',
87+
'reference:dxConvertPixels',
88+
])} currentId='' />
89+
90+
</AutoStarlightPage>

0 commit comments

Comments
 (0)