Set transparency of an image on openFrameworks - c++

I'm working on openFrameworks and I want to set the transparency of an image in order to modify it when I press a button, but I don't know how to implement this parameter.
In which way can I change this value? Is there a particular function to manage the transparency of an image?

check out http://openframeworks.cc/ofBook/chapters/intro_to_graphics.html
ofEnableAlphaBlending();
ofSetColor(255,0,0,127); # this would be a 50% transparent red color
ofDrawRectangle(20,20,100,100);
ofDisableAlphaBlending();

Related

Image overlap with alphachannel doesn't work on QT

I've put two label of the same dimension overlapped on my GUI. On the first, that is on the back there is one image set by the pixmap of the label. The second label has another image set by pixmap that is trasparent in some pixel. During design i can see the back image via the front image. When I execute the program, the trasparent pixel of the second image are transformed into white pixel, so i cant see the back image. I'm using QT 5.10. The image are in .png format.
I've resolved putting autoFillBackground on and i've changed the color of window in palette putting a transparent color

wxBitmap transparent background

I have a wxBitmap which can be hidden or revealed on a wxPanel. When the wxBitmap is hidden I would like it to have the background of the wxPanel, instead it has a standard grey background.
To illustrate my point here are two images:
Bitmap shown:
http://i.stack.imgur.com/PzpR9.png
Bitmap hidden:
http://i.stack.imgur.com/GWs7r.png
I tried applying a mask and using alpha channel for transparency, but these do not solve the problem. What I need to do is set the background of the wxBitmap.
Any ideas how I can accomplish this?
I have noticed that if I minimise the window and then show it again, the problem is solved - no default grey background when the bitmap is hidden. I do not know what operation this (minimise + maximise) procedure performs and I have not yet figured out how to implement it programmatically.

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

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.

Color Picker / Choser for an OpenGL Application

I am building an OpenGL application. I read through the GLUI tutorial on Code Project to create windows form controls on an OpenGL Application. But my requirement is to develop a color choser/picker, like an RGB chart or RGB cube to select a color. The tutorial on Code project shows the list of colors as a drop down box. However that wont really help me, as I require it to be present as a windows color picker. I know that color picker as a dialog box is a part of the windows application. Can anyone suggest me a way to use it with my OpenGL Application?
You can try fox-toolkit. It is a C++ based Toolkit for developing Graphical User Interfaces. It provides Color Picker and OpenGL widgets for 3D graphical manipulations.
On windows, you can call directly ChooseColor() from the windows API. It will open the native color color chooser.If you need a cross-platform solution, tiny file dialogs on sourceforge also has a color picker and no main loop.
You could render a Quad/Triangle/Cirle with different color on each vertex and activate smooth shading for interpolation between these points. Then just read back the color value from OpenGL at the mouse position.
edit: or like that where you calculate the color on the mouse position by yourself (reading values slows down OpenGL a lot!): http://sharathpatali.wordpress.com/2009/07/07/a-color-picker-for-pymt/
I did this with simple gradient image which i kept in memory. Then i just tracked my mouse position on the image, and simply read the data from the image (that was kept in RAM) and get the 32bit RGBA color value for it. This is easier than reading the pixels from screen (also faster and more reliable).
This also allows a lot more flexible way of presenting the palette, only your imagination is the limit on the looks of your palette. Note: you must use 32bit colors on the image, because if you want smooth edges, you simply just fade the alpha but keep the colors the same, so the colors wont get distorted at edges. Don't forget to enable blending when rendering the image.

win32 c++ owner draw button with transparent image

i've implemented a owner draw button into my win32 app (no MFC). The button is a normal 20x20 bitmap (round icon with transparency). The problem is that the button is positioned on a solid background and i can see the buttons gray background (since the bitmap is round). I've tried responding to WM_CTLCOLORBTN with NULL_BRUSH but no luck.. I've tried displaying the button using a bitmap and a ico file but wont budge.. Does anyone know how to solve this problem?
This is my problem, the settings icon should be transparent at the edges (not white/gray)
It sounds like you're trying to make a non-rectangular control.
You could call SetWindowRgn to tell Windows that your control is non-rectangular.
In addition to what #joel's answer, if you want to make some area transperant put a unique color in the area where you want to have transperancy using some image editors (RGB(0xFF,0x00,0xFF)) is mostly used Then use TransperantBlt
You say it's a solid background but your image shows some kind of orange-yellow gradient as a background. If it really was a standard windows button solid color you can load the bitmap with LoadImage using the LR_LOADMAP3DCOLORS or LR_LOADTRANSPARENT. Since you have a gradient you'll have to use a more complicated technique to mask out the bitmap.
http://www.winprog.org/tutorial/transparency.html