Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [a5] Can shaders be created and used without creating a display?

This thread is locked; no one can reply to it. rss feed Print
[a5] Can shaders be created and used without creating a display?
Mark Oates
Member #1,146
March 2001
avatar

Looking at some code, I see Allegro's shaders are prepared by using the ALLEGRO_PROGRAMMABLE_PIPELINE flag for al_set_new_display_flags.

I don't have enough understanding of the GL APIs below the Allegro layer, but based on this design it seems that displays are a required dependency? Is this a limitation of Allegro (or, should I say, the "median" of GL APIs that Allegro wraps), or is there a way to access shader rendering without creating a display?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

That's just the way it works. To create a shader, you need an OpenGL context. To create an OpenGL context, you need a display. Allegro doesn't support custom GL contexts without a display.

You're more than welcome to set it all up yourself. ;)

Erin Maus
Member #7,537
July 2006
avatar

Do you want to render using shaders without creating a physical window on the screen? I.e., have a completely off-screen GL context?

That is possible but you might have to drop down to lower level platform-specific APIs for that, or use platform-specific APIs to hide the Allegro window after creation.

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Mark Oates
Member #1,146
March 2001
avatar

Erin Maus said:

Do you want to render using shaders without creating a physical window on the screen? I.e., have a completely off-screen GL context?

Yea, in this special narrow case that's what I'm looking for. It's not critical, but would make for cleaner testing.

Another thing I'm creepin' for is the ability to spawn new displays underneath the topmost window (so as not so take focus from the current window).

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Erin Maus said:

Do you want to render using shaders without creating a physical window on the screen? I.e., have a completely off-screen GL context?

Yea, in this special narrow case that's what I'm looking for. It's not critical, but would make for cleaner testing.

Another thing I'm creepin' for is the ability to spawn new displays underneath the topmost window (so as not so take focus from the current window).

Just use al_set_new_display_position :

al_set_new_display_position(-10000,-10000);

8-)

MikiZX
Member #17,092
June 2019

On Windows you could use: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow?redirectedfrom=MSDN to hide a window (though I only assume the OpenGL context remains active - I think it should).

On Linux or OSX I am not sure - some Google-ing gives this: https://stackoverflow.com/questions/26836430/hiding-active-window-in-linux

Chris Katko
Member #1,881
January 2002
avatar

Yea, in this special narrow case that's what I'm looking for. It's not critical, but would make for cleaner testing.

I mean, what would rendering mean, without a device context? If the device is in 8 bit color, it renders in 8-bit color. 24-bit, 32-bit. 800x600, 1280x720, ... RGB vs BGR, as well as setting giving the user all the relevant function pointers. If there's no device (even a "virtual" one)... that'd be like drawing using pencils with no piece of paper. What does "drawing a beautiful girl" mean when you're just waving pencils in the air?

Now, I've read you can use the desktop window as a kind of root context "as long as you're sure to not draw to it".

The alternative (listed above) is to simply hide the window. That seems to be the most common situation.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Mark Oates
Member #1,146
March 2001
avatar

The behaviour I'm curious about is the ability to load up a Shader and render with it, without having to create a window instance with the OS.

This is similar to being able to draw to a software-created ALLEGRO_BITMAP, without having to create a display. I'd like to draw to it with a Shader on, and then read from the bitmap (pluck a pixel or two) to check it rendered as expected, or possibly save the bitmap to a file on the filesystem.

The other concern, having a window that I do want created to spawn underneath the current focused window, is a different thing altogether. It solves a different problem, which is that the created windows interrupt the current focus. That means I don't want to create-and-then-hide, because that will still break the focus. Here, I'm looking for something like a new display flag to spawn underneath the current window, or at the bottom of the window drawing order.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

MikiZX
Member #17,092
June 2019

I am not sure how much this will help...
If you are on Windows OS (Vista or newer) then possibly you could start your Allegro app programmatically, within a hidden desktop (please note I've never used this so take this just as an idea to explore - I have no idea how well shaders and hw acceleration work under these):
https://stackoverflow.com/questions/53573561/creating-a-secure-desktop-on-current-windows-session-winsta0-default
More info on hidden desktops: https://docs.microsoft.com/en-us/windows/win32/winstation/about-window-stations-and-desktops

Also, for starting your application without it taking focus, possibly running your app/launcher app as a service could be a solution?
This one approach would need to be tested - not sure how relevant it is here: https://social.msdn.microsoft.com/Forums/windows/en-US/3b98feb6-3a65-49d0-97e5-825529658591/how-could-i-run-an-opengl-application-as-a-service-need-to-make-sure-its-always-running?forum=windowscompatibility

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: