Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

general.h File Reference

#include "shared.h"
#include "polygon.h"
#include "texture.h"

Go to the source code of this file.

Functions

void SetGLScene (POLYGON *)
void SetGLProperties ()
void SetGLProjection (int Width, int Height)
void SetGLView (int Width, int Height)
void SetGLMaterial ()
void SetGLLighting ()
void SetGLTexture (TEXTURE *)
void DrawGrid ()
void DrawCube (POLYGON *, TEXTURE *)
void DrawSphere ()
void DrawCone ()


Function Documentation

void DrawCone  
 

Definition at line 313 of file general.cpp.

Referenced by DrawGLScene().

00314 {
00315     float mat_ambient[] = { 0.1, 0.5, 1.0, 1.0 };
00316     float mat_diffuse[] = { 0.1, 0.5, 1.0, 1.0 };
00317     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00318     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00319 
00320     glDisable(GL_TEXTURE_2D);
00321     glDisable(GL_CULL_FACE);
00322     glPushMatrix();
00323     glTranslatef(3.0f,-2.0f,-8.0f);
00324     glRotatef(-90,1,0,0);
00325     GLUquadricObj * cylinder = gluNewQuadric();
00326     gluQuadricOrientation(cylinder, GLU_OUTSIDE);
00327     gluCylinder(cylinder,1.0,0.0,2.0,20,20);
00328     glPopMatrix();
00329     glEnable(GL_CULL_FACE);
00330     glEnable(GL_TEXTURE_2D);
00331 }

void DrawCube POLYGON  ,
TEXTURE  
 

Definition at line 226 of file general.cpp.

References polygon, and texture.

Referenced by DrawGLScene().

00227 {
00228         float mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 };
00229         float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
00230         glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00231         glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00232 
00233         glBindTexture(GL_TEXTURE_2D, texture[0].TexID);
00234 
00235         glPushMatrix();
00236     glTranslatef(0.0f,0.0f,-5.0f);
00237     glBegin(GL_TRIANGLES);
00238         // Front Face
00239             glNormal3fv(&polygon[0].Vertex[0].nx);
00240         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[0].x);
00241         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[1].x);
00242         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[0].Vertex[2].x);
00243 
00244         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[1].Vertex[0].x);
00245         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[1].x);
00246         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[2].x);
00247         // Back Face
00248             glNormal3fv(&polygon[2].Vertex[0].nx);
00249         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[0].x);
00250         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[1].x);
00251         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[2].Vertex[2].x);
00252 
00253         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[3].Vertex[0].x);
00254         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[1].x);
00255         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[2].x);
00256         // Top Face
00257             glNormal3fv(&polygon[4].Vertex[0].nx);
00258         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[0].x);
00259         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[1].x);
00260         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[4].Vertex[2].x);
00261 
00262         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[5].Vertex[0].x);
00263         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[1].x);
00264         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[2].x);
00265         // Bottom Face
00266             glNormal3fv(&polygon[6].Vertex[0].nx);
00267         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[0].x);
00268         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[1].x);
00269         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[6].Vertex[2].x);
00270 
00271         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[7].Vertex[0].x);
00272         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[1].x);
00273         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[2].x);
00274         // Right face
00275             glNormal3fv(&polygon[8].Vertex[0].nx);
00276         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[0].x);
00277         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[1].x);
00278         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[8].Vertex[2].x);
00279 
00280         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[9].Vertex[0].x);
00281         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[1].x);
00282         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[2].x);
00283         // Left Face
00284             glNormal3fv(&polygon[10].Vertex[0].nx);
00285         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[0].x);
00286         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[1].x);
00287         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[10].Vertex[2].x);
00288 
00289         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[11].Vertex[0].x);
00290         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[1].x);
00291         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[2].x);
00292     glEnd();
00293         glPopMatrix();
00294 }

void DrawGrid  
 

Definition at line 203 of file general.cpp.

Referenced by DrawGLScene().

