More work on texture ID overlay

This commit is contained in:
UnknownShadow200 2017-08-20 21:09:46 +10:00
parent 0233a846da
commit 16806fb20d
2 changed files with 78 additions and 37 deletions

View File

@ -11,35 +11,72 @@ namespace ClassicalSharp.Gui.Screens {
TextAtlas idAtlas;
public TexIdsOverlay(Game game) : base(game) { }
const int verticesCount = TerrainAtlas2D.TilesPerRow * TerrainAtlas2D.RowsCount * 4;
static VertexP3fT2fC4b[] vertices;
int dynamicVb;
public override void Init() {
base.Init();
idAtlas = new TextAtlas(game, 16);
idAtlas.Pack("0123456789", regularFont, "f");
if (vertices == null) {
vertices = new VertexP3fT2fC4b[verticesCount];
}
dynamicVb = gfx.CreateDynamicVb(VertexFormat.P3fT2fC4b, verticesCount);
}
const int tileSize = 45, textOffset = 3;
int xOffset, yOffset;
public override void Render(double delta) {
int index = 0;
VertexP3fT2fC4b[] vertices = game.ModelCache.vertices;
idAtlas.tex.Y = 100;
for (int y = 0; y < 2; y++) {
idAtlas.curX = 0;
for (int x = 0; x < 16; x++) {
idAtlas.AddInt(x + (y * 16), vertices, ref index);
idAtlas.curX += 20;
}
idAtlas.tex.Y += 50;
}
RenderMenuBounds();
gfx.Texturing = true;
gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
gfx.BindTexture(idAtlas.tex.ID);
gfx.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index);
RenderWidgets(widgets, delta);
RenderTerrain();
RenderTextOverlay();
gfx.Texturing = false;
}
void RenderTerrain() {
int elementsPerAtlas = game.TerrainAtlas1D.elementsPerAtlas1D;
for (int i = 0; i < TerrainAtlas2D.TilesPerRow * TerrainAtlas2D.RowsCount;) {
int index = 0, texIdx = i / elementsPerAtlas, ignored;
for (int j = 0; j < elementsPerAtlas; j++) {
TextureRec rec = game.TerrainAtlas1D.GetTexRec(i + j, 1, out ignored);
int x = (i + j) % TerrainAtlas2D.TilesPerRow;
int y = (i + j) / TerrainAtlas2D.TilesPerRow;
Texture tex = new Texture(0, xOffset + x * tileSize, yOffset + y * tileSize,
tileSize, tileSize, rec);
IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked, vertices, ref index);
}
i += elementsPerAtlas;
gfx.BindTexture(game.TerrainAtlas1D.TexIds[texIdx]);
gfx.UpdateDynamicVb_IndexedTris(dynamicVb, vertices, index);
}
}
void RenderTextOverlay() {
int index = 0;
idAtlas.tex.Y = (short)(yOffset + (tileSize - idAtlas.tex.Height));
for (int y = 0; y < 4; y++) {
for (int x = 0; x < TerrainAtlas2D.TilesPerRow; x++) {
idAtlas.curX = xOffset + tileSize * x + textOffset;
idAtlas.AddInt(x + (y * 16), vertices, ref index);
}
idAtlas.tex.Y += tileSize;
}
gfx.BindTexture(idAtlas.tex.ID);
gfx.UpdateDynamicVb_IndexedTris(dynamicVb, vertices, index);
}
public override bool HandlesKeyDown(Key key) {
if (key == Key.F10 || key == game.Input.Keys[KeyBind.PauseOrExit]) {
Dispose();
@ -51,7 +88,12 @@ namespace ClassicalSharp.Gui.Screens {
public override void RedrawText() { }
public override void MakeButtons() {
widgets = new Widget[0];
xOffset = (game.Width / 2) - (tileSize * TerrainAtlas2D.TilesPerRow) / 2;
yOffset = (game.Height / 2) - (tileSize * TerrainAtlas2D.RowsCount) / 2;
widgets = new Widget[1];
widgets[0] = TextWidget.Create(game, "Texture ID reference sheet", titleFont)
.SetLocation(Anchor.Centre, Anchor.LeftOrTop, 0, yOffset - 30);
}
public override void Dispose() {

View File

@ -23,7 +23,6 @@ GfxResourceID weather_vb;
#define weather_extent 4
#define weather_verticesCount 8 * (weather_extent * 2 + 1) * (weather_extent * 2 + 1)
VertexP3fT2fC4b weather_vertices[weather_verticesCount];
Int16* weather_heightmap;
Real64 weather_accumulator;
@ -71,11 +70,11 @@ void WeatherRenderer_Render(Real64 deltaTime) {
Int32 vCount = 0;
PackedCol col = WorldEnv_SunCol;
VertexP3fT2fC4b v;
VertexP3fT2fC4b* ptr = weather_vertices;
VertexP3fT2fC4b vertices[weather_verticesCount];
VertexP3fT2fC4b* ptr = vertices;
for (Int32 dx = -weather_extent; dx <= weather_extent; dx++)
for (Int32 dz = -weather_extent; dz <= weather_extent; dz++)
{
for (Int32 dz = -weather_extent; dz <= weather_extent; dz++) {
Int32 x = pos.X + dx, z = pos.Z + dz;
Real32 y = WeatherRenderer_RainHeight(x, z);
Real32 height = pos.Y - y;
@ -97,24 +96,24 @@ void WeatherRenderer_Render(Real64 deltaTime) {
#define AddVertex *ptr = v; ptr++;
v.X = x; v.Y = y; v.Z = z; v.U = 0.0f; v.V = v1; AddVertex
/* (x, y, z) (0, v1) */
v.Y = y + height; v.V = v2; AddVertex
/* (x, y + height, z) (0, v2) */
v.X = x + 1; v.Z = z + 1; v.U = 1.0f; AddVertex
/* (x + 1, y + height, z + 1) (1, v2) */
v.Y = y; v.V = v1; AddVertex
/* (x + 1, y, z + 1) (1, v1) */
/* (x, y, z) (0, v1) */
v.Y = y + height; v.V = v2; AddVertex
/* (x, y + height, z) (0, v2) */
v.X = x + 1; v.Z = z + 1; v.U = 1.0f; AddVertex
/* (x + 1, y + height, z + 1) (1, v2) */
v.Y = y; v.V = v1; AddVertex
/* (x + 1, y, z + 1) (1, v1) */
v.Z = z; AddVertex
/* (x + 1, y, z) (1, v1) */
v.Y = y + height; v.V = v2; AddVertex
/* (x + 1, y + height, z) (1, v2) */
v.X = x; v.Z = z + 1; v.U = 0.0f; AddVertex
/* (x, y + height, z + 1) (0, v2) */
v.Y = y; v.V = v1; AddVertex
/* (x y, z + 1) (0, v1) */
v.Z = z; AddVertex
/* (x + 1, y, z) (1, v1) */
v.Y = y + height; v.V = v2; AddVertex
/* (x + 1, y + height, z) (1, v2) */
v.X = x; v.Z = z + 1; v.U = 0.0f; AddVertex
/* (x, y + height, z + 1) (0, v2) */
v.Y = y; v.V = v1; AddVertex
/* (x y, z + 1) (0, v1) */
vCount += 8;
vCount += 8;
}
if (particles && (weather_accumulator >= 0.25f || moved))
@ -126,7 +125,7 @@ void WeatherRenderer_Render(Real64 deltaTime) {
Gfx_SetAlphaArgBlend(true);
Gfx_SetBatchFormat(VertexFormat_P3fT2fC4b);
GfxCommon_UpdateDynamicVb_IndexedTris(weather_vb, weather_vertices, vCount);
GfxCommon_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount);
Gfx_SetAlphaArgBlend(false);
Gfx_SetDepthWrite(false);