121 lines
3.1 KiB
C++
121 lines
3.1 KiB
C++
|
|
/* Author: Josh Holtrop
|
|
* DornerWorks screensaver
|
|
* This was a for-fun project I started working on in November '07
|
|
* because I like 3D graphics. I modeled the DornerWorks logo in
|
|
* blender, exported it to an Alias WaveFront object and material
|
|
* file, wrote an Alias Wavefront object loader, and then wrapped
|
|
* some OpenGL and ODE logic around it for various screensaver modes
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <SDL/SDL.h>
|
|
#include <SDL/SDL_syswm.h>
|
|
#include "displayinfo.h"
|
|
#include "ss/SSMain.h"
|
|
using namespace std;
|
|
|
|
#define PROGNAME "dwscr"
|
|
#define DEFAULT_WIDTH 1024
|
|
#define DEFAULT_HEIGHT 768
|
|
|
|
/* main function, called upon program invocation */
|
|
int main(int argc, char * argv[])
|
|
{
|
|
#ifdef WIN32
|
|
bool start = false;
|
|
#else
|
|
bool start = true;
|
|
#endif
|
|
SDL_Surface * sdlSurface;
|
|
int width = DEFAULT_WIDTH;
|
|
int height = DEFAULT_HEIGHT;
|
|
bool windowed = false;
|
|
bool multisample = true;
|
|
|
|
#ifdef DEBUG
|
|
start = true;
|
|
#endif
|
|
|
|
getDisplaySize(&width, &height);
|
|
|
|
/* extremely simple command-line argument handling */
|
|
for (int i = 1; i < argc; i++)
|
|
{
|
|
if (!strcmp("/s", argv[i]))
|
|
start = true;
|
|
else if (!strcmp("-W", argv[i]))
|
|
windowed = true;
|
|
else if (!strncmp("-w", argv[i], 2))
|
|
{
|
|
width = atoi( (strlen(argv[i]) > 2)
|
|
? argv[i] + 2
|
|
: argv[++i] );
|
|
}
|
|
else if (!strncmp("-h", argv[i], 2))
|
|
{
|
|
height = atoi( (strlen(argv[i]) > 2)
|
|
? argv[i] + 2
|
|
: argv[++i] );
|
|
}
|
|
else if (!strcmp("+m", argv[i]))
|
|
{
|
|
multisample = false;
|
|
}
|
|
}
|
|
|
|
/* make the SDL window appear in the top-left corner of the screen */
|
|
if (!windowed)
|
|
putenv("SDL_VIDEO_WINDOW_POS=0,0");
|
|
|
|
/* do not disable power management (this will allow monitors
|
|
* to power off at the normally configured timeout) */
|
|
putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");
|
|
|
|
if (!start)
|
|
return 0;
|
|
|
|
/* initialize SDL library */
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
|
|
{
|
|
cerr << "Error initializing video!" << endl;
|
|
return -1;
|
|
}
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
/* Enable multisampling */
|
|
if (multisample)
|
|
{
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
|
}
|
|
|
|
int sdlMode = SDL_HWSURFACE | SDL_OPENGL;
|
|
if (!windowed)
|
|
sdlMode |= SDL_NOFRAME;
|
|
if ((sdlSurface = SDL_SetVideoMode(width, height, 0, sdlMode)) == NULL)
|
|
{
|
|
cerr << "Error setting video mode!" << endl;
|
|
return -2;
|
|
}
|
|
|
|
SDL_WM_SetCaption("dwscr", "dwscr");
|
|
if (!windowed)
|
|
{
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
}
|
|
|
|
/* after our window is created and SDL and OpenGL are initialized,
|
|
* start the main screensaver functionality */
|
|
int num_monitors = windowed ? 1 : getNumMonitors();
|
|
SSMain ss(width, height, num_monitors, sdlSurface);
|
|
ss.run();
|
|
|
|
SDL_Quit();
|
|
return 0;
|
|
}
|