00204 {
00205     glDisable(GL_TEXTURE_2D);
00206     glDisable(GL_LIGHTING);
00207     glPushMatrix();
00208     glTranslatef(0,-2.0,0);
00209     float Line = -10;
00210     int Grid;
00211     glBegin(GL_LINES);
00212     for(Grid = 0; Grid <= 20; Grid += 1)
00213     {
00214         glColor3f(0.0f,1.0f,0.0f);
00215         glVertex3f(Line + Grid, 0, -10);
00216         glVertex3f(Line + Grid, 0, 10);
00217         glVertex3f(-10, 0, Line + Grid);
00218         glVertex3f(10, 0, Line + Grid);
00219     }
00220     glEnd();
00221     glPopMatrix();
00222     glEnable(GL_TEXTURE_2D);
00223     glEnable(GL_LIGHTING);
00224 }

void DrawSphere  
 

Definition at line 296 of file general.cpp.

Referenced by DrawGLScene().

00297 {
00298     float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
00299     float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
00300     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00301     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00302 
00303     glDisable(GL_TEXTURE_2D);
00304     glPushMatrix();
00305     glTranslatef(-3.0f,-1.0f,-8.0f);
00306     GLUquadricObj * sphere = gluNewQuadric();
00307     gluQuadricOrientation(sphere, GLU_OUTSIDE);
00308     gluSphere(sphere,1.0,50,50);
00309     glPopMatrix();
00310     glEnable(GL_TEXTURE_2D);
00311 }

void SetGLLighting  
 

Definition at line 187 of file general.cpp.

Referenced by InitGL().

00188 {
00189     float light_ambient[] = {0.2, 0.2, 0.2, 1.0};
00190     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
00191     float light_position[] = {-3.0, 2.0, 1.0, 1.0};
00192     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00193     glEnable(GL_LIGHTING);
00194     glEnable(GL_LIGHT0);
00195 }

void SetGLMaterial  
 

Definition at line 172 of file general.cpp.

Referenced by InitGL().

00173 {
00174     float mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
00175     float mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
00176     float mat_specular[] = { 0.9, 0.9, 0.9, 1.0 };
00177     float mat_emission[] = { 0.0, 0.0, 0.0, 1.0 };
00178     float mat_shininess[] = { 80.0 };
00179 
00180     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00181     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00182     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00183     glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
00184     glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
00185 }

void SetGLProjection int    Width,
int    Height
 

Definition at line 155 of file general.cpp.

Referenced by SetGLView().

00156 {
00157     if (Height==0)                                      // Prevent A Divide By Zero If The Window Is Too Small
00158         Height=1;
00159     glViewport(0, 0, Width, Height);                    // Reset The Current Viewport And Perspective Transformation
00160     glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
00161     glLoadIdentity();                                   // Reset The Projection Matrix
00162     gluPerspective(45.0, (float)Width / (float)Height, 1.0, 200.0); // Calculate The Aspect Ratio Of The Window
00163 }

void SetGLProperties  
 

Definition at line 143 of file general.cpp.

Referenced by InitGL().

00144 {
00145     glCullFace(GL_BACK);
00146     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);               // This Will Clear The Background Color To Black
00147     glClearDepth(1.0);                                  // Enables Clearing Of The Depth Buffer
00148     glDepthFunc(GL_LESS);                               // The Type Of Depth Test To Do
00149     glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
00150     glShadeModel(GL_SMOOTH);                            // Enables Smooth Color Shading
00151     glEnable(GL_NORMALIZE);
00152     glEnable(GL_CULL_FACE);
00153 }

void SetGLScene POLYGON  
 

Definition at line 6 of file general.cpp.

References polygon, POLYGON::SetNormal(), POLYGON::Vertex, VERTEX::x, VERTEX::y, and VERTEX::z.

Referenced by InitGL().

