Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Summer Special
      2. The Diamond Casino Heist
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA VI

      1. St. Andrews Cathedral
    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

kr0wns

[C++] Draw Sprite

Recommended Posts

kr0wns

Hey guys, how to do this work? nothing appears on the screen.

GRAPHICS::DRAW_SPRITE("CommonMenu", "MP_SpecItem_Weed", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);
Edited by kr0wns

Share this post


Link to post
Share on other sites
ChOcOsKiZo

 

Hey guys, how to do this work? nothing appears on the screen.

GRAPHICS::DRAW_SPRITE("CommonMenu", "MP_SpecItem_Weed", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);

on ps3 i run it in a loop

Share this post


Link to post
Share on other sites
kr0wns

 

 

Hey guys, how to do this work? nothing appears on the screen.

GRAPHICS::DRAW_SPRITE("CommonMenu", "MP_SpecItem_Weed", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);

on ps3 i run it in a loop

 

but the code is correct?

Edited by kr0wns

Share this post


Link to post
Share on other sites
ChOcOsKiZo

 

 

 

Hey guys, how to do this work? nothing appears on the screen.

GRAPHICS::DRAW_SPRITE("CommonMenu", "MP_SpecItem_Weed", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);

on ps3 i run it in a loop

 

but the code is correct?

 

yup looks like it's correct :)

http://pastebin.com/4J5tSrEM

 

Edited by ChOcOsKiZo

Share this post


Link to post
Share on other sites
frangershwing

x,y,z = 0.5f, 0.5f, 0.5f

means that you're placing the sprite at the "origin", basically - try player's coordinates instead

Vector3 coords = ENTITY::GET_ENTITY_COORDS( PLAYER::PLAYER_PED_ID(), TRUE);

x,y,z = coords.x, coords.y, coords.z

Share this post


Link to post
Share on other sites
maksimpalinski
Posted (edited)

GRAPHICS::DRAW_SPRITE("CommonMenu", "MP_SpecItem_Weed", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);

 

Wehre must be the destination/path from the diretory "CommonMenu" ??

Can someone please help me

Edited by maksimpalinski

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)

Your text is almost impossible to read, can you change the colour to make it all white?

 

As for your question, CommonMenu is a texture dictionary, a ytd file. Run OpenIV, press Control + F3 and type commonmenu into the search box. That will list all the locations where you can find that file.

 

"MP_SpecItem_Weed" is the name of a texture inside that CommonMenu texture dictionary.

Edited by LeeC22

Share this post


Link to post
Share on other sites
maksimpalinski

okay okay, I understand, and I can just import my own sprite like a mod menu header into some dictonarys right?

 

Share this post


Link to post
Share on other sites
maksimpalinski

I cant load my own sprite, i see just white screen...

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)
14 minutes ago, maksimpalinski said:

I cant load my own sprite, i see just white screen...

If you want to load your own sprite, it has to be inside a texture dictionary (a ytd file) inside script_txds.rpf for it to work and you have to request the dictionary before you can use it.

 

So imagine you have your own texture dictionary called mysprites.ytd. You place that file inside script_txds.rpf.

 

Inside mySprites.ytd, you have a texture called mySpriteTexture.

 

To draw that, you would do something like this:-

        if (Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, "mySprites"))
        {
            Function.Call(Hash.DRAW_SPRITE, "mySprites", "mySpriteTexture", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);
        }
        else
        {
            Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, "mySprites", false);
        }

You have to call that every frame, if you don't tell a sprite to draw each frame, then nothing is displayed. The bit inside the else will keep requesting the dictionary until it has loaded, then it will start drawing the sprite.

 

That's C#... I don't code in C++ but you should be able to work out what the C++ code should be from that.

Edited by LeeC22
  • Like 1

Share this post


Link to post
Share on other sites
maksimpalinski

I dont understand it right... Can u please tell me, how i have to name my file and where i have to put it in...

Please

I just want to display a custom header on my mod menu for GTA  5

 

Share this post


Link to post
Share on other sites
LeeC22
35 minutes ago, LeeC22 said:

If you want to load your own sprite, it has to be inside a texture dictionary (a ytd file) inside script_txds.rpf for it to work and you have to request the dictionary before you can use it.

 

So imagine you have your own texture dictionary called mysprites.ytd. You place that file inside script_txds.rpf.

 

Inside mySprites.ytd, you have a texture called mySpriteTexture.

I can't write it any clearer than that.

 

It tells you the name of the texture dictionary:- mysprites.ytd

it tells you the name of a sprite:- mySpriteTexture but you could call it myModMenuHeaderSprite if you wanted to.

it tells you the name of the rpf file it has to go into:- script_txds.rpf

  • Like 1

Share this post


Link to post
Share on other sites
maksimpalinski

Okay thanks a lot dude...

 

