To load a PNG image as an UI element, you could use something like this:
BorderImage* yourImage_ = new BorderImage(context_);
yourImage_->SetTexture(cache->GetResource<Texture2D>("yourImage.png"));
yourImage_->SetSize(100,100);
yourImage_->SetAlignment(HA_LEFT,VA_TOP);
yourImage_->SetPosition(0,0);
uiRoot_->AddChild(yourImage_);
To load a PNG image as a sprite, check the samples
24_Urho2DSprite
and
36_Urho2DTileMap
.
And to load a PNG image as an “object” on the 3D space, I guess you could load it on a plane object (similar to how it was done on sample
38_SceneAndUILoad
), maybe like this:
Node* planeNode_ = scene_->CreateChild("Plane");
planeNode_->SetScale(Vector3(2.0f, 2.0f, 2.0f));
planeNode_->SetRotation(Quaternion(-90.0f, 0.0f, 0.0f));
StaticModel* planeObject = planeNode_->CreateComponent<StaticModel>();
planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
planeObject->SetMaterial(cache->GetResource<Material>("Materials/yourMaterial.xml"));
And yourMaterial.xml:
<material>
<technique name="Techniques/DiffUnlit.xml"/>
<texture name="yourImage.png" unit="diffuse"/>
<parameter name="MatDiffColor" value="1 1 1 1"/>
<parameter name="MatSpecColor" value="1 1 1 1"/>
</material>
I don’t have much experience with the engine yet, so I don’t know how you could read the pixels of the PNG image. But I guess you could use the
File API
and the
Deserializer
for that. Maybe something like this:
Something imagePixels = (cache->GetFile("yourImage.png"))->Read();
Or:
File imageFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "yourImage.png", FILE_READ);
Something imagePixels = imageFile.Read();