create overlay textures for entity overlays, instead of rendering glyphs

This commit is contained in:
Jupeyy 2017-09-12 20:15:37 +02:00
parent 6dc4d1e578
commit 9d2a625363
2 changed files with 85 additions and 0 deletions

View file

@ -5,6 +5,7 @@
#include <engine/storage.h>
#include <engine/serverbrowser.h>
#include <game/client/component.h>
#include <engine/textrender.h>
#include <game/mapitems.h>
#include "mapimages.h"
@ -13,6 +14,70 @@ CMapImages::CMapImages()
{
m_Count = 0;
m_EntitiesTextures = -1;
m_OverlayBottomTexture = -1;
m_OverlayTopTexture = -1;
m_OverlayCenterTexture = -1;
}
void CMapImages::OnInit(){
//TODO: improve this a bit -- with better fron sizes etc.
if(m_OverlayBottomTexture == -1){
void *pMem = mem_alloc(1024*1024, 1);
mem_zero(pMem, 1024*1024);
m_OverlayBottomTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
for(int i = 0; i < 256; ++i){
char buff[4];
str_format(buff, 4, "%d", i);
int len = str_length(buff);
float x = (i%16) * 64;
float y = (int)(i/16)* 64;
Graphics()->LoadTextureRawSub(m_OverlayBottomTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem);
TextRender()->UploadText(m_OverlayBottomTexture, buff, -1, x, y + 12 + 32, 20);
}
mem_free(pMem);
}
if(m_OverlayTopTexture == -1){
void *pMem = mem_alloc(1024*1024, 1);
mem_zero(pMem, 1024*1024);
m_OverlayTopTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
for(int i = 0; i < 256; ++i){
char buff[4];
str_format(buff, 4, "%d", i);
int len = str_length(buff);
float x = (i%16) * 64;
float y = (int)(i/16)* 64;
Graphics()->LoadTextureRawSub(m_OverlayTopTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem);
TextRender()->UploadText(m_OverlayTopTexture, buff, -1, x, y, 20);
}
mem_free(pMem);
}
if(m_OverlayCenterTexture == -1){
void *pMem = mem_alloc(1024*1024, 1);
mem_zero(pMem, 1024*1024);
m_OverlayCenterTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
for(int i = 0; i < 256; ++i){
char buff[4];
str_format(buff, 4, "%d", i);
int len = str_length(buff);
float x = (i%16) * 64;
float y = (int)(i/16)* 64;
int Size = (len == 3 ? 20 : 64);
int Width = (len == 3 ? 15 : 32);
int OffY = (len == 3 ? 10 : 5);
int OffX = (len == 3 ? 10 : 0);
Graphics()->LoadTextureRawSub(m_OverlayCenterTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem);
TextRender()->UploadText(m_OverlayCenterTexture, buff, -1, x + OffX, y + OffY, Size);
}
mem_free(pMem);
}
}
void CMapImages::OnMapLoad()
@ -118,3 +183,15 @@ int CMapImages::GetEntities()
}
return m_EntitiesTextures;
}
int CMapImages::GetOverlayBottom(){
return m_OverlayBottomTexture;
}
int CMapImages::GetOverlayTop(){
return m_OverlayTopTexture;
}
int CMapImages::GetOverlayCenter(){
return m_OverlayCenterTexture;
}

View file

@ -19,15 +19,23 @@ public:
int Num() const { return m_Count; }
virtual void OnMapLoad();
virtual void OnInit();
void LoadBackground(class IMap *pMap);
// DDRace
int GetEntities();
int GetOverlayBottom();
int GetOverlayTop();
int GetOverlayCenter();
private:
int m_EntitiesTextures;
int m_OverlayBottomTexture;
int m_OverlayTopTexture;
int m_OverlayCenterTexture;
};
#endif