00007 {
00008 //Front
00009     polygon[0].Vertex[0].x = -1.0;
00010     polygon[0].Vertex[0].y = -1.0;
00011     polygon[0].Vertex[0].z = 1.0;
00012     polygon[0].Vertex[1].x = 1.0;
00013     polygon[0].Vertex[1].y = -1.0;
00014     polygon[0].Vertex[1].z = 1.0;
00015     polygon[0].Vertex[2].x = 1.0;
00016     polygon[0].Vertex[2].y = 1.0;
00017     polygon[0].Vertex[2].z = 1.0;
00018 
00019     polygon[1].Vertex[0].x = -1.0;
00020     polygon[1].Vertex[0].y = -1.0;
00021     polygon[1].Vertex[0].z = 1.0;
00022     polygon[1].Vertex[1].x = 1.0;
00023     polygon[1].Vertex[1].y = 1.0;
00024     polygon[1].Vertex[1].z = 1.0;
00025     polygon[1].Vertex[2].x = -1.0;
00026     polygon[1].Vertex[2].y = 1.0;
00027     polygon[1].Vertex[2].z = 1.0;
00028 //Back
00029     polygon[2].Vertex[0].x = 1.0;
00030     polygon[2].Vertex[0].y = -1.0;
00031     polygon[2].Vertex[0].z = -1.0;
00032     polygon[2].Vertex[1].x = -1.0;
00033     polygon[2].Vertex[1].y = -1.0;
00034     polygon[2].Vertex[1].z = -1.0;
00035     polygon[2].Vertex[2].x = -1.0;
00036     polygon[2].Vertex[2].y = 1.0;
00037     polygon[2].Vertex[2].z = -1.0;
00038 
00039     polygon[3].Vertex[0].x = 1.0;
00040     polygon[3].Vertex[0].y = -1.0;
00041     polygon[3].Vertex[0].z = -1.0;
00042     polygon[3].Vertex[1].x = -1.0;
00043     polygon[3].Vertex[1].y = 1.0;
00044     polygon[3].Vertex[1].z = -1.0;
00045     polygon[3].Vertex[2].x = 1.0;
00046     polygon[3].Vertex[2].y = 1.0;
00047     polygon[3].Vertex[2].z = -1.0;
00048 //Left
00049     polygon[4].Vertex[0].x = -1.0;
00050     polygon[4].Vertex[0].y = -1.0;
00051     polygon[4].Vertex[0].z = -1.0;
00052     polygon[4].Vertex[1].x = -1.0;
00053     polygon[4].Vertex[1].y = -1.0;
00054     polygon[4].Vertex[1].z = 1.0;
00055     polygon[4].Vertex[2].x = -1.0;
00056     polygon[4].Vertex[2].y = 1.0;
00057     polygon[4].Vertex[2].z = 1.0;
00058 
00059     polygon[5].Vertex[0].x = -1.0;
00060     polygon[5].Vertex[0].y = -1.0;
00061     polygon[5].Vertex[0].z = -1.0;
00062     polygon[5].Vertex[1].x = -1.0;
00063     polygon[5].Vertex[1].y = 1.0;
00064     polygon[5].Vertex[1].z = 1.0;
00065     polygon[5].Vertex[2].x = -1.0;
00066     polygon[5].Vertex[2].y = 1.0;
00067     polygon[5].Vertex[2].z = -1.0;
00068 //Right
00069     polygon[6].Vertex[0].x = 1.0;
00070     polygon[6].Vertex[0].y = -1.0;
00071     polygon[6].Vertex[0].z = 1.0;
00072     polygon[6].Vertex[1].x = 1.0;
00073     polygon[6].Vertex[1].y = -1.0;
00074     polygon[6].Vertex[1].z = -1.0;
00075     polygon[6].Vertex[2].x = 1.0;
00076     polygon[6].Vertex[2].y = 1.0;
00077     polygon[6].Vertex[2].z = -1.0;
00078 
00079     polygon[7].Vertex[0].x = 1.0;
00080     polygon[7].Vertex[0].y = -1.0;
00081     polygon[7].Vertex[0].z = 1.0;
00082     polygon[7].Vertex[1].x = 1.0;
00083     polygon[7].Vertex[1].y = 1.0;
00084     polygon[7].Vertex[1].z = -1.0;
00085     polygon[7].Vertex[2].x = 1.0;
00086     polygon[7].Vertex[2].y = 1.0;
00087     polygon[7].Vertex[2].z = 1.0;
00088 //Top
00089     polygon[8].Vertex[0].x = 1.0;
00090     polygon[8].Vertex[0].y = 1.0;
00091     polygon[8].Vertex[0].z = 1.0;
00092     polygon[8].Vertex[1].x = 1.0;
00093     polygon[8].Vertex[1].y = 1.0;
00094     polygon[8].Vertex[1].z = -1.0;
00095     polygon[8].Vertex[2].x = -1.0;
00096     polygon[8].Vertex[2].y = 1.0;
00097     polygon[8].Vertex[2].z = -1.0;
00098 
00099     polygon[9].Vertex[0].x = 1.0;
00100     polygon[9].Vertex[0].y = 1.0;
00101     polygon[9].Vertex[0].z = 1.0;
00102     polygon[9].Vertex[1].x = -1.0;
00103     polygon[9].Vertex[1].y = 1.0;
00104     polygon[9].Vertex[1].z = -1.0;
00105     polygon[9].Vertex[2].x = -1.0;
00106     polygon[9].Vertex[2].y = 1.0;
00107     polygon[9].Vertex[2].z = 1.0;
00108 //Bottom
00109     polygon[10].Vertex[0].x = -1.0;
00110     polygon[10].Vertex[0].y = -1.0;
00111     polygon[10].Vertex[0].z = 1.0;
00112     polygon[10].Vertex[1].x = -1.0;
00113     polygon[10].Vertex[1].y = -1.0;
00114     polygon[10].Vertex[1].z = -1.0;
00115     polygon[10].Vertex[2].x = 1.0;
00116     polygon[10].Vertex[2].y = -1.0;
00117     polygon[10].Vertex[2].z = -1.0;
00118 
00119     polygon[11].Vertex[0].x = -1.0;
00120     polygon[11].Vertex[0].y = -1.0;
00121     polygon[11].Vertex[0].z = 1.0;
00122     polygon[11].Vertex[1].x = 1.0;
00123     polygon[11].Vertex[1].y = -1.0;
00124     polygon[11].Vertex[1].z = -1.0;
00125     polygon[11].Vertex[2].x = 1.0;
00126     polygon[11].Vertex[2].y = -1.0;
00127     polygon[11].Vertex[2].z = 1.0;
00128 
00129     polygon[0].SetNormal();
00130     polygon[1].SetNormal();
00131     polygon[2].SetNormal();
00132     polygon[3].SetNormal();
00133     polygon[4].SetNormal();
00134     polygon[5].SetNormal();
00135     polygon[6].SetNormal();
00136     polygon[7].SetNormal();
00137     polygon[8].SetNormal();
00138     polygon[9].SetNormal();
00139     polygon[10].SetNormal();
00140     polygon[11].SetNormal();
00141 }

void SetGLTexture TEXTURE  
 

Definition at line 197 of file general.cpp.

References TEXTURE::LoadTGA(), and texture.

Referenced by InitGL().

00198 {
00199     sprintf(texture[0].TexName, "%s", "tile1.tga");
00200     texture[0].LoadTGA();
00201 }

void SetGLView int    Width,
int    Height
 

Definition at line 165 of file general.cpp.

References SetGLProjection().

Referenced by InitGL(), and ReSizeGLScene().

00166 {
00167     SetGLProjection(Width, Height);
00168     glMatrixMode(GL_MODELVIEW);                          // Select The Modelview Matrix
00169     glLoadIdentity();
00170 }


Generated on Fri Dec 23 05:22:20 2005 for Template by doxygen1.2.15