Can i create a Texture from RGBA Data?

Hey,

i’m getting a unique ID from the Steam Avatars and the only 2 Things you can do with it is getting the size of the picture and the RGBA Stream.

I don’t really know how i can use this do display the Avatar in UE4.

Here is the code that includes the Steamworks functions:

int Picture = SteamFriends()->GetMediumFriendAvatar(SteamUser()->GetSteamID());
	uint32 height;
	uint32 width;
	if (SteamUtils()->GetImageSize(Picture, &width, &height))
	{
		FString ResolutionH = FString::FromInt(height);
		FString ResolutionW = FString::FromInt(width);
		GEngine->AddOnScreenDebugMessage(1, 20.0F, FColor::Red, ResolutionH + ResolutionW);
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(1, 20.0F, FColor::Red, TEXT("Didn't work :("));
	}

	if (width > 0 && height > 0)
	{
		BYTE *oAvatarRGBA = new BYTE[width * height * 4];
		SteamUtils()->GetImageRGBA(Picture, (uint8*)oAvatarRGBA, width * height * 4);

	}

In the last if, i need to create something that UE4 can use. Normaly that would be a Texture2D or?
What can i use to create a texture now? :frowning:

Anything derived from UTexture or UTexture2D would work. UTexture doesn’t provide much help for this kind of use case, so UTexture2D may be a slightly better choice. Note that the actual texture data is not stored in the UTexture, but in a so called FTextureResource. UTexture is merely an Engine friendly container for the low level resource data that is used by the renderer. All the useful stuff is in the texture resource.

You could probably hook into the UTexture2D API (i.e. GetRawMipData()), but a cleaner approach may be to create your own sub-class altogether. For example, take a look at the UMediaTexture and FMediaTextureResources classes, which implement a texture that is populated from streamed video data. Note that the UMediaTexture is rather dumb and only provides an interface to the Engine and to Blueprints. The actual data is in FMediaTextureResource, and the UMediaTexture calls UpdateResource() in the appropriate places to have the texture resource be created and initialized correctly.

Also note that the texture resource object is shared between the Game Thread and the Render Thread, so proper locking must be used before writing to the resource data. See the RHIUnlockTexture2D() and RHILockTexture2D() calls in FMediaTextureResource.

If you want to show the avatar in a Slate or UMG based user interface, then another option would be to create and initialize a Slate image brush instead of a UTexture derived object. You can find an example of this in the NewsFeed module. Take a look at FNewsFeedCache::ProcessIconFile(), which generates a slate image brush from raw byte data.

Hm, thanks for the answer, but i’m not skilled enough to take any information out of this. I searched for a simple Method that converts the RGBA Data to a Texture.
Isn’t there something easy to understand for a hobby developer? Using Steamworks is way to complicated like this… I mean, it’s just an avatar and i can’t get this to run at all -_-
Is anyone here who uses Steamworks and also managed to display the Avatars? Or does noone uses Steamworks at all, since there are only around 10 Questions about it in general o.o

I’m afraid that we currently do not have an easy way to do this that does not require custom code. Based on your feedback, however, I will put it on the to-do list.

I know this topic is old but it shows up in the search early so i think it is useful to also provide this link:

Hey, thanks for the additional answer. (: The reason i asked this was to get the RGBA Data from the Steam Friend Avatars and display them in the friend list.

But at the time asking this, i didn’t know that this could be achieved through the OnlineSubsystem that works pretty well with steam if you try around.

But anyway (: I helps answering my original question, although i wouldn’t know how to use “CreateTexture2D” exactly :smiley:

I don’t want to bump this, but I’m currently trying to figure out how to get steam avatars with the online system here, and cannot figure it out. Could you please perhaps share this information with me if you are still around?

In this AnswerHUB Post is an answer with C++ code:

That should help people who are still struggling (: