18 #include "../../include/Draw.h"    23   info = (
char *)malloc(256*
sizeof(
char));
    24   Number = (
char *)malloc(100*
sizeof(
char));
    32   pixel = (GLubyte*)malloc(
sizeof(GLubyte));
    39 void Draw::Shout(
const char * s, ...)
    44   vfprintf(stderr, s, args);
    45   fprintf(stderr, 
"\n");
   109   glutInit(&argc,argv);
   110   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
   111   glutInitWindowSize(
ImWidth,ImHeight);
   126   glutTimerFunc(0,Timer,0);
   127   glutDisplayFunc(Figure);
   128   glutReshapeFunc(reshape);
   130   glutMouseFunc(mouse);
   131   glutKeyboardFunc(keyboard);
   132   glutMotionFunc( MouseMove );
   133   glutSpecialFunc(special);
   142   glClearColor(.0,.0,.0,.0);
   146   glutTimerFunc(30,Timer, 0);
   151 void Draw::Illuminazione(
void){
   153   glEnable(GL_DEPTH_TEST);
   154   glDepthFunc(GL_LESS);
   163   glShadeModel(GL_SMOOTH);
   164   glEnable(GL_POINT_SMOOTH);
   165   glEnable(GL_LINE_SMOOTH);
   166   glEnable(GL_ALPHA_TEST);
   167   glAlphaFunc(GL_GREATER,0.1);
   173   glReadBuffer(GL_FRONT);
   178   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
   179   glCullFace(GL_FRONT_AND_BACK);
   184   GLfloat ambientMaterial[4]     = { .5, .5, .5,1.};
   185   GLfloat diffuseMaterial[4]     = { .0, .0, .0,1.};
   186   GLfloat specularMaterial[4]    = { .0, .0, .0,1.0};
   187   GLfloat shininessMaterial      = 25.0;
   188   GLfloat emissionMaterial[4]    = { .0, .0, .0,1.};
   189   GLfloat riflettivitaSpeculare[]= { 0.0, .0, .0,1.};
   197   glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,DrAmbientWhite);
   198   glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,DrDiffuseWhite);
   199   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,DrSpecularWhite);
   200   glMaterialf(GL_FRONT,GL_SHININESS,shininessMaterial);
   201   glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emissionMaterial);
   202   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,riflettivitaSpeculare);
   203   glMaterialfv(GL_BACK,  GL_AMBIENT,   DrAmbientGreen); 
   204   glMaterialfv(GL_BACK,  GL_DIFFUSE,   DrDiffuseGreen); 
   205   glMaterialfv(GL_FRONT, GL_AMBIENT,   DrAmbientBlue); 
   206   glMaterialfv(GL_FRONT, GL_DIFFUSE,   DrDiffuseBlue); 
   207   glMaterialfv(GL_FRONT, GL_SPECULAR,  DrSpecularWhite); 
   208   glMaterialf( GL_FRONT, GL_SHININESS, 25.0); 
   210   GLfloat DrPropertiesAmbient [] = {0.50, 0.50, 0.50, 1.00}; 
   211   GLfloat DrPropertiesDiffuse [] = {0.75, 0.75, 0.75, 1.00}; 
   212   GLfloat DrPropertiesSpecular[] = {1.00, 1.00, 1.00, 1.00}; 
   214   glEnable(GL_LIGHTING);
   217   glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1.0);
   218   glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0); 
   220   glEnable( GL_LIGHT0 );
   221   glLightfv( GL_LIGHT0, GL_AMBIENT,  DrPropertiesAmbient); 
   222   glLightfv( GL_LIGHT0, GL_DIFFUSE,  DrPropertiesDiffuse); 
   223   glLightfv( GL_LIGHT0, GL_SPECULAR, DrPropertiesSpecular); 
   224   GLfloat LightPos0[]={
xl0,yl0,zl0, 0.0f };
   225   GLfloat LightPos1[]={
xl1,yl1,zl1, 0.0f };
   226   glLightfv(GL_LIGHT0, GL_POSITION,LightPos0);
   228   glLightfv(GL_LIGHT1, GL_AMBIENT, DrPropertiesAmbient);    
   229   glLightfv(GL_LIGHT1, GL_DIFFUSE, DrPropertiesDiffuse);    
   230   glLightfv(GL_LIGHT1, GL_POSITION,LightPos1);
   231   glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
   232   glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
   233   glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);
   234   glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);
   235   glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
   238   glViewport(0,0,(GLsizei)  w, (GLsizei) h);
   243   glMatrixMode(GL_PROJECTION);
   247     gluPerspective(30,(GLfloat) w/(GLfloat) h,.1,200.);
   255     glEnable(GL_DEPTH_TEST);
   257   glMatrixMode(GL_MODELVIEW);
   260   gluLookAt( 0., 0.,1.5,
   267 void Draw::Spot(
void){
   268   GLfloat direzioneSpot[3]       = { .0, 1.0, 1.0};
   269   GLfloat coloreNebbia[]         = { 0.2, 0.2, 0.2,1.};
   270   GLfloat esponenteSpot          = 1.5;
   271   GLfloat angoloSpot             = 120.;
   272   glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,angoloSpot);
   273   glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,direzioneSpot);
   274   glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,esponenteSpot);
   276 void Draw::Nebbia(
void){
   277   GLfloat zIniNebbia             = 10.;
   278   GLfloat zFinNebbia             = -10.;
   279   GLfloat DensitaNebbia          = 1.;
   281   glFogf(GL_FOG_START,zIniNebbia);
   282   glFogf(GL_FOG_END,zFinNebbia);
   283   glFogi(GL_FOG_MODE,GL_EXP);
   284   glFogf(GL_FOG_DENSITY,DensitaNebbia);
   286 void Draw::ChangeSize(GLsizei w,GLsizei h){
   291   aspectRatio=(GLfloat)w/(GLfloat)h;
   293   glMatrixMode(GL_PROJECTION);
   296     glOrtho(-100.,100.,-100./aspectRatio,100.
   297        /aspectRatio,1.,-1.);
   299     glOrtho(-100*aspectRatio,-100*aspectRatio,
   301   glMatrixMode(GL_MODELVIEW);
   305   char *
Number = (
char *)calloc(50,
sizeof(
char));
   306   sprintf(Number,
"%d",n);
   309       (Pos[2]*InvScaleUn));
   310   for (
int l = 0; l < strlen(Number); l++) {
   311     glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, Number[l]);
 double InvScaleUn
Rescale the three orthogonal directions. 
 
void Dreshape(int w, int h)
Principal reshape function. 
 
GLfloat IncrVisDxSx
Increment visual DxSx, SuGiu. 
 
void ReadScript()
Reads and draw a script file. 
 
int ne
Enables/disables fog. 
 
GLuint XCenter
Center of the frame. 
 
int sp
Enables/disables spot light. 
 
GLfloat xl1
Position of the light1. 
 
int Values
Number of values to divide the edge in squares. 
 
int WinHeight
Height of the window. 
 
GLuint YCenter
Center of the frame. 
 
int ImWidth
Width and height of the image. 
 
int MainWindow
Refers to optional different windows. 
 
void DTimer(int v)
Not working. 
 
void InitConstant()
Initializes all the view constants. 
 
GLfloat xl0
Position of the light0. 
 
int yRem
Old y position of the mouse. 
 
void Lista(int NSquare)
Definition of the primitives. 
 
int xRem
Old x position of the mouse. 
 
void ChooseBlend(int Which)
Choose a different blending function. 
 
void Window(int argc, char **argv)
Initial definition of the window. 
 
int WinWidth
Width of the window. 
 
char * Number
Characters for the grid. 
 
int NLevel
Levels of the images data (usually 4=RGBA) 
 
void Numera(double *Pos, int n)
Print the. 
 
GLubyte * pixel
Principal image (always allocated) 
 
void ReadConf()
Reads and applies external configurations.