Again: Creating Screen Savers: How To?

Hello all

I know that this post is redundant but actually becuze I didn’t find a full answer to the subjact i will re-ask the Question again how to make A SCREEN SAVER using GLUT?

for example how to convert this code to a screen saver
#include <GL\glut.h>

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.0);
glVertex3f(-0.5,-0.5,-3.0);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.5,-0.5,-3.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.5,0.5,-3.0);
glEnd();
glFlush(); //Finish rendering
}

void Reshape(int x, int y)
{
if (y == 0 | | x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); //Use the whole window for rendering
}

int main (int argc, char **argv)
{
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(300,300);
//Create a window with rendering context and everything else we need
glutCreateWindow(“First Tutorial”);
glClearColor(0.0,0.0,0.0,0.0);
//Assign the two used Msg-routines
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
//Let GLUT get the msgs
glutMainLoop();
return 0;
}

I wish there r useful answers …

I wouldn’t use glut for a screensaver. You CAN do it, but it’s really ugly. You can just change the name of your .exe to .scr, but you’re also going to have to handle different command-line parameters. It’s much cleaner to use Win32’s screensaver library. I’ve got an Appwizard for VC++ that will setup the screensaver project for you. It doen’t currently initialize OpenGL, so you’ll have to use SetPixelFormat, etc. If you want it, it’s at http://www.lycanth.com/MiscFiles/scrnapp.zip

Hello there thanx for the fast response
but can u tell me how to export the code i gave into ur project … can u do that for me as an example\ hanx alot

Originally posted by Deiussum:
I wouldn’t use glut for a screensaver. You CAN do it, but it’s really ugly. You can just change the name of your .exe to .scr, but you’re also going to have to handle different command-line parameters. It’s much cleaner to use Win32’s screensaver library. I’ve got an Appwizard for VC++ that will setup the screensaver project for you. It doen’t currently initialize OpenGL, so you’ll have to use SetPixelFormat, etc. If you want it, it’s at http://www.lycanth.com/MiscFiles/scrnapp.zip

Basically… for the WM_CREATE message you will use ChoosePixelFormat, DescribePixelFormat, and SetPixelFormat. (Not necessarily the BEST way, but probably the easiest way to initialize the window w/o Glut. Check the Nehe tutorials on how to use these.) After initialization, you can call your reshape function. (Or wait for a WM_SIZE message, but since it’s a screensaver, it’s not going to get resized after creation so it works just as well in WM_CREATE.)

In the WM_PAINT message, you can call your display function.

Include the GL/gl.h and GL/glu.h headers (AFTER windows.h), add the opengl32.lib and glu32.lib libraries to the project (Project settings->link->external modules), compile, and you should be ready to go.

[This message has been edited by Deiussum (edited 02-12-2001).]