Share this post


Link to post
Share on other sites
maksimpalinski

I did it same like u said, but I just get a white rectagle ://

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)
7 hours ago, maksimpalinski said:

I did it same like u said, but I just get a white rectagle ://

That doesn't tell me much.

 

What code are you using to draw it?

Is it a big rectangle?

Is it a small rectangle?

Is it just white or is there something else in there as well?

What should it actually be drawing?

What format is your sprite in inside the ytd file? DXT1, DXT5, A8R8G8B8?

Is it a JPG or a PNG... or a DDS?

 

I won't be able to answer for another 6 or 7 hours but the more you can tell us, the more we know and can try and help.

 

Edit: It occurred to me this morning that it hadn't been mentioned that you must be using the latest script_txds.rpf, which will be in the update.rpf in your mods folder.

Edited by LeeC22

Share this post


Link to post
Share on other sites
maksimpalinski
Posted (edited)

Im using that line of code

GRAPHICS::DRAW_SPRITE("mySprites", mySpriteTexture", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 255);

 And inside the „mySpriteTexture“, I have my custom .png file.

 

and the „mySprites“ ytd is located inside the script_txds.rpf.

 

but the result is just a big white rectangle In the middle of my screen...

Edited by maksimpalinski

Share this post


Link to post
Share on other sites
LeeC22

Does your rpf/ytd files look like this? This is just a sample using one of my own menu banners.Notice the names of everything and where they are.

 

draw-sprite-01.jpg

Share this post


Link to post
Share on other sites
maksimpalinski
Posted (edited)

Yes it looks still like the same.

 

Later I‘m again on my pc and I‘ll look again, but I‘m pretty sure, It still looks like your sample.

Edited by maksimpalinski

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)

Okay... paste this code into a file called SimpleSpriteDraw.cs and put it into your scripts folder. Does this draw your sprite? This requires ScriptHookVDotNet to be installed in your game folder, anything after 2.10.7 should work.

using System;
using System.Drawing;

using GTA;
using GTA.Math;
using GTA.Native;

namespace SimpleSpriteDrawTest
{
    public class cSimpleSpriteDrawTest : Script
    {
        const string SpriteLibrary = "mySprites";
        const string SpriteName = "mySpriteTexture";

        public cSimpleSpriteDrawTest()
        {
            Tick += onTick;
            Interval = 0;
        }

        private void onTick(object sender, EventArgs e)
        {
            // Exits from the loop if the game is loading
            if (Game.IsLoading) return;

            DrawSprite();
        }

        private void DrawSprite()
        {
            // Centre of the screen
            float spriteX = .5f;
            float spriteY = .5f;

            // Get the texture resolution, textureRes.X = width, textureRes.Y = height
            Vector3 textureRes = Function.Call<Vector3>(Hash.GET_TEXTURE_RESOLUTION, SpriteLibrary, SpriteName);

            // Divide those values by the screen resolution to get the required scale values to draw it at normal size.
            // NOTE: The scale values are a percentage of the SCREEN size, not the SPRITE size... 1f = Draw the sprite the size of the screen
            float scaleX = textureRes.X / Game.ScreenResolution.Width;
            float scaleY = textureRes.Y / Game.ScreenResolution.Height;

            // Set the rotation to 0
            float rotation = 0f;

            // Set the colour to white
            Color col = Color.White;

            // Has the texture library loaded?
            if (Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, SpriteLibrary))
            {
                // If Yes, draw the sprite
                Function.Call(Hash.DRAW_SPRITE, SpriteLibrary, SpriteName, spriteX, spriteY, scaleX, scaleY, rotation, col.R, col.G, col.B, col.A);
            }
            else
            {
                // If No, request it
                Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, SpriteLibrary, false);
            }
        }
    }
}

That gets me this as a result.

 

sprite-draw-test.jpg

Edited by LeeC22

Share this post


Link to post
Share on other sites
maksimpalinski

Okay nice, can u show me just how I can change the x and y from the sprite?

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)
27 minutes ago, maksimpalinski said:

Okay nice, can u show me just how I can change the x and y from the sprite?

If you wanted your sprite to be drawn at X = 100, Y = 50

100 / Game.ScreenResolution.Width = X coord

50 / Game.ScreenResolution.Height = Y coord

 

So for 100, 50 on a 1920x1080 screen, you would use 0.052f, 0.0463f

 

Remember that this is for drawing the sprite with the centre at those coordinates.

 

If you want to draw from the top-left corner, then you have to add an offset equal to half the sprite width to the X and half the sprite height to the Y, before calculating the X & Y coordinates. The code I showed you already gets the texture size, so working that part out should be easy enough with what I have shown.

Edited by LeeC22

Share this post


Link to post
Share on other sites
maksimpalinski

Thank you so much... really

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.