Thread: Canīt create an OpenGL screensaver

  1. #1

    Canīt create an OpenGL screensaver

    I've searched for tutorials everywhere I knew and read pretty much all OpenGL screensavers threads from here and gamedev, but I still couldnīt get it to work.
    I'm trying to get an opengl prog created with Nehe's OpenGL tutorial setup and make a screensaver from it. My father saw that flag effect and asked me If I could make a screensaver out of it for his company.
    I can only get it to work as a screensaver if I keep Winmain and use no textures at all. So as you can see I came up with a big mess
    Reading MSDN wasnīt such a big help either.

    Can anyone give me some leads? I'm completely lost this time.
    Also, I'm not interested in dealing with saving preferences to the registry nor having anything at all on it's Setup. Just the most basics will be more than great.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003

  3. #3
    Thanks for the link codeplug, wasnīt for lack of google I didnīt find it though, been trying to get this to work for more than 3 hours now.
    But even after looking through the source I donīt understand why my GLWindow is not being created, I try starting the app but nothing happens.
    I guess this might be too advanced for me, I'm still 4 months old with programming.

    I just tried placing a messagebox on WM_CREATE from LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) and it didnīt popup, so itīs never being called.
    Any ideas why? Shouldnt that be the first thing to start up?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Did you read the entire link at MSDN?


  5. #5
    I took a long brake, then came back and read it once more carefully, but sorry, still not ringing a bell .

    If someone knows of any good tutorial that deals with OpenGL screensavers please let me know.

    Thanks again Codeplug!

  6. #6
    Here, I'm uploading my code. I got rid of all drawing and functions so all it does is create a black GL screensaver window, thereīs not much to look at.

    And since WM_CREATE is never being called, I think I'm missing something obvious.
    If anyone can take a look I'd really appreciate, I'm having trouble figuring this out on my own.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    I think the problem is more likely to be with your compiling/building the code rather than the code itself.

    Have you got a .def file?

    How are you compiling it/what compiler?

  8. #8
    I was compiling it like a basic Windows GL application. Just changed the Windows procedure to ScreeSaverProc and added the extra stuff actually.

    I didnīt have a .def file anonytmouse. I have an example of one from Codeplug's link I can refer to, but I'm not sure how to add it to the project. All the .def references I found to hep me were dealing with DLLs.
    I'm using MS Visual 6.0
    Anything else that could be the problem?

  9. #9
    I found this tutorial:

    I shouldnīt have a problem now, thanks everyone for helping

    There was a similar link that was broken, and I skiped that one accidentaly.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Let us know how you fix it.


  11. #11
    I followed the tutorial, set up my resource properly, but still WM_CREATE is never being called for ScreenSaverProc.
    I'm completely clueless.
    That tutorial also didnīt say anything about setting up a .def file.
    Any ideas?

    - edit -

    Ok, here are my steps:

    1) Succesfully create the OpenGL App that I want to convert into a Screensaver.
    2) Include <scrnsave.h> and scrnsave.lib to my project.
    3) File, New, Resource.
    4) Add a String Table with first line as ID: IDS_DESCRIPTION, Value: 1
    5) Include "resource.h"
    6) Add LRESULT WINAPI ScreenSaverProc( HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam)
    7) Place a message box on WM_CREATE ( never pops )
    8) Add BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) returning FALSE and BOOL WINAPI RegisterDialogClasses(HANDLE hInstance) returning true.
    9) Star Comment WinMain just to be sure
    10) Compile with no errors and warnings.

    What am I missing?
    Last edited by the dead tree; 08-23-2004 at 08:34 PM.

  12. #12
    Well, this is as simple as it can get.
    I try to run it, but it acts like I'm not doing anything.

    #include <windows.h>
    #include <scrnsave.h>
    #include "resource.h"
    // ScreenSaver Procedure
    LRESULT WINAPI ScreenSaverProc( HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam)
     switch (uMsg) // Check For Windows Messages
     case WM_CREATE:
       MessageBox(NULL,TEXT("Test"),TEXT("Test"),IDOK); // Never being called
       return 0;
     // Pass All Unhandled Messages To DefWindowProc
     return DefScreenSaverProc(hWnd,uMsg,wParam,lParam);
    // Functions
     BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    	return FALSE;
    BOOL WINAPI RegisterDialogClasses(HANDLE hInstance)
      return TRUE;

  13. #13
    Join Date
    Jan 2002
    Take a look at the bottom of the msdn page that codeplug provided a link to (Handling screen savers) where it describes setting up a module defintion file (def file referred to by anonytmouse) which is required to export your ScreenSaverProc so that the system can call it.


    Alternatively, you can abandon using scrnsave.lib altogether but you'll have to parse the command line for various flags and do the message handling for just about everything else yourself. There used to be a great article for this in www-land called "How to write a 32bit screen saver" but all I've managed to find are dead links. Anyway, from the little I remember here's some of the command line flags passed to your screensaver that might get you started:
    /S or /s Start screensaver in full screen.
    /P or /p - show the screensaver in the little monitor window in the screen saver tab of display properties. A number follows this flag which is the handle to what should be the parent of your screensaver so you can size it to fit the little monitor window.
    /c display your configure dialog box. This, too, is followed by a number which should be used as the parent window handle of your dialog
    Actually, there seems to be a very slow page here that looks very much like the original How to write a 32bit screen saver but without the formatting or images. If you get tired of fighting with scrnsave.lib then you may be interested in trying that approach.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  14. #14
    i don't know how to deal with ScreenSaverProc but you don't really need it: you can write a saver with [WinMain]. i have done so in the past: i wrote a framework/sdk (called DEVIL Screensaver System) that does all you need:

    * cares about all the screensaver stuff
    * offers a class loading/saving settings for you

    check for full sourcecode and a little more info (home/news section) if you like.

    ps: i guess ScreenSaverProc doesn't call WM_CREATE by design. DialogProc doesn't either.

  15. #15
    Thanks for the help everyone, but I'm giving up.
    I will just make a normal WinMain exec and use a resource bitmap, then rename it to scr.
    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't create child windows
    By OnionKnight in forum Windows Programming
    Replies: 4
    Last Post: 04-10-2011, 04:13 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. first opengl game, problems.
    By n3v in forum Game Programming
    Replies: 1
    Last Post: 07-11-2006, 08:22 PM
  4. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 05:06 PM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
Website Security Test