Jump to content

Using dxCreateTexture with raw data makes textures blurry


JeViCo

Recommended Posts

Side by side comparsion of 20x20 info icon:

*Click here*

Example code:

local iconPath = "info.png"

local f = fileOpen(iconPath)
local rawData = fileRead(f, fileGetSize(f))
fileClose(f)

local pathTex = dxCreateTexture(iconPath)
local rawDataTex = dxCreateTexture(rawData)
local size = 20

addEventHandler("onClientRender", root, function()
	dxDrawImage(0, 0, size, size, pathTex) -- texture created from path (the left one)
	dxDrawImage(size, 0, size, size, rawDataTex) -- texture created from raw data (the right one)
end)

Does anyone know how to fix this?

Link to comment
37 minutes ago, JeViCo said:

Side by side comparsion of 20x20 info icon:

*Click here*

Example code:

local iconPath = "info.png"

local f = fileOpen(iconPath)
local rawData = fileRead(f, fileGetSize(f))
fileClose(f)

local pathTex = dxCreateTexture(iconPath)
local rawDataTex = dxCreateTexture(rawData)
local size = 20

addEventHandler("onClientRender", root, function()
	dxDrawImage(0, 0, size, size, pathTex) -- texture created from path (the left one)
	dxDrawImage(size, 0, size, size, rawDataTex) -- texture created from raw data (the right one)
end)

Does anyone know how to fix this?

hello! @JeViCo welcome to forum,set mipmap option to false
 

element dxCreateTexture ( string pixels / string filepath [, string textureFormat = "argb", bool mipmaps = true, string textureEdge = "wrap" ] )

https://wiki.multitheftauto.com/wiki/DxCreateTexture
 

Link to comment
  • 2 weeks later...

 

<script src="blabla.lua" type="client" cache="false"/>

Scripts are preserved with "cache" 
a player can take a screenshot and edit the picture thanks to photoshop and get it,but if you want to keep your lua scripts use cache tag in meta.xml

Edited by Shady1
Link to comment
  • 2 weeks later...
10 hours ago, JeViCo said:

I'm not sure that this is the answer i was expecting but still, thanks. I'll probably open an issue on GitHub later on

after you created your texture 

it saves your pixels in memory

then you can just delete your texture file with `fileDelete`

but your clients have to download your texture file always when they are trying to connect to server

------

local path = "img.png";

if fileExists(path) then

    local texture = dxCreateTexture(path);

    fileDelete(path);

end

------

but why you are trying to do that?

i think imgs and sounds are not important that much

but your code is

your client can extract that image with just taking an screenshot

with this you torture both your client and yourself

Link to comment
On 21/01/2023 at 11:54, Mobin said:

but why you are trying to do that?

Quick example 1: I drew a whole gta map from scratch all by myself and put a lot of effort into it
Quick example 2: I drew a set of unique liveries for vehicles and i don't want them to be anywhere else

Link to comment
4 hours ago, JeViCo said:

Quick example 1: I drew a whole gta map from scratch all by myself and put a lot of effort into it
Quick example 2: I drew a set of unique liveries for vehicles and i don't want them to be anywhere else

i can't find other ways for that

only way is loading texture by file path `dxCreateTexture("img.png")` to let cpp load that file

you can delete the file after you loaded that but it happens when script loaded if player download the img and left the server before it loads the client can save that file at other place

Link to comment
  • Moderators

@JeViCo

Just wondering if cutting the process in smaller parts would give you the same effect (you never know):

local width, height =  dxGetPixelsSize ( rawData )

local rawDataTex = dxCreateTexture(width, height)

dxSetTexturePixels (rawDataTex, rawData)

 

  • Like 1
Link to comment

Maybe this has something to do with non-power-of-2 dimensions? If so, then 16x16 or 32x32 would give a better result than 20x20.

I don't see an obvious reason why it would be like that, since if it can properly load the data coming from a file, it should be able to load the same data coming from a string. But it all depends on what's happening inside dxCreateTexture. I guess there might be some indirection involved, like drawing the texture to a buffer and then reading it to produce the final texture, which could degrade the quality for non-power-of-2 textures.

  • Thanks 1
Link to comment
On 24/01/2023 at 02:12, IIYAMA said:

@JeViCo

Just wondering if cutting the process in smaller parts would give you the same effect (you never know):

local width, height =  dxGetPixelsSize ( rawData )

local rawDataTex = dxCreateTexture(width, height)

dxSetTexturePixels (rawDataTex, rawData)

 

Nah. It seems to be a texture size-related issue

5 hours ago, Reyomin said:

Maybe this has something to do with non-power-of-2 dimensions? If so, then 16x16 or 32x32 would give a better result than 20x20.

I don't see an obvious reason why it would be like that, since if it can properly load the data coming from a file, it should be able to load the same data coming from a string. But it all depends on what's happening inside dxCreateTexture. I guess there might be some indirection involved, like drawing the texture to a buffer and then reading it to produce the final texture, which could degrade the quality for non-power-of-2 textures.

Technically we found the solution to the problem of this topic. Thank you for great explanation

Texture is stretching somewhere and actual problem hides somewhere deep in the source code. Any furher code-related discussion will be placed on Github

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