Is it possible to draw on an SFML window regardless of views? - c++

I have a game I'm currently working on, and it uses multiple views (for a minimap for example).
Thing is, I would like to have a fading effect added at some point, so I thought I'd create a black image that is the size of the screen and change its alpha value with a timer. That part is not a problem.
What happens right now is the main area (ie window default view) is fading (because the opacity of the image is increasing), but the minimap (minimap view) is unaffected. This is normal behaviour for views, but is there a way to draw an image to the whole window, regardless of the views ?
Thanks in advance

To clarify, you have the default view where you'll draw the main game, then you'll have the minimap view where you would draw the minimap. At some point in the game you want the whole screen to fade to black. It sounds like you've been trying to draw a black image on the default view (changing the alpha) to make this effect work.
So, you need a third view that you draw your black image on to get this fading effect.

Related

Draw semi transparent shadow around Window

I'm trying to do something like what Auslogics Disk Defrag does with its custom window:
As can be seen, the blurred semi transparent shadow surrounding the window is much darker than the standard one, so the program must be drawing it by itself. The problem is, I can't find a way to paint anything transparent around a window.
In an answer to a similiar question, someone suggested creating a slightly bigger transparent window (using WS_EX_LAYERED + SetLayeredWindowAttributes()) behind the actual application window, and then do the translucent drawing on the transparent one. Not only does it sound like an ugly hack, it doesn't actually work. If, for example, one tries to draw a semi transparent black rectangle on a transparent window via GDI+, alpha blending is applied to the shape's color over the window background color (which would also be the transparency color) and then the shape is drawn with the calculated color, which obviously is not the window transparency, resulting in an opaque rectangle.
The semi transparent shadow is actually done by Gaussian Blur of the black square.
You can use this effect to create glows and drop shadows and use the
composite effect to apply the result to the original image. It is
useful in photo processing for filters like highlights and shadows.
You can use the output of this effect for input into lighting effects,
like the Specular Lighting or Diffuse Lighting effects, because the
alpha channel is blurred, too and lighting effects use the alpha
channel to determine surface geometry as a height map.
This effect is used by the built-in Shadow effect.
Refer: Gaussian blur effect
Then remove the standard frame, the entire window is your client area, so you can draw shadow in the extended frame.
Refer: Drawing in the Extended Frame Window
I think I've found a solution that works for me. I was hoping I wouldn't have to create an extra window just for the shadow, but every method I could find or think of would require me to draw all the controls by myself and/or somehow correct their alpha values.
So, I'm using a layered window with per pixel alpha. I paint over it with Direct2D, or, alternatively, I use some PNGs with transparency for the edges and corners of the shadow and copy them on a memory DC. Either way I simply recreate the shadow with the right dimensions when the window is resized, and call UpdateLayeredWindowIndirect. Both methods seem to be working well on Windows 7 and 10, and so far I haven't found any glitches.
Preventing it from showing on the taskbar was a bit tricky. All the ways I know have drawbacks. What worked best for me was making the layered window owned by the main one. At least that way it will only be visible on the desktop where the program is actually running, unlike other alternatives which would force it to show on every virtual desktop. Finally, because I disable that window, I interact with it by processing WM_SETCURSOR.

QOpenGLWidget: cannot disable blending (Qt5.10)

I have an app written in Qt5.10 using QOpenGLWidget. I use raw OpenGL calls to draw on the widget.
If I have some viewport area that is drawn with alpha <1.0 this area is not drawn anew, but rather it looks like it's drawn over the previous state of the widget.
When I switch between different Windows apps, it's drawing over previous contents of the screen rendered by a different apps.
I don't change the default update behaviour of the widget.
I set the default SurfaceFormat as follows:
QSurfaceFormat surfaceFormat = QSurfaceFormat::defaultFormat();
surfaceFormat.setRedBufferSize(8);
surfaceFormat.setGreenBufferSize(8);
surfaceFormat.setBlueBufferSize(8);
surfaceFormat.setAlphaBufferSize(8);
surfaceFormat.setStencilBufferSize(8);
surfaceFormat.setDepthBufferSize(16);
surfaceFormat.setSamples(4);
surfaceFormat.setRenderableType(QSurfaceFormat::RenderableType::OpenGL);
surfaceFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile);
surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
QSurfaceFormat::setDefaultFormat(surfaceFormat);
I was trying to add calls to glClear and glInvalidateFramebuffer in random places in the code, but it didn't seem to help.
What should I do to force redrawing of the widget?

How to avoid pixel fighting when drawing on display with SetPixel?

I am using SetPixel(GetDC(0),x,y,color) to write on the screen but as I do that, some other program updates it's screen and overwrites my drawn pixel thus the image drawn on screen appear to sparkle.
How Can I avoid this and draw something on the screen without the fear that it will be overwritten?
The screen is a shared resource. If you want something that is exclusively yours, create a window and draw into that.

Cocos2d sprite is drawn outside screen when transition

When I do page transition that shows the outside part of the stage (like CCTransitionFlipX), I can briefly see the sprites outside the screen while transition. It is really annoying. I thought I can manually check the position of the sprite in realtime and remove if it is off the screen. But that won't work if that sprite is partially outside. Is there something like UIKit's clipSubviews in cocos2d?
There's a ClippingNode class that might help.
Since the flip animation allows the user to see more than just the visible screen area, because the screen rotates, I think the behavior you observed may be expected.

SFML Text appears gigantic in small View

I've encountered a problem drawing SFML Text. In my application, I use views as a sort of coordinate system for my application. Thus, a typical view would be 10 x 10 or 20 x 20. All my normal drawing functions work fine, when drawing primitives and lines, etc., and the relevant code doesn't have to know about the coordinate system.
However, when I tried to draw text to the screen, I found that it appeared gigantic. When I reduced the font size drastically, it appeared extremely blurry and pixellated, as if it were trying to render to GIANT pixels that are 1x1 in my view.
Is there a way to draw text with a standard font size, in a way that it won't be affected by the view? Ideally, my text would width/size-wise on any view? How can I accomplish this?
Thanks for any input!
(P.S., I'm using SFML 2.0, for reference)
You can set another view (i.e. apply OpenGL transformation) and render text after it. Here is an example from sfml tutorial:
sf::View View(sf::FloatRect(600, 700, 1400, 1300));
App.SetView(View);
// Draw the game...
App.SetView(App.GetDefaultView());
// Draw the interface...