Jump to content
PYL

Starter question on how to draw homemade texture on HUD

Recommended Posts

Hello all, I somehow finally got the permissions to start new threads so I wanted to ask, how do I draw a 2D texture on the screen, given its XY coordinates?

For example I want to draw this texture from file m1.paa or m1.tga or whatever  its name is at _x and _y (in this example _x = 1800 and _y = 900)

In another game I used to:

1. load the archive containing all the textures;

2. load the texture by its index name;

3. draw on screen at x,y with rotation 0-360, alpha 0-255, etc..;

4. relase the texture dictionary.

 

Image example:

kHLOygf.jpg

Share this post


Link to post
Share on other sites
with uiNamespace do 
{  
   picture = findDisplay 46 ctrlCreate ["RscPicture", -1];  
   picture ctrlSetPosition [ 0.345, 0.3,1,1 ]; 
   picture ctrlSetText "images\loadScreen.jpg"; 
   picture ctrlCommit 0; 
};

Something along those lines should do the trick.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Put the following code into a file called "MyDisplay.hpp" (in this case):

class Model3d {
    type = 80;    //type 3D model
    direction[] = {0, 0, 0};
    up[] = {0, 0, 0};
    
    //position
    x = 0;
    y = 0;
    z = 0;
    model = "\core\Empty\empty.p3d"; //default model
    scale = 1.0; //size
};

class MyDisplay { //best practise: file and display class should have the same name
    idd = 99990; //unique ID of the display
    enableSimulation = true; //game continues while the display is visible
    
    class Objects {
        class Model : Model3d { //colon means, class "Model" is derived from class "Model3d"
            idc = 99991; //unique ID of this control
            model = "myCustomModel.p3d";
        };
    };
};

Replace "myCustomModel.p3d" with your model file. I don't know though, if it works for anything else then p3d files.

 

Finally, add the file in your Description.ext under the section "RscTitles", like this:

class RscTitles {
    #include "MyDisplay.hpp"
};

If the hpp file is in another folder than where the Description.ext is in, you need to specify the relative path in the #include line.

  • Like 1

Share this post


Link to post
Share on other sites
with uiNamespace do 
{  
   picture = findDisplay 46 ctrlCreate ["RscPicture", -1];  
   picture ctrlSetPosition [ 0.345, 0.3,1,1 ]; 
   picture ctrlSetText "images\loadScreen.jpg"; 
   picture ctrlCommit 0; 
};

Something along those lines should do the trick.

 

Hi R3vo, thanks for helping me like you did in my array question :D

Before studying the function, I tried to paste it into the LOCAL EXEC, just to get excited, with the following path:

C:\Program Files (x86)\Steam\steamapps\common\Arma 3\Mods\m1.png 

But the interpreter gave me the following error:

U2lD38z.jpg

Why is the value 46 always there in the "display" context? It's also on the BI wiki.

Share this post


Link to post
Share on other sites
I tried to paste it into the LOCAL EXEC, just to get excited, with the following path:
C:\Program Files (x86)\Steam\steamapps\common\Arma 3\Mods\m1.png 

But the interpreter gave me the following error:

 

 

You should add the code in a sqf file in the mission directory.

I don't think you can use absolute path in a code like that.

  • Like 1

Share this post


Link to post
Share on other sites

Amazing, it works! I am so happy now :)

You simply have to give it a paa texture!

0pMYHZC.jpg

Now I will study the uiNamespace function to understand how to remove the drawn texture. Thanks again!

Share this post


Link to post
Share on other sites


with uiNamespace do

{

picture = findDisplay 46 ctrlCreate ["RscPicture", -1];

picture ctrlSetPosition [ 0.345, 0.3,1,1 ];

picture ctrlSetText "images\loadScreen.jpg";

picture ctrlCommit 0;

};

sleep 5;

ctrlDelete (uiNamespace getVariable "picture"); // removes it after 5 secs

  • Like 1

Share this post


Link to post
Share on other sites

You simply have to give it a paa texture!

 

Also works with jpg. Not sure about png though.

  • Like 1

Share this post


Link to post
Share on other sites
Hello, since I found nothing on the BI wiki, is there an opcode which gets the loaded image width and height?

Reading on the BI wiki, I found only the mip maps have a byte which says their size, so you can't load the file and read the corresponding size in width x height.

Share this post


Link to post
Share on other sites

