home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
egltk22.zip
/
sample2.cpp
< prev
next >
Wrap
Text File
|
1998-07-30
|
11KB
|
248 lines
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Sample Escape GL Custom Screen Saver
// Copyright (c) 1997, Snow Storm Software
// All Rights Reserved
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "glcustom.hpp"
#include <glut.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// general instructions:
// - copy this file to another name eg. cool.cpp
// - modify all functions examples to provide the processing you desire
// - add your project to the 'TARGETS =' part of 'MAKEFILE.' eg. 'TARGETS = sample.egl cool.egl'
// - make sure the 'TOP =' part of 'MAKEFILE' correctly identifies the location of your opengl base directory
// eg. 'TOP = \opengl'
// - build your project using 'nmake'
// - copy your new screen saver module 'cool.egl' to any Escape GL sub-directory
// - reload Escape GL
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// new class definition
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static class SampleModel
: public GLCustomModelV2
{
public:
SampleModel();
virtual ~SampleModel(); // virtual destructor
virtual void initialize(); // virtual function to initialize the model
virtual void destroy(); // virtual function to destroy the model
virtual void animate( GLfloat fStep ); // virtual function to animate the model
virtual void display(); // virtual function to display the model
virtual void reshape( long width, long height ); // virtual function to reshape the viewport
virtual void addSettings(); // virtual function to add settings definitions
private:
GLfloat rotation;
GLboolean spin;
GLint quality;
char *text;
Point3D point;
} sample;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// global variables, constants, common functions, other classes
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// constructor
// creates the model object
// do not perform any OpenGL commands in the constructor, they will not work
// the constructor is only called once, when the model is created the first time
//
// GLCustomModel takes as its parameter the name of the module as it will appear
// in the drop down module list, this name must be unique and not match any
// existing modules, nor custom modules
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SampleModel :: SampleModel()
: GLCustomModelV2( "Cube Sample 2" )
, rotation( 0 )
{
//
// all of the following settings are the defaults, only use to change the defaults
//
//setDoubleBuffered( GL_TRUE ); // set double buffered flag
//setFPS( 10. ); // set the desired maximum frames per second
//setMaxStepSize( 0.25 ); // set the maximum step size (seconds)
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// destructor
// destroys the object
// this is only called when the program is exited, not when the model is changed, use destroy to
// destroy anything related to the actual model use
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SampleModel :: ~SampleModel()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// initialize
// initializes the opengl module you wish to display and is called once before the model is animated
// this function is called once to setup the module
//
// retrieve any settings here, not in the constructor
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: initialize()
{
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glShadeModel( GL_FLAT );
spin = getOnOffSetting( "Spin" );
//
// the quality setting is not used for this sample, however is presented as an example.
//
quality = getNumericSetting( "Quality" );
//
// the directory setting is not used for this sample, however is presented as an example.
//
char dir[256], file[256];
GLboolean inc;
getDirectorySetting( "Dir", dir, file, &inc );
//
// the text setting is not used for this sample, however is presented as an example.
//
text = getTextSetting( "Text" );
//
// the point setting is not used for this sample, however is presented as an example.
//
point = getPointSetting( "Color" );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// destroy
// destroy display lists, objects etc. when the module has ended
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: destroy()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// animate
// animates and displays the module
// the parameter 'step' simply defines the time in seconds between time steps, use this to control the animation speed
// the size of the step is based on the speed of the target system and the complexity of the module, slower modules
// will take larger steps
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: animate( GLfloat step )
{
if ( spin )
{
rotation += step * 270.; // rotate at 30 deg per second
if ( rotation > 360.0 )
rotation -= 360.;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// display
// display the model
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: display()
{
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 1.0, 1.0 );
glLoadIdentity(); /* clear the matrix */
/* viewing transformation */
gluLookAt( 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
/* rotate */
glRotatef( rotation, 0, 1, 0 );
glutWireCube( 1.0 );
// NOTE: swapping of the buffers is done automatically by Escape GL and should not be added here.
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// reshape
// resizes the window
// use this function to define the viewport and projection transformations based on the window size
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: reshape( GLint width, GLint height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 1.5, 20.0 );
glMatrixMode( GL_MODELVIEW );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// addSettings
// add your custom settings here
// simply use the add* function to add the type of setting you want
// leave this function blank if no settings are required
// NOTE: settings are displayed in reverse order, so add the setting you want first, last
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SampleModel :: addSettings()
{
//
// sample settings, add or remove these as desired
//
addOnOffSetting( "Spin", "Spin the Model", // id, prompt
"Spin: indicates if the model will spin.", // help
1 ); // default (0 = off, 1 = on)
addNumericSetting( "Quality", "Quality (1 lowest, 3 highest)", // id, prompt
"Quality: model quality.", // help
1, 1, 3 ); // default, minimum, maximum
addDirectorySetting( "Dir", "\\os2\\bitmap", "*", 0 ); // id, default directory, file default, include subdirectories default
addDescription( "Module Description" ); // this description shows up at the top of the help notebook page
setDefaultWindowSize( 7 ); // set the default window size
setDefaultFloatingWindow( 1 ); // set the default for floating windows
addTextSetting( "Text", "Text String", // id, prompt
"Text String: text help", // help
"default text" ); // default
addPointSetting( "Color", "Color", "Color: color of object", // id, prompt, help
Point3D( 5, 5, 5 ), // default 3D point value
0, 360 ); // minimum and maximum of values
}