Skip to content

Commit 10f2066

Browse files
committed
Pixels mdx
1 parent c42d379 commit 10f2066

3 files changed

Lines changed: 81 additions & 91 deletions

File tree

‎web/src/pages/reference/Pixels.astro‎

Lines changed: 0 additions & 90 deletions
This file was deleted.

‎web/src/pages/reference/Pixels.mdx‎

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

‎web/src/pages/reference/Predefined_variables.mdx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AutoStarlightPage from '@src/components/AutoStarlightPage.astro';
22
import CodeExamplesSection from '@src/components/CodeExamplesSection.astro';
3-
import { Code } from '@astrojs/starlight/components';
43
import { getSeeAlsoLinksFromList } from '@src/utils/general';
54
import SeeAlsoSection from '@src/components/SeeAlsoSection.astro';
65
import {sharedVars, clientVars, sharedEventVars, serverEventVars, sharedTimerVars} from '../../data/predefined_variables'

0 commit comments

Comments
 (0)