kevin42
kevin42

Reputation: 2128

Offscreen rendering to a texture in a win32 service

I'm trying to write a C++ windows service that can render to a texture. I've got the code working as a regular console app, but when run as a service wglGetProcAddress() returns NULL.

Can anyone tell me if this is possible, and if so, what do I need to do to make OpenGL work inside a service process?


Edit:

I still haven't got this to work under Vista, but it does work under XP.

Upvotes: 1

Views: 2870

Answers (3)

Shane Blackett
Shane Blackett

Reputation:

You can get a fully capable software renderer by using Mesa3D. Simply build Mesa3D and put the opengl32.dll built there alongside your application. This should enable you to use OpenGL 2.1 and extensions. We use this for testing Opengl applications in a Windows service.

Upvotes: 3

Coincoin
Coincoin

Reputation: 28606

OpenGL needs desktop access to create a render context and a service by default don't have desktop access.

You need to run the service in interactive mode. To do that go in the service properties in Administrative Tools. Where you set the service's log on user, you will have an option to run the service in interactive mode, or something similar as "Allow service to interact with desktop". You can try logging the service as another user too.

If you are working through a .Net IIS application, you will also have to force the managed part of the server to log as another user.

EDIT:

I forgot to say, a user must currently be logged on the accelerated hardware desktop and the machine must not be locked. That sucks but that's the only way I made it work before. We had dirty script that logged a user on as soon as the machine started.

As a side note, we were using DirectX, so it might not apply to OpenGL.

Upvotes: 0

Stephen Martin
Stephen Martin

Reputation: 9645

Services run in non-interactive desktops. These desktops do not connect to the physical display device of the computer but rather to logical display devices. The logical display devices are very basic generic VGA devices set to 1024 X 768 with no bells and whistles.

Services can use most GDI functions but no advanced graphics functions such as DirectX or OpenGL. So you can create windows, create or retrieve device contexts and do some fairly complex drawing and rendering but you can't use anything but straightforward GDI (and some GDI+).

If you check GetLastError after wglGetProcAddress returns NULL you should get the reason for the failure.

Upvotes: 1

Related Questions