Fix mipmaps

This commit is contained in:
UnknownShadow200 2018-11-19 23:21:27 +11:00
parent 7c845058aa
commit b91b7715de
6 changed files with 71 additions and 45 deletions

View File

@ -182,7 +182,7 @@ static BitmapCol GfxCommon_Average(BitmapCol p1, BitmapCol p2) {
/* Convert RGB to pre-multiplied form */
b1 = p1.B * a1; g1 = p1.G * a1; r1 = p1.R * a1;
b2 = p1.B * a2; g2 = p2.G * a2; r2 = p2.R * a2;
b2 = p2.B * a2; g2 = p2.G * a2; r2 = p2.R * a2;
/* https://stackoverflow.com/a/347376
We need to convert RGB back from the pre-multiplied average into normal form

View File

@ -2716,10 +2716,11 @@ struct Screen* HacksSettingsScreen_MakeInstance(void) {
"&ethe block to be placed, and you to be moved out of the way.|" \
"&fThis is mainly useful for quick pillaring/towering.";
descs[8] = "&eIf &fOFF&e, you will immediately stop when in noclip|&emode and no movement keys are held down.";
/* TODO: Is this needed because user may not always use . for decimal point? */
static char jumpHeightBuffer[STRING_INT_CHARS];
String jumpHeight = String_ClearedArray(jumpHeightBuffer);
String jumpHeight;
/* TODO: Is this needed because user may not always use . for decimal point? */
jumpHeight = String_ClearedArray(jumpHeightBuffer);
String_AppendFloat(&jumpHeight, 1.233f, 3);
validators[1] = MenuInputValidator_Float(0.10f, 50.00f);

View File

@ -22,14 +22,19 @@ static RNGState rnd;
static bool particle_hitTerrain;
void Particle_DoRender(Vector2* size, Vector3* pos, TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices) {
float sX = size->X * 0.5f, sY = size->Y * 0.5f;
Vector3 centre = *pos; centre.Y += sY;
struct Matrix* view = &Gfx_View;
struct Matrix* view;
VertexP3fT2fC4b v;
float sX, sY;
Vector3 centre;
float aX, aY, aZ, bX, bY, bZ;
sX = size->X * 0.5f; sY = size->Y * 0.5f;
centre = *pos; centre.Y += sY;
view = &Gfx_View;
aX = view->Row0.X * sX; aY = view->Row1.X * sX; aZ = view->Row2.X * sX; /* right * size.X * 0.5f */
bX = view->Row0.Y * sY; bY = view->Row1.Y * sY; bZ = view->Row2.Y * sY; /* up * size.Y * 0.5f */
VertexP3fT2fC4b v; v.Col = col;
v.Col = col;
v.X = centre.X - aX - bX; v.Y = centre.Y - aY - bY; v.Z = centre.Z - aZ - bZ;
v.U = rec->U1; v.V = rec->V2; vertices[0] = v;

View File

@ -993,15 +993,17 @@ static void Font_DirCallback(const String* path, void* obj) {
Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
FT_Face face = args->Font.Handle;
String text = args->Text;
Size2D s = { 0, face->size->metrics.height };
Size2D s = { 0, 0 };
Codepoint cp;
int i;
for (i = 0; i < text.length; i++) {
Codepoint cp = Convert_CP437ToUnicode(text.buffer[i]);
cp = Convert_CP437ToUnicode(text.buffer[i]);
FT_Load_Char(face, cp, 0); /* TODO: Check error */
s.Width += face->glyph->advance.x;
}
s.Height = face->size->metrics.height;
s.Width = TEXT_CEIL(s.Width);
s.Height = TEXT_CEIL(s.Height);
return s;
@ -1010,30 +1012,43 @@ Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col) {
FT_Face face = args->Font.Handle;
String text = args->Text;
Size2D s = { x, TEXT_CEIL(face->size->metrics.height) };
int i, descender = TEXT_CEIL(face->size->metrics.descender);
Size2D s = { 0, 0 };
int descender, begX = x;
/* glyph state */
int i, xx, yy, offset;
Codepoint cp;
FT_Bitmap* img;
/* glyph drawing state */
uint8_t* src;
BitmapCol* dst;
uint8_t intensity, invIntensity;
s.Height = TEXT_CEIL(face->size->metrics.height);
descender = TEXT_CEIL(face->size->metrics.descender);
for (i = 0; i < text.length; i++) {
Codepoint cp = Convert_CP437ToUnicode(text.buffer[i]);
cp = Convert_CP437ToUnicode(text.buffer[i]);
FT_Load_Char(face, cp, FT_LOAD_RENDER); /* TODO: Check error */
FT_Bitmap* img = &face->glyph->bitmap;
int xx, yy, offset = s.Height + descender - face->glyph->bitmap_top;
img = &face->glyph->bitmap;
offset = (s.Height + descender) - face->glyph->bitmap_top;
x += face->glyph->bitmap_left; y += offset;
for (yy = 0; yy < img->rows; yy++) {
if ((y + yy) < 0 || (y + yy) >= bmp->Height) continue;
uint8_t* src = img->buffer + (yy * img->width);
BitmapCol* dst = Bitmap_GetRow(bmp, y + yy) + x;
src = img->buffer + (yy * img->width);
dst = Bitmap_GetRow(bmp, y + yy) + x;
for (xx = 0; xx < img->width; xx++) {
if ((x + xx) < 0 || (x + xx) >= bmp->Width) continue;
intensity = *src; invIntensity = UInt8_MaxValue - intensity;
uint8_t intensity = *src, invIntensity = UInt8_MaxValue - intensity;
dst->B = ((col.B * intensity) >> 8) + ((dst->B * invIntensity) >> 8);
dst->G = ((col.G * intensity) >> 8) + ((dst->G * invIntensity) >> 8);
dst->R = ((col.R * intensity) >> 8) + ((dst->R * invIntensity) >> 8);
//dst[3] = ((col.A * intensity) >> 8) + ((dst->A * invIntensity) >> 8);
/*dst->A = ((col.A * intensity) >> 8) + ((dst->A * invIntensity) >> 8);*/
dst->A = intensity + ((dst->A * invIntensity) >> 8);
src++; dst++;
}
@ -1043,7 +1058,6 @@ Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, B
x -= face->glyph->bitmap_left; y -= offset;
}
int begX = s.Width;
if (args->Font.Style == FONT_STYLE_UNDERLINE) {
int ul_pos = FT_MulFix(face->underline_position, face->size->metrics.y_scale);
int ul_thick = FT_MulFix(face->underline_thickness, face->size->metrics.y_scale);
@ -1052,6 +1066,7 @@ Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, B
int ulY = s.Height + TEXT_CEIL(ul_pos);
Drawer2D_Underline(bmp, begX, ulY + y, x - begX, ulHeight, col);
}
s.Width = x - begX; return s;
}
@ -1486,16 +1501,17 @@ void Audio_Init(AudioHandle* handle, int buffers) {
}
ReturnCode Audio_Free(AudioHandle handle) {
struct AudioContext* ctx = &Audio_Contexts[handle];
struct AudioFormat fmt = { 0 };
struct AudioContext* ctx;
ReturnCode res;
ctx = &Audio_Contexts[handle];
if (!ctx->Count) return 0;
ctx->Count = 0;
ctx->Format = fmt;
res = waveOutClose(ctx->Handle);
ctx->Handle = NULL;
ctx->Count = 0;
struct AudioFormat fmt = { 0 };
ctx->Format = fmt;
return res;
}
@ -1652,12 +1668,13 @@ void Audio_Init(AudioHandle* handle, int buffers) {
}
ReturnCode Audio_Free(AudioHandle handle) {
struct AudioContext* ctx = &Audio_Contexts[handle];
ALenum err;
if (!ctx->Count) return 0;
ctx->Count = 0;
struct AudioFormat fmt = { 0 };
struct AudioContext* ctx;
ALenum err;
ctx = &Audio_Contexts[handle];
if (!ctx->Count) return 0;
ctx->Count = 0;
ctx->Format = fmt;
err = Audio_FreeSource(ctx);

View File

@ -894,8 +894,12 @@ static uint32_t Vorbis_ReverseBits(uint32_t v) {
}
void imdct_init(struct imdct_state* state, int n) {
int k, k2, n4 = n >> 2, n8 = n >> 3, log2_n = Math_Log2(n);
int k, k2, n4 = n >> 2, n8 = n >> 3, log2_n;
float *A = state->A, *B = state->B, *C = state->C;
uint32_t* reversed;
log2_n = Math_Log2(n);
reversed = state->Reversed;
state->n = n; state->log2_n = log2_n;
/* setup twiddle factors */
@ -910,7 +914,6 @@ void imdct_init(struct imdct_state* state, int n) {
C[k2+1] = -(float)Math_Sin(((k2+1) * (2*PI)) / n);
}
uint32_t* reversed = state->Reversed;
for (k = 0; k < n8; k++) {
reversed[k] = Vorbis_ReverseBits(k) >> (32-log2_n+3);
}

View File

@ -551,13 +551,13 @@ static void TableWidget_MoveCursorToSelected(struct TableWidget* w) {
static void TableWidget_MakeBlockDesc(String* desc, BlockID block) {
String name;
int block_ = block;
if (Game_PureClassic) { String_AppendConst(desc, "Select block"); return; }
name = Block_UNSAFE_GetName(block);
String_AppendString(desc, &name);
if (Game_ClassicMode) return;
int block_ = block;
String_Format1(desc, " (ID %i&f", &block_);
if (!Block_CanPlace[block]) { String_AppendConst(desc, ", place &cNo&f"); }
if (!Block_CanDelete[block]) { String_AppendConst(desc, ", delete &cNo&f"); }
@ -1621,22 +1621,22 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
}
static void ChatInputWidget_Render(void* widget, double delta) {
PackedCol backCol = PACKEDCOL_CONST(0, 0, 0, 127);
struct InputWidget* w = widget;
Gfx_SetTexturing(false);
int x = w->X, y = w->Y;
bool caretAtEnd;
int i, width;
int i;
Gfx_SetTexturing(false);
for (i = 0; i < INPUTWIDGET_MAX_LINES; i++) {
if (i > 0 && w->LineSizes[i].Height == 0) break;
bool caretAtEnd = (w->CaretY == i) && (w->CaretX == INPUTWIDGET_LEN || w->CaretPos == -1);
int drawWidth = w->LineSizes[i].Width + (caretAtEnd ? w->CaretTex.Width : 0);
/* Cover whole window width to match original classic behaviour */
if (Game_PureClassic) {
drawWidth = max(drawWidth, Game_Width - x * 4);
}
if (i > 0 && !w->LineSizes[i].Height) break;
PackedCol backCol = PACKEDCOL_CONST(0, 0, 0, 127);
GfxCommon_Draw2DFlat(x, y, drawWidth + w->Padding * 2, w->PrefixHeight, backCol);
caretAtEnd = (w->CaretY == i) && (w->CaretX == INPUTWIDGET_LEN || w->CaretPos == -1);
width = w->LineSizes[i].Width + (caretAtEnd ? w->CaretTex.Width : 0);
/* Cover whole window width to match original classic behaviour */
if (Game_PureClassic) { width = max(width, Game_Width - x * 4); }
GfxCommon_Draw2DFlat(x, y, width + w->Padding * 2, w->PrefixHeight, backCol);
y += w->LineSizes[i].Height;
}