Color.FromNonPremultiplied different tinting with BlendState.NonPremultiplied - colors

In my XNA project I use non-processed images and draw them with BlendState.NonPremultiplied so they look normal around the edges. But when I use non-white color (Color.FromNonPremultiplied(12, 34, 56, 78)) in SpriteBatch.Draw method, it doesn't tint the sprite as it would if the BlendState was set to default.
How do I achieve the same tinting as default blendstate allows without switching to it?

The documentation says about Color.FromNonPremultiplied Method: Converts a non-premultipled alpha color to a color that contains premultiplied alpha.
Based on this you should use either
BlendState.NonPremultipliedand Color(12, 34, 56, 78)
OR
BlendState.AlphaBlend and Color.FromNonPremultiplied(12, 34, 56, 78)
together.

Related

Creating subwindow fails with BadRegion?

In trying to fix https://stackoverflow.com/a/69647995?noredirect=1, I had an idea; what if I drew the things (that were failing to draw directly on the window) in subwindows of the frame window? It looks like other WMs like Openbox also took this approach.
So I tried doing this:
let text_win = self.conn.generate_id()?;
let text_win_aux = xproto::CreateWindowAux::new()
.event_mask(
xproto::EventMask::EXPOSURE
| xproto::EventMask::SUBSTRUCTURE_REDIRECT
| xproto::EventMask::SUBSTRUCTURE_NOTIFY
| xproto::EventMask::BUTTON_PRESS
| xproto::EventMask::BUTTON_RELEASE
| xproto::EventMask::POINTER_MOTION
| xproto::EventMask::ENTER_WINDOW
| xproto::EventMask::PROPERTY_CHANGE,
)
.background_pixel(0xFFFFFF);
self.conn.create_window(
COPY_DEPTH_FROM_PARENT,
text_win,
frame_win,
15,
15,
60,
25,
0,
xproto::WindowClass::INPUT_OUTPUT,
screen.root_visual,
&text_win_aux,
)?;
self.conn.map_window(text_win)?
But it doesn't work (there is no white rectangle rendered), and it looks like I get a BadRegion error too.
What I expect is that a white rectangle is rendered on the frame window (as the background_pixel of the child is white, and I map it to the frame).
What could I be doing wrong? This doesn't seem to be affected by depth, btw.
I've figured it out. The "text_win" needs to be using the same visual as the frame window; I accidentally used the X11 screen's root visual instead.
So this create_window call functions as expected:
.background_pixel(0xFFFFFF);
self.conn.create_window(
COPY_DEPTH_FROM_PARENT,
text_win,
frame_win,
15,
15,
60,
25,
0,
xproto::WindowClass::INPUT_OUTPUT,
attr.visual,
&text_win_aux,
)?;
(Also, I discovered that the BadRegion was something else, it was a xcompmgr bug, nothing related to this)

Setting (intern) variable for color

I'm trying to create a variable so I can use it across my app. I've put the "code" in OnVisible in my first screen with the following code:
Set(LayoutSettings, {
colorHR : RGBA(55, 207, 177, 1)
})
To test it, I simply used a rectangle and in Fill I use have:
LayoutSettings.colorHR
So basically I have:
HomeScreen.OnVisible = Set(LayoutSettings, {colorHR : RGBA(55, 207, 177, 1)})
Rectangle.Fill = LayoutSettings.colorHR
But somehow my rectangle is still black. What am I doing wrong?

Pygame: Fill transparent areas of text with a color

I have several fonts that I would like to use that are basically outlines of letters, but the insides are transparent. How would I go about filling only the inside areas of these fonts with with a color? I suspect it would be using the special blitting RGBA_BLEND modes, but I am not familiar with their functionality.
Here is an example of the font I am using:
https://www.dafont.com/fipps.font?back=bitmap
Right now, I am simply rendering the font onto a surface, and I've written a helper function for that. Ideally I would be able to integrate this into my function.
def renderText(surface, text, font, color, position):
x, y = position[0], position[1]
width, height = font.size(text)
position = x-width//2, y-height//2
render = font.render(text, 1, color)
surface.blit(render, position)
Thank you so much for any help you can give me!
An option is to define a surface the size of the text, fill that with the color you want, and blit the text on that. For example you could do this:
text = font.render('Hello World!', True, (255, 255, 255)
temp_surface = pygame.Surface(text.get_size())
temp_surface.fill((192, 192, 192))
temp_surface.blit(text, (0, 0))
screen.blit(temp_surface, (0, 0))
This will create a temporary surface that should fill in the transparent pixels of a text surface. There is another option of using set_at() but its too expensive in processing power for what you are doing and is best used for pre-processing surfaces.
Im certain that a better option using BLEND_RGBA_MULT will come from a more experienced user. Im not too good at blending modes either.

Python Cocos2d Label class is ignoring color

I'm using the Python Cocos2D game library and in their docs you can find cocos.text.Label which accepts color=RGBA(int, int, int, int) as params. I've got the following code create a Label:
self.name = cocos.text.Label("Test Label",
font_name='Times New Roman',
font_size=22,
color=(163, 42, 44, 1),
anchor_x='center', anchor_y='center')
self.name.position = (10, 90)
self.add(self.name)
This code is attached to a cocos.layer.Layer and rendered in a Scene initiated in the director.
The issue is this: if I remove the color param from the Label the Label is created correctly and displayed as White color, but if specified color, then the label is just never rendered. Not even black its just not there.
Any help on why this is happening and how to change Label color is very appreciated.
I'm using python 3.4.3 and latest version of python-cocos2d. I'm willing to update and post any code so feel free to ask. Thanks in advance.
Maybe you just can't see the label? The A in RGBA goes from 0 to 255. Value 1 is almost transparent. Try color=(163, 42, 44, 255).

How to change the output color of gulp-debug?

Due to a crash with Gulp, I could not debug what's happening behind. So I installed gulp-debug. I think it's throwing some lines of errors but with unreadable condition in my Windows system due to the output color. Is it possible to change this output color?
Update
#pgreen2, Thanks for your reply.
gulp --no-color
allows complete no-color and so that I cannot distinguish between input and output. So is there any other way to change the particular blue color itself?
I searched across all the folders and noticed that it was hard coded. Developers have clearly stated like this as well
// Don't use 'blue' not visible on cmd.exe
So I replaced to some hexadecimal color in float.patch under core-util-is with in the array of colors.
-inspect.colors = {
- 'bold' : [1, 22],
- 'italic' : [3, 23],
- 'underline' : [4, 24],
- 'inverse' : [7, 27],
- 'white' : [37, 39],
- 'grey' : [90, 39],
- 'black' : [30, 39],
- '#FFF8DC' : [34, 39], // Blue got changed here
- 'cyan' : [36, 39],
- 'green' : [32, 39],
- 'magenta' : [35, 39],
- 'red' : [31, 39],
- 'yellow' : [33, 39]
-};
and in one more core-util-is. But still it's taking blue color itself. Also there is one more entry in readme.md script. Are they traversing that page as well? Please correct me if am doing anything wrong.
And is gulp-debug a good debug tool?
I haven't used gulp-debug, so I can't comment on the usefulness of it. After looking at the source code (https://github.com/sindresorhus/gulp-debug/blob/master/index.js), the output colors are hard coded. However, you can disable all colors for gulp, using --no-color.
Example:
gulp --no-color
Late to the party, but if you use an alternative console like Console2 you can remap output colours as you see fit :)

Resources