mirror of https://github.com/buggins/dlangui.git
fix problem with font colors under OpenGL
This commit is contained in:
parent
6adad89d53
commit
0cff3908fe
|
@ -67,7 +67,7 @@ class GLDrawBuf : DrawBuf {
|
||||||
assert(_scene !is null);
|
assert(_scene !is null);
|
||||||
Rect dstrect = Rect(x,y, x + glyph.blackBoxX, y + glyph.blackBoxY);
|
Rect dstrect = Rect(x,y, x + glyph.blackBoxX, y + glyph.blackBoxY);
|
||||||
Rect srcrect = Rect(0, 0, glyph.blackBoxX, glyph.blackBoxY);
|
Rect srcrect = Rect(0, 0, glyph.blackBoxX, glyph.blackBoxY);
|
||||||
//Log.v("GLDrawBuf.frawFragment dst=", dstrect, " src=", srcrect);
|
Log.v("GLDrawBuf.drawGlyph dst=", dstrect, " src=", srcrect, " color=", color);
|
||||||
if (applyClipping(dstrect, srcrect)) {
|
if (applyClipping(dstrect, srcrect)) {
|
||||||
if (!glGlyphCache.get(glyph.id))
|
if (!glGlyphCache.get(glyph.id))
|
||||||
glGlyphCache.put(glyph);
|
glGlyphCache.put(glyph);
|
||||||
|
@ -248,13 +248,15 @@ private class GLImageCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void invertAlpha(GLImageCacheItem item) {
|
void convertPixelFormat(GLImageCacheItem item) {
|
||||||
Rect rc = item._rc;
|
Rect rc = item._rc;
|
||||||
for (int y = rc.top; y < rc.bottom; y++) {
|
for (int y = rc.top - 1; y <= rc.bottom; y++) {
|
||||||
uint * row = _drawbuf.scanLine(y);
|
uint * row = _drawbuf.scanLine(y);
|
||||||
for (int x = rc.left; x < rc.right; x++) {
|
for (int x = rc.left - 1; x <= rc.right; x++) {
|
||||||
uint cl = row[x];
|
uint cl = row[x];
|
||||||
|
// invert A
|
||||||
cl ^= 0xFF000000;
|
cl ^= 0xFF000000;
|
||||||
|
// swap R and B
|
||||||
uint r = (cl & 0x00FF0000) >> 16;
|
uint r = (cl & 0x00FF0000) >> 16;
|
||||||
uint b = (cl & 0x000000FF) << 16;
|
uint b = (cl & 0x000000FF) << 16;
|
||||||
row[x] = (cl & 0xFF00FF00) | r | b;
|
row[x] = (cl & 0xFF00FF00) | r | b;
|
||||||
|
@ -304,7 +306,7 @@ private class GLImageCache {
|
||||||
return null;
|
return null;
|
||||||
buf.onDestroyCallback = &onObjectDestroyedCallback;
|
buf.onDestroyCallback = &onObjectDestroyedCallback;
|
||||||
_drawbuf.drawImage(cacheItem._rc.left, cacheItem._rc.top, buf);
|
_drawbuf.drawImage(cacheItem._rc.left, cacheItem._rc.top, buf);
|
||||||
invertAlpha(cacheItem);
|
convertPixelFormat(cacheItem);
|
||||||
_needUpdateTexture = true;
|
_needUpdateTexture = true;
|
||||||
return cacheItem;
|
return cacheItem;
|
||||||
}
|
}
|
||||||
|
@ -507,8 +509,8 @@ private class TextureSceneItem : SceneItem {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// by some reason ALPHA texture does not work as expected
|
||||||
|
private immutable USE_RGBA_TEXTURE_FOR_GLYPHS = true;
|
||||||
|
|
||||||
private class GLGlyphCache {
|
private class GLGlyphCache {
|
||||||
|
|
||||||
|
@ -555,6 +557,9 @@ private class GLGlyphCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static if (USE_RGBA_TEXTURE_FOR_GLYPHS) {
|
||||||
|
uint[] _rgbaBuffer;
|
||||||
|
}
|
||||||
void updateTexture() {
|
void updateTexture() {
|
||||||
if (_drawbuf is null)
|
if (_drawbuf is null)
|
||||||
return; // no draw buffer!!!
|
return; // no draw buffer!!!
|
||||||
|
@ -566,11 +571,23 @@ private class GLGlyphCache {
|
||||||
}
|
}
|
||||||
//CRLog::debug("updateTexture - setting image %dx%d", _drawbuf.width, _drawbuf.height);
|
//CRLog::debug("updateTexture - setting image %dx%d", _drawbuf.width, _drawbuf.height);
|
||||||
ubyte * pixels = _drawbuf.scanLine(0);
|
ubyte * pixels = _drawbuf.scanLine(0);
|
||||||
|
static if (USE_RGBA_TEXTURE_FOR_GLYPHS) {
|
||||||
|
int len = _drawbuf.width * _drawbuf.height;
|
||||||
|
_rgbaBuffer.length = len;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
_rgbaBuffer[i] = ((cast(uint)pixels[i]) << 24) | 0x00FFFFFF;
|
||||||
|
if (!setTextureImage(_textureId, _drawbuf.width, _drawbuf.height, cast(ubyte*)_rgbaBuffer.ptr)) {
|
||||||
|
deleteTexture(_textureId);
|
||||||
|
_textureId = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (!setTextureImageAlpha(_textureId, _drawbuf.width, _drawbuf.height, pixels)) {
|
if (!setTextureImageAlpha(_textureId, _drawbuf.width, _drawbuf.height, pixels)) {
|
||||||
deleteTexture(_textureId);
|
deleteTexture(_textureId);
|
||||||
_textureId = 0;
|
_textureId = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_needUpdateTexture = false;
|
_needUpdateTexture = false;
|
||||||
if (_closed) {
|
if (_closed) {
|
||||||
destroy(_drawbuf);
|
destroy(_drawbuf);
|
||||||
|
@ -650,8 +667,10 @@ private class GLGlyphCache {
|
||||||
dstrc.top += clip.top;
|
dstrc.top += clip.top;
|
||||||
dstrc.bottom -= clip.bottom;
|
dstrc.bottom -= clip.bottom;
|
||||||
}
|
}
|
||||||
if (!dstrc.empty)
|
if (!dstrc.empty) {
|
||||||
|
Log.d("drawing glyph with color ", color);
|
||||||
drawColorAndTextureRect(_textureId, _tdx, _tdy, srcrc, dstrc, color, false);
|
drawColorAndTextureRect(_textureId, _tdx, _tdy, srcrc, dstrc, color, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -659,6 +678,9 @@ private class GLGlyphCache {
|
||||||
_closed = true;
|
_closed = true;
|
||||||
if (_needUpdateTexture)
|
if (_needUpdateTexture)
|
||||||
updateTexture();
|
updateTexture();
|
||||||
|
static if (USE_RGBA_TEXTURE_FOR_GLYPHS) {
|
||||||
|
_rgbaBuffer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,10 +745,9 @@ private class GLGlyphCache {
|
||||||
}
|
}
|
||||||
/// draw cached item
|
/// draw cached item
|
||||||
void drawItem(uint objectId, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
|
void drawItem(uint objectId, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
|
||||||
if (objectId in _map) {
|
GLGlyphCacheItem * item = objectId in _map;
|
||||||
GLGlyphCacheItem item = _map[objectId];
|
if (item)
|
||||||
item.page.drawItem(item, dstrc, srcrc, color, clip);
|
item.page.drawItem(*item, dstrc, srcrc, color, clip);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// handle cached object deletion, mark as deleted
|
/// handle cached object deletion, mark as deleted
|
||||||
void onCachedObjectDeleted(uint objectId) {
|
void onCachedObjectDeleted(uint objectId) {
|
||||||
|
|
|
@ -63,7 +63,6 @@ void drawSolidFillRect(Rect rc, uint color1, uint color2, uint color3, uint colo
|
||||||
_solidFillProgram.execute(vertices, colors);
|
_solidFillProgram.execute(vertices, colors);
|
||||||
} else
|
} else
|
||||||
Log.e("No program");
|
Log.e("No program");
|
||||||
//drawSolidFillRect(vertices, colors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawColorAndTextureRect(uint textureId, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color, bool linear) {
|
void drawColorAndTextureRect(uint textureId, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color, bool linear) {
|
||||||
|
@ -72,9 +71,6 @@ void drawColorAndTextureRect(uint textureId, int tdx, int tdy, Rect srcrc, Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawColorAndTextureRect(uint textureId, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color, bool linear) {
|
void drawColorAndTextureRect(uint textureId, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color, bool linear) {
|
||||||
//if (crconfig.getTextureFormat() == TEXTURE_ALPHA) {
|
|
||||||
// color = 0x000000;
|
|
||||||
//}
|
|
||||||
float colors[6*4];
|
float colors[6*4];
|
||||||
LVGLFillColor(color, colors.ptr, 6);
|
LVGLFillColor(color, colors.ptr, 6);
|
||||||
float dstx0 = cast(float)xx;
|
float dstx0 = cast(float)xx;
|
||||||
|
@ -466,6 +462,7 @@ class SolidFillProgram : GLProgram {
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
checkError("glDisable(GL_CULL_FACE)");
|
checkError("glDisable(GL_CULL_FACE)");
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
checkError("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)");
|
checkError("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)");
|
||||||
bind();
|
bind();
|
||||||
//glUniformMatrix4fv(matrixLocation, 1, false, m.value_ptr);
|
//glUniformMatrix4fv(matrixLocation, 1, false, m.value_ptr);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import std.file;
|
||||||
import dlangui.platforms.common.platform;
|
import dlangui.platforms.common.platform;
|
||||||
import dlangui.platforms.windows.win32fonts;
|
import dlangui.platforms.windows.win32fonts;
|
||||||
import dlangui.platforms.windows.win32drawbuf;
|
import dlangui.platforms.windows.win32drawbuf;
|
||||||
|
import dlangui.widgets.styles;
|
||||||
import dlangui.graphics.drawbuf;
|
import dlangui.graphics.drawbuf;
|
||||||
import dlangui.graphics.images;
|
import dlangui.graphics.images;
|
||||||
import dlangui.graphics.fonts;
|
import dlangui.graphics.fonts;
|
||||||
|
@ -250,21 +251,16 @@ class Win32Window : Window {
|
||||||
GLDrawBuf buf = new GLDrawBuf(_dx, _dy, false);
|
GLDrawBuf buf = new GLDrawBuf(_dx, _dy, false);
|
||||||
buf.beforeDrawing();
|
buf.beforeDrawing();
|
||||||
if (false) {
|
if (false) {
|
||||||
|
// for testing for render
|
||||||
buf.fillRect(Rect(100, 100, 200, 200), 0x704020);
|
buf.fillRect(Rect(100, 100, 200, 200), 0x704020);
|
||||||
buf.fillRect(Rect(40, 70, 100, 120), 0x000000);
|
buf.fillRect(Rect(40, 70, 100, 120), 0x000000);
|
||||||
buf.fillRect(Rect(80, 80, 150, 150), 0x80008000); // green
|
buf.fillRect(Rect(80, 80, 150, 150), 0x80008000); // green
|
||||||
DrawableRef img = drawableCache.get("exit");
|
drawableCache.get("exit").drawTo(buf, Rect(300, 100, 364, 164));
|
||||||
if (!img.isNull) {
|
drawableCache.get("btn_default_pressed").drawTo(buf, Rect(300, 200, 564, 264));
|
||||||
img.drawTo(buf, Rect(300, 100, 364, 164));
|
|
||||||
img.drawTo(buf, Rect(400, 200, 528, 328));
|
|
||||||
}
|
|
||||||
DrawableRef img2 = drawableCache.get("btn_default_pressed");
|
|
||||||
if (!img2.isNull) {
|
|
||||||
img2.drawTo(buf, Rect(300, 200, 564, 264));
|
|
||||||
img2.drawTo(buf, Rect(600, 200, 628, 328));
|
|
||||||
}
|
|
||||||
drawableCache.get("btn_default_normal").drawTo(buf, Rect(300, 0, 400, 50));
|
drawableCache.get("btn_default_normal").drawTo(buf, Rect(300, 0, 400, 50));
|
||||||
drawableCache.get("btn_default_selected").drawTo(buf, Rect(0, 0, 100, 50));
|
drawableCache.get("btn_default_selected").drawTo(buf, Rect(0, 0, 100, 50));
|
||||||
|
FontRef fnt = currentTheme.font;
|
||||||
|
fnt.drawText(buf, 40, 40, "Some Text 1234567890 !@#$^*", 0x80FF0000);
|
||||||
} else {
|
} else {
|
||||||
onDraw(buf);
|
onDraw(buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue