George Netu
George Netu

Reputation: 2822

Transparent background window in OpenFrameworks

I am trying to create an invisible overlay that captures touch events (which will be responsible with sending packets using oscpack). Therefore, I need to create a transparent fullscreen window. (EDIT: win32 would be just fine if cross compatibility is a problem)

In the official documentation, ofBackground seems to accept alpha blending, but when I write ofBackground(0, 255, 0, 10); and run the project, the window is not transparent. I also tried using ofEnableAlphaBlending();, but the result was the same. (I think it only enables the alpha blending for new drawn stuff)

I tried to dig some more and I found a little comment inside this method:

ofAppGlutWindow::setupOpenGL(int w, int h, int screenMode)
{
//code
}

/*
    ofBackground(200,200,200);      // default bg color
            ofSetColor(0xFFFFFF);           // default draw color
            // used to be black, but
            // black + texture = black
            // so maybe grey bg
            // and "white" fg color
            // as default works the best...
            */

This didn't help me as much as I thought initially, I am still stuck.

Upvotes: 0

Views: 1900

Answers (2)

Danoli3
Danoli3

Reputation: 3233

As of March 2023! You can now for Windows, macOS and Linux use the following setting to enable transparency in GLFW openFrameworks.

ofGLFWWindowSettings settings;
settings.transparent = true;

So the following would be an example main.cpp:

int main( ){

//Use ofGLFWWindowSettings for more options like multi-monitor fullscreen
ofGLFWWindowSettings settings;
settings.setSize(1024, 768);
settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN
settings.glVersionMajor = 3.0;
settings.glVersionMinor = 3.0;
settings.transparent = true;
auto window = ofCreateWindow(settings);

ofRunApp(window, make_shared<ofApp>());
ofRunMainLoop();
}

And then all you would need to do, is clear the backbuffer each frame via the ofClear method.

ofClear(0.0f, 0.0f, 0.0f, 0.0f);

So in an example ofApp::draw() with at the start clearing that buffer

void ofApp::draw(){
     ofClear(0.0f, 0.0f, 0.0f, 0.0f);

    // other draw code after clear 
}

Technically this was made possible by GLFW Hint - GLFW_TRANSPARENT_FRAMEBUFFER which now uses settings.transparent for it's value.

Upvotes: 1

Elie G&#233;nard
Elie G&#233;nard

Reputation: 1683

You can't do this with openFrameworks directly. You need to create an OpenGL context with a transparent background. It's pretty difficult to do and I don't know if you can integrate it with oF but you can test this.

However if you are on OSX, there is this addon: ofxTransparentWindow

A dirty trick would be to grab an image of your desktop and put it as a background in your ofApp.

Upvotes: 2

Related Questions