-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nametag.cpp
52 lines (45 loc) · 1.4 KB
/
Nametag.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Nametag.h"
#include "textlib/textlib.h"
namespace anengine
{
PropertyInfo Nametag::PlayerNameProperty("PlayerName", typeid(Nametag));
PropertyInfo Nametag::HealthProperty("Health", typeid(Nametag));
void Nametag::OnPropertyChanged(const PropertyInfo *id, bool implicit)
{
if(id == &PlayerNameProperty || id == &HealthProperty)
{
if(IsCreated())
UpdateStatus();
}
Billboard::OnPropertyChanged(id, implicit);
}
void Nametag::OnCreate()
{
myTexture = Scene.Get()->GetAssetManager()->CreateFromMemory<Texture>("");
UpdateStatus();
SetTexture(myTexture);
Billboard::OnCreate();
}
void Nametag::OnDestroy()
{
myTexture.Release();
Billboard::OnDestroy();
}
void Nametag::OnNewProgram()
{
ProgramState().SetUniform("Flip", VectorF2(0,1));
Billboard::OnNewProgram();
}
void Nametag::UpdateStatus()
{
SDL_Surface *stat = textlib_get_nametag(PlayerName.Get().c_str(), Health.Get());
TextureSettings settings;
settings.MinFilter = GL_LINEAR_MIPMAP_LINEAR;
settings.MagFilter = GL_LINEAR;
settings.GenerateMipmap = true;
SDL_LockSurface(stat);
myTexture->SetData(stat->w, stat->h, GL_BGRA, stat->pixels, settings);
SDL_UnlockSurface(stat);
SDL_FreeSurface(stat);
}
};