Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Main.cpp File Reference

Implements the Shadow demonstration. More...

#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include "Const.h"
#include "Transformer.h"
#include "TransformerArcBall.h"
#include "TransformerPan.h"
#include "TransformerZoom.h"
#include "Application.h"
#include "Painter.h"
#include "PainterStencil.h"
#include "PainterPixelShader.h"

Namespaces

namespace  std

Functions

void displayString (int x, int y, const char *message)
 Displays a string at the given coordinates.

void displayStatus ()
 Displays the current status (frames per second).

void displayCallback ()
 Callback function invoked to render the contents of the GLUT window.

void reshapeCallback (int width, int height)
 Callback function invoked when the window is resized.

void setApplicationMatrix (Matrix &matrix)
 Update the Application matrix specified by s_transformationType with the contents of the current transformation matrix.

void mouseCallback (int button, int state, int x, int y)
 Callback function invoked when a mouse button is pressed or released.

void motionCallback (int x, int y)
 Callback function invoked when the mouse is moved while a button is pressed.

void menuCallback (int value)
 Callback function invoked when a menu entry is selected.

void idleCallback ()
 Called when the application is idle.

void initGLUT (int argc, char **argv)
 Initialize GLUT.

void initOpenGL ()
 Initialize OpenGL.

void cgErrorCallback ()
 Callback invoked when a Cg error is encountered.

void initCg (const char *fileName)
 Initialize Cg.

int main (int argc, char **argv)
 The entry point into the application.


Variables

const int K_WINDOW_WIDTH = 640
 Constant representind the default width of the application window.

const int K_WINDOW_HEIGHT = 480
 Constant representind the default height of the application window.

const float K_FRUSTUM_Z_NEAR = 1.0f
 Constant representind the distance from the eye to the 'near' frustum plane.

const float K_FRUSTUM_Z_FAR = 100.0f
 Constant representind the distance from the eye to the 'far' frustum plane.

const float K_FRUSTUM_FOV = 90.0f
 Constant representind the angle of the field of view.

int s_windowWidth
 The dimensions of the Window which appears on the screen.

int s_windowHeight
 The dimensions of the Window which appears on the screen.

int s_menuHandle
 The menu identifier for the application menu.

const int K_MENU_SCENE = 0
 Identifier for menu entry.

const int K_MENU_MODEL = 1
 Identifier for menu entry.

const int K_MENU_LIGHT = 2
 Identifier for menu entry.

CGcontext s_CgContext
 The Cg context in which the pixel shader code executes.

CGprofile s_CgProfile
 The Cg profile in which the pixel shader code executes.

CGprogram s_CgProgram
 The Cg pixel shader program.

Matrix s_transformationMatrix
 The current transformation matrix for the scene.

int s_transformationType
 The type of transformation matrix (Application::getSceneMatrix, Application::getModelMatrix, Application::getLightMatrix).

Transformers_transformer
 The Transformer which moves the objects on the screen.

Applications_application
 The Application that renders the scene.


Detailed Description

Implements the Shadow demonstration.

Author:
Razvan Surdulescu
Version:
1.0
Date:
2/15/2003

Function Documentation

void displayString int  x,
int  y,
const char *  message
 

Displays a string at the given coordinates.

Uses glutBitmapCharacter() to draw the string at the specified coordinates with the font GLUT_BITMAP_HELVETICA_12

void displayStatus  ) 
 

Displays the current status (frames per second).

This function should be called once per frame.

void displayCallback  ) 
 

Callback function invoked to render the contents of the GLUT window.

This function is invoked from motionCallback to render the scene when a new transformation has been defined by the user.

The scene is drawn by calling Application::draw

void reshapeCallback int  width,
int  height
 

Callback function invoked when the window is resized.

This function is invoked when the window first appears on the screen as well as everytime the window is resized.

The function updates the Transformer dimensions and sets up the perspective to use a specified FOV and Z range.

void mouseCallback int  button,
int  state,
int  x,
int  y
 

Callback function invoked when a mouse button is pressed or released.

The function ignores all but the left mouse button events.

If the left mouse button is pressed, the function starts a new transformation on the current Transformer.

If the left mouse button is released, the function sets the transformation matrix on the Application.

Since in GLUT coordinates the Y coordinate increases from top to bottom (which is backwards from the way OpenGL expects it) the y coordinate is flipped first.

void motionCallback int  x,
int  y
 

Callback function invoked when the mouse is moved while a button is pressed.

Computes the transformation matrix at the current mouse position by calling Transformer::end.

Since in GLUT coordinates the Y coordinate increases from top to bottom (which is backwards from the way OpenGL expects it) the y coordinate is flipped first.

void menuCallback int  value  ) 
 

Callback function invoked when a menu entry is selected.

Changes the transformation matrix and type based on the user selection.

void idleCallback  ) 
 

Called when the application is idle.

Refreshes the screen (glutPostRedisplay()).

void initGLUT int  argc,
char **  argv
 

Initialize GLUT.

Create the window, menu, and setup the appropriate callbacks.

void initCg const char *  fileName  ) 
 

Initialize Cg.

Setup the global Cg error callback (cgErrorCallback), create the global Cg context (s_CgContext), setup the Cg profile (s_CgProfile) and load the Cg pixel shader program (s_CgProgram).


Variable Documentation

Matrix s_transformationMatrix [static]
 

The current transformation matrix for the scene.

This matrix is initialized when the user presses the mouse button (to start defining a new transformation) and is updated when the user releases the mouse button (to end the current transformation).


Generated on Mon Aug 25 23:40:57 2003 for Shadow by doxygen 1.3.2