0

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.

George Netu
  • 2,758
  • 4
  • 28
  • 49

2 Answers2

2

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.

Community
  • 1
  • 1
Elie Génard
  • 1,673
  • 3
  • 21
  • 34
  • I have managed to use the files from ofxTransparentWindow by eliminating the Cocoa stuff, but I only got a black screen. I have also read that discussion several times and it's hard to find something that could be integrated with OpenFrameworks, even if it's pure OpenGL. I think the only thing left is to try and load a image into a fullscreen window, delete all the pixels from it and the catch the events using the same "empty" image. Thank you for your answer. – George Netu Mar 25 '15 at 11:18
  • There is also [this](http://stackoverflow.com/questions/1617370/opengl-alpha-transparency) attempt, but I can't get it running with OF. – George Netu Mar 25 '15 at 13:47
1

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.

Danoli3
  • 3,203
  • 3
  • 24
  • 35