Hi thanks for the reply but maybe I did not explain myself clearly. Let me rephrase the question: let's say you have a texture called tank.paa in C:\Textures and you want to know the file dimensions, is there a way to do it through a command? I know that's possible and doable in a normal programming language by reading the appropriate bytes and so on.  I tried to find some info on the BI wiki about the paa format and discovered the bytes for the dimensions are only for the mipMaps, so I asked here with the hope somebody already ran into a similar problem and found a solution.

Share this post


Link to post
Share on other sites

I'm pretty sure there is no way to find the size of the image, however some information is that as all images in arma 3 to come out looking correct (alpha layer) they need to be a binary value (1x1, 2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024, etc.), so that may be some information.

I might have also misinterpreted your question so sorry if I have

Share this post


Link to post
Share on other sites

Hello again, I'm trying to place this image on the screen but x and y parameters is the top left corner of the image, and not actually the center:

Should be

de6cba460617747.jpg 

But instead is

4c8ddc460617721.jpg 

 

To solve this little problem I tried to move the image of a vector [-w/2,-h/2] (refer to the two images to understand the numbers :) ):

_wantedX = 0; // that's what should be the centerX of the image, 564th pixel from left
_wantedY =  0; // that's what should be the centerY of the image, 243rd pixel from top

_pictureXHalved = 44; // width/2 of the texture
_pictureYHalved = 44; // height/2 of the texture

_actX = _wantedX - ((SafeZoneWAbs/(getResolution select 0))*_pictureXHalved); // 0-((2.42424/1920)*44) = -0.0555555 .. seems pretty ok
_actY = _wantedY - ((SafeZoneHAbs/(getResolution select 1))*_pictureYHalved); // 0-((1.81818/1080)*44) = -0.074074 .... this as well..


with uiNamespace do 
{  
   tst = findDisplay 46 ctrlCreate ["RscPicture", -1];  
   tst ctrlSetPosition [_actX, _actY, 0.75, 1]; 
   tst ctrlSetText "C:\%USERPROFILE%\Desktop\test.paa"; 
   tst ctrlCommit 0; 
};

But sadly it doesn't work even if it should, at least on my sheets so I'm stuck with my first "addon" :( ... Any advice?

Share this post


Link to post
Share on other sites

UI measures in ArmA are NOT pixels or inches or whatever. They are values between 0 and 1 where 0 is basically "nothing" and 1 is the height/width of the screen. There are some special things which make this statement not exactly true, but for ease of explanaition, let's keep say it was that way.

 

Your lines to create _actX and _actY are very long. You shouldn't over complicate things when you don't know where the error is.

 

If you want the top left corner of the image to be outside the screen, you need to use values smaller than 0 (as you already found out). I personally haven't had such problems yet, but I assume, you might get a senseful result, if you use ctrlPosition on the control containing the image, when the dialog is opened. Then you can do your calculation with these values, which come in form of an array [x, y, w, h].

Share this post


Link to post
Share on other sites

UI measures in ArmA are NOT pixels or inches or whatever. They are values between 0 and 1 where 0 is basically "nothing" and 1 is the height/width of the screen. There are some special things which make this statement not exactly true, but for ease of explanaition, let's keep say it was that way.

 

Your lines to create _actX and _actY are very long. You shouldn't over complicate things when you don't know where the error is.

 

If you want the top left corner of the image to be outside the screen, you need to use values smaller than 0 (as you already found out). I personally haven't had such problems yet, but I assume, you might get a senseful result, if you use ctrlPosition on the control containing the image, when the dialog is opened. Then you can do your calculation with these values, which come in form of an array [x, y, w, h].

5fc532460815008.jpg 

Can't be happier and I am very proud of my awful skills!!!! :lol:  I managed to get it to work!: you have to convert texture's width and height from pixels to arma coords calculating how many arma coords is one pixel and then multiplicate it by width and height with:

actualW = (SafeZoneWAbs/(getResolution select 0))*tWidth;
actualH = ((SafeZoneH/(getResolution select 1))* tHeight)*4/3;

Hope that's useful for somebody :)

 

And now comes the fun part: how do I create a function which I can call to not repeat those lines of code?

Something like:

float conv_a2p (float tWidth, float tHeight)
{
    float actualW;
    float actualH;
    actualW = (SafeZoneWAbs/(getResolution select 0))*tWidth;
    actualH = ((SafeZoneH/(getResolution select 1))* tHeight)*4/3;
    return actualW;
    return actualH;
}
.
.
.
w = conv_a2p (tWidth);
h = conv_a2p (tHeight);

Thanks again :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×