void drawBoard(double xSize, double ySize, double zSize) { ErrCheck("Before drawBoard"); glPushMatrix(); glTranslated(xSize/2.0*0, ySize/2.0*0, zSize/2.0*0); glScaled(xSize, ySize, zSize); //This rotation gets the gradient in the right direction double temp = ySize; ySize = zSize; zSize = temp; glRotated(90, 1, 0, 0); glRotated(90, 0, 0, 1); double boardColor[] = {255.0/255, 127.0/255, 36.0/255}; // Set specular color to white float white[] = {1,1,1,1}; float black[] = {0,0,0,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black); drawCube(1, 1, 1, boardColor, boardColor, logTexture, logTexture , logTexture, true); glPopMatrix(); ErrCheck("After drawBoard"); }
// Drawing a single tree void drawTree(double heightScale, double widthScale, double xLoc, double yLoc, double zLoc) { ErrCheck("Before drawTree"); glPushMatrix(); //Everything is rotated, so it is weird coordinates glTranslated(xLoc, yLoc, zLoc); //Make sure everything is the right height glScaled(widthScale, widthScale, heightScale); //Draw Cylinder; double trunkWidth= (rand()%40+80)/1000.0; //Gets a tree trunk around .1 double treeHeight = (rand()%30+100)/115.0; //gets a tree height around 1 //glTranslated(0, 0, treeHeight); //Brings the bottom of the tree to zero //Rotate the tree so they don't all look the same glRotated(rand()%360,0,0,1); double treeColor[] = {210.0/255, 105.0/255, 30.0/255}; drawCylinder(trunkWidth, treeHeight, treeColor, treeTexture, logEndTexture, true); double currentAngle = 0; glTranslated(0, 0, treeHeight*1.05); //Moves just above the cylinder double thisLeafAngle; double leafScaleX; double leafScaleY; double leafScaleZ; setupLeaf(); int escape = 0; while(currentAngle < 720) //Draws three things of leaves { glPushMatrix(); if(currentAngle > 360) { glTranslated(0, 0, .05); } thisLeafAngle = (rand()%20+40);//Gets an angle between 20 and 40 leafScaleX = (rand()%10+90)/120.0; //Changes size a little bit leafScaleY = (rand()%10+90)/120.0; //Changes size a little bit leafScaleZ = (rand()%20+95)/100.0; //Changes size a little bit glScaled(leafScaleX, leafScaleY , -leafScaleZ); glRotated(currentAngle, 0, 0, 1); glRotated(-(rand()%6+27), 0, 1, 0); //random angle for the pitch glRotated(-(rand()%5-2.5), 1, 0, 0); //Rotates the leaf a bit drawLeafArray(); glPopMatrix(); currentAngle += thisLeafAngle; escape++; if (escape > 25) { // Make sure we don't get stuck break; } } teardownLeaf(); glPopMatrix(); ErrCheck("In drawTree"); }
/* * Draw a ball * at (x,y,z) * radius (r) */ void ball(double x,double y,double z,double r) { ErrCheck("Before ball"); int th,ph; float yellow[] = {1.0,1.0,0.0,1.0}; float Emission[] = {0.0,0.0,0.01*emission,1.0}; // Save transformation glPushMatrix(); // Offset, scale and rotate glTranslated(x,y,z); glScaled(r,r,r); // White ball glColor3f(1,1,1); glMaterialfv(GL_FRONT,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT,GL_SPECULAR,yellow); glMaterialfv(GL_FRONT,GL_EMISSION,Emission); // Bands of latitude for (ph=-90;ph<90;ph+=inc) { glBegin(GL_QUAD_STRIP); for (th=0;th<=360;th+=2*inc) { Vertex(th,ph,1.0); Vertex(th,ph+inc,1.0); } glEnd(); } // Undo transofrmations glPopMatrix(); ErrCheck("After ball"); }
void drawWoodPlanks(double width, double length, double height, int boardCount, int boardGap) { ErrCheck("Before drawWoodPlanks"); double averageBoardWidth = width/(boardCount*1.0); double currentWidth = 0; for(int ii = 0; ii < boardCount; ii++) { glPushMatrix(); double boardWidth = (rand()%(10*int(boardCount*.7)) + 100-int(boardCount*.7)*5)/100.0*averageBoardWidth; double boardHeight = (rand()%10+95)/100.0*height; if(ii == boardCount - 1) { boardWidth = width - currentWidth; } glTranslated(currentWidth + boardWidth/2.0 , 0, 0); glRotated(90,0,1,0); if(rand()%2) { glTranslated(length,0,0); glRotated(180,0,1,0); } drawBoard(length,boardHeight,boardWidth*(1-boardGap)); currentWidth += boardWidth; glPopMatrix(); } ErrCheck("After drawWoodPlanks"); }
void drawWall(double height, double width, int logCount) { ErrCheck("Before drawWall"); glPushMatrix(); double averageLogHeight = height/(logCount*1.0); double currentHeight = 0; glRotated(90,0,0,1); for(int ii = 0; ii < logCount; ii++) { glPushMatrix(); double cylinderSize = (rand()%(10*int(logCount*.8))+100-int(logCount*.8)*5)/100.0*averageLogHeight; if(ii == logCount - 1) { cylinderSize = height - currentHeight; } glTranslated(cylinderSize/2+currentHeight, 0, 0); double logColor[] = {255.0/255, 127.0/255, 36.0/255}; // Flip the log half of the time to make it look better if(rand()%2) { glTranslated(0,-width,0); glRotated(180,0,0,1); } glRotated(rand()%360,0,1,0); cylinder::drawCylinder(cylinderSize/2, width, 900, logColor, logTexture, logEndTexture, true); currentHeight += cylinderSize; glPopMatrix(); } glPopMatrix(); ErrCheck("After drawWall"); }
/* * Draw a drawRock * at (x,y,z) * radius (r) */ void drawRock(double x,double y,double z,double rx, double ry, double rz, int roughness) { ErrCheck("before drawRock"); int th,ph; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,rockTexture); // Save transformation glPushMatrix(); // Offset, scale and rotate glTranslated(x, z+rz, y); // I like z going up glScaled(rx,rz,ry); // Set specular color to white float white[] = {1,1,1,1}; float black[] = {0,0,0,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black); double previousRadius[361]; // = {[0 ... 360] = 1.0}; for(int ii = 0; ii <= 360; ii++) { previousRadius[ii] = 1.0; } glColor3f(180/255.0 ,180/255.0 ,160/255.0); // Bands of latitude for (ph=-90;ph<90;ph+=roughness) { glBegin(GL_QUAD_STRIP); double radius0 = (rand()%30+85)/100.0; for (th=0;th<=360;th+=2*roughness) { double thisRadius = (rand()%30+85)/100.0; if(ph+roughness == 90) { thisRadius = 1.0; } if(th == 0 || th == 360) { thisRadius = radius0; } glTexCoord2f(((ph+90)%180)/180.0,(th%360)/360.0); Vertex(th,ph,previousRadius[th]); glTexCoord2f(((ph+90+roughness)%180)/180.0,(th%360)/360.0); Vertex(th,ph+roughness,thisRadius); previousRadius[th] = thisRadius; } glEnd(); } // Undo transofrmations glPopMatrix(); glDisable(GL_TEXTURE_2D); ErrCheck("After drawRock"); }
void drawSquare( double Corner00Color[3] , double Corner01Color[3] , double Corner11Color[3] , double Corner10Color[3] , unsigned int texture , bool enableTextures) { ErrCheck("Before drawSquare"); glPushMatrix(); glBindTexture(GL_TEXTURE_2D,texture); if(enableTextures) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texture); } glBegin(GL_QUADS); glNormal3f(0,0,1); glColor3dv(Corner00Color); if(enableTextures) { glTexCoord2f(0,0); } glVertex2f(0,0); glNormal3f(0,0,1); glColor3dv(Corner01Color); if(enableTextures) { glTexCoord2f(0,1); } glVertex2f(0,1); glNormal3f(0,0,1); glColor3dv(Corner11Color); if(enableTextures) { glTexCoord2f(1,1); } glVertex2f(1,1); glNormal3f(0,0,1); glColor3dv(Corner10Color); if(enableTextures) { glTexCoord2f(1,0); } glVertex2f(1,0); glEnd(); if(enableTextures) { glDisable(GL_TEXTURE_2D); } glPopMatrix(); ErrCheck("After drawSquare"); }
// Draws a leaf, it is really long and messy void drawLeaf( ) { ErrCheck("Before drawLeaf"); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,leafTexture); const int vertexCount = 21; // Set specular color to white float white[] = {1,1,1,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white); float Emission[] = {0.003,.005*emission,0.0005*emission,1}; glMaterialfv(GL_FRONT,GL_EMISSION,Emission); glRotated(90, 1, 0, 0); glScaled(1,1,1); double leafVertex[vertexCount*3] = { 0.0, 0.0, 0.0, // 0 .1, .15, 0.0, // 1 .2, .2, 0.0, // 2 .3, .24, -.01, //3 .4, .28, -.02, //4 .5, .3, -.03, //5 .6, .25, -.04, //6 .7, .23, -.05, //7 .8, .2, -.15, //8 .9, .11, -.18, //9 1.0, 0.0, -.2, //10 .9, -.1, -.15, //11 .8, -.2, -.10, //12 .7, -.23, -.05, //13 .6, -.25, -.03, //14 .5, -.3, -.02, //15 .4, -.28, -.01, //16 .3, -.24, 0.0, //17 .2, -.2, 0.0, //18 .1, -.15, 0.0, //19 0, 0, 0 //20 }; glBegin(GL_POLYGON); glNormal3f(.2, 0, -.98); glColor3f(.7, 1, .2); for(int ii = 0; ii < vertexCount - 1; ii++) { glTexCoord2f(leafVertex[ii*3+1]/.3+.5,1-leafVertex[ii*3]); glVertex3dv(&leafVertex[ii*3]); } glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); ErrCheck("After drawLeaf"); }
void drawFloor(coordinates houseSize, double logOverlap) { ErrCheck("Before drawFloor"); glPushMatrix(); glTranslated(logOverlap*2,.005*houseSize.y, -logOverlap*2); drawWoodPlanks(houseSize.x*(1-logOverlap), houseSize.z*(1-logOverlap), .1, 20, .95); glPopMatrix(); ErrCheck("After drawFloor"); }
void drawHouse() { ErrCheck("Before drawHouse"); glPushMatrix(); coordinates house; house.x = 5.0; house.y = 3.0; house.z = 4.0; glTranslated(-house.x/2.0, 0, house.z/2.0); int logNum = 8; double logOverlap= .1; // Wall Zero glPushMatrix(); glTranslated(0, 0, -house.z*logOverlap); glRotated(0, 0, 0, 0); drawWallWithOpening(house.y, house.x, logNum, house.x*.4, 0, house.x*.6, house.y*.75); //drawWall(house.y, house.x, logNum); glPopMatrix(); // Wall 1 glPushMatrix(); glTranslated(house.x*logOverlap, 0, 0); glRotated(90, 0, 1, 0); drawWallWithOpening(house.y, house.z, logNum, house.z*.4, house.y*.4, house.z*.75, house.y*.75); glPopMatrix(); // Wall 2 glPushMatrix(); glTranslated(0, 0, house.z*(logOverlap - 1)); glRotated(00, 0, 0, 0); drawWall(house.y, house.x, logNum); glPopMatrix(); // Wall 3 glPushMatrix(); glTranslated(house.x*(1 - logOverlap), 0, 0); glRotated(90, 0, 1, 0); drawWallWithOpening(house.y, house.z, logNum, house.z*.4, house.y*.4, house.z*.75, house.y*.75); //drawWall(house.y, house.z, logNum); glPopMatrix(); drawRoof(2.0, house); drawFloor(house, logOverlap); glPopMatrix(); ErrCheck("After drawFloor"); }
void drawGround(double xSize, double ySize, double zSize) { ErrCheck("Before drawGround"); // Set specular color to white float white[] = {1,1,1,1}; float black[] = {0,0,0,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black); drawCube(xSize, ySize, zSize , grassColor, dirtColor, grassTexture , dirtTexture, grassCrossSectionTexture, true); ErrCheck("After drawSquare"); }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("OpenGL 4"); #ifdef USEGLEW // Initialize GLEW if (glewInit()!=GLEW_OK) Fatal("Error initializing GLEW\n"); if (!GLEW_VERSION_4_3) Fatal("OpenGL 4.3 not supported\n"); #endif // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); // Load crate crate = LoadTexBMP("pi.bmp"); // Create Shader Programs shader = CreateShaderProg("gl430.vert","gl430.frag"); // Initialize cube InitCube(); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
int main(int argc, char* argv[]){ //Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("Textures and Lighting"); // Set callbacks init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); //process mouse callbacks glutMouseFunc(picker); //glutMotionFunc(processMouseActiveMotion); ///glutPassiveMotionFunc(processMousePassiveMotion); // glutEntryFunc(processMouseEntry); // Load textures texture[0] = LoadTexBMP("crate.bmp"); texture[1] = LoadTexBMP("StoneWall.bmp"); texture[2] = LoadTexBMP("grass.bmp"); texture[3] = LoadTexBMP("bark.bmp"); texture[4] = LoadTexBMP("roof.bmp"); texture[5] = LoadTexBMP("brick.bmp"); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
int main(int argc,char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(1000,1000); glutCreateWindow("Textures Assignment (Seth Perry)"); //sets the function that handles window reshaping to reshape. glutReshapeFunc(reshape); //sets the display function to display glutDisplayFunc(display); //set the idle function to idle glutIdleFunc(idle); //sets the special key function to special glutSpecialFunc(special); //sets the keyboard function to key glutKeyboardFunc(key); getHourOfDay(); loadTextures(); determineTreeLocations(); generateDisplayLists(); pew=LoadOBJ("pew.obj"); //check for errors ErrCheck("init"); //gives control to GLUT so user input can be managed. glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { int k; // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA); glutCreateWindow("Solar System"); glutFullScreen(); // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); // Load textures for (k=0;k<N;k++) { planet[k].balltex = LoadTexBMP(planet[k].ball); planet[k].ringtex = planet[k].ring ? LoadTexBMP(planet[k].ring) : 0; } SetMode(3); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
/* * Main */ int main(int argc, char *argv[]) { // Initialize GLUT and process user parameters glutInit(&argc, argv); // Request double buffered, true color window glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Request 500 x 500 pixel window glutInitWindowSize(1000, 1000); // Create the window glutCreateWindow("Sahle Alturaigi: Lighting"); // Tell GLUT to call "display" when the scene should be drawn glutDisplayFunc(display); // Tell GLUT to call "reshape" when the window is resized glutReshapeFunc(reshape); // Tell GLUT to call "special_key" when an arrow key is pressed glutSpecialFunc(special_key); // Tell GLUT to call "key" when a key is pressed glutKeyboardFunc(key); // Tell GLUT to call idle when the program is not being interacted. glutIdleFunc(idle); // Checks for any thrown errors ErrCheck("init"); // Pass control to GLUT so it can interact with the user glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(700,700); glutCreateWindow("Robert Werthman Assignment 6"); // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); // Tell GLUT to call "idle" when there is nothing else to do glutIdleFunc(idle); // Load the textures for the helicopter littlebird[0] = LoadTexBMP("littlebirdenginetank.bmp"); littlebird[1] = LoadTexBMP("littlebirdenginetank.bmp"); littlebird[2] = LoadTexBMP("littlebirdcockpit.bmp"); littlebird[3] = LoadTexBMP("littlebirdengine.bmp"); littlebird[4] = LoadTexBMP("littlebirdskidmount.bmp"); littlebird[5] = LoadTexBMP("littlebirdskid.bmp"); littlebird[6] = LoadTexBMP("littlebirdrotor.bmp"); littlebird[7] = LoadTexBMP("littlebirdgear.bmp"); // Check if any errors have occurred ErrCheck("init"); // Pass control to GLUT so it can interact with the user glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); if (argc!=2 && argc!=3 && argc!=6) Fatal("Usage: %s <obj> [scale [R G B]]\n",argv[0]); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("Model Loader"); // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); // Set scale if (argc>=3) scale = strtod(argv[2],NULL); if (scale<=0) scale = 1; // Set color if (argc>=6) RGBA[0] = strtod(argv[3],NULL); if (argc>=6) RGBA[1] = strtod(argv[4],NULL); if (argc>=6) RGBA[2] = strtod(argv[5],NULL); // Load object obj = LoadOBJ(argv[1]); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("NDC RGB Shader"); #ifdef USEGLEW // Initialize GLEW if (glewInit()!=GLEW_OK) Fatal("Error initializing GLEW\n"); if (!GLEW_VERSION_2_0) Fatal("OpenGL 2.0 not supported\n"); #endif // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); // Load object model = LoadOBJ("tyra.obj"); // Create Shader Programs shader[1] = CreateShaderProg("ndcrgb.vert","ndcrgb.frag"); shader[2] = CreateShaderProg("ndcrgb.vert",NULL); shader[3] = CreateShaderProg(NULL,"ndcrgb2.frag"); // Initialize location x = y = z = 0; // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("Nbody Simulator"); #ifdef USEGLEW // Initialize GLEW if (glewInit()!=GLEW_OK) Fatal("Error initializing GLEW\n"); if (!GLEW_VERSION_2_0) Fatal("OpenGL 2.0 not supported\n"); #endif // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); // Initialize stars InitLoc(); // Initialize OpenCL InitCL(); // Shader program shader = CreateShaderProgGeom(); ErrCheck("init"); // Star texture LoadTexBMP("star.bmp"); // Pass control to GLUT so it can interact with the user glutMainLoop(); return 0; }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering & stencil at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL); glutInitWindowSize(600,600); glutCreateWindow("Shadow Volumes"); // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(move?idle:NULL); // Check stencil depth glGetIntegerv(GL_STENCIL_BITS,&depth); if (depth<=0) Fatal("No stencil buffer\n"); // Load textures tex2d[0] = LoadTexBMP("water.bmp"); tex2d[1] = LoadTexBMP("crate.bmp"); tex2d[2] = LoadTexBMP("pi.bmp"); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
/* * Display the scene */ void display() { // Clear the image glClear(GL_COLOR_BUFFER_BIT); // Reset previous transforms glLoadIdentity(); // Set view angle glRotated(ph,1,0,0); glRotated(th,0,1,0); // Draw 1 pixel points - Randomly generated colors glColor3ub( rand()%255, rand()%255, rand()%255 ); glPointSize(1); glBegin(GL_LINE_STRIP); int i; /* Coordinates */ double x = 1; double y = 1; double z = 1; /* Time step */ double dt = 0.001; for (i=0;i<50000;i++) { double dx = s*(y-x); double dy = x*(r-z)-y; double dz = x*y - b*z; x += dt*dx; y += dt*dy; z += dt*dz; glVertex4f(x*0.03,y*0.03,z*0.03,w); } glEnd(); // Draw axes in white glColor3f(1,1,1); glBegin(GL_LINES); glVertex3d(0,0,0); glVertex3d(1,0,0); glVertex3d(0,0,0); glVertex3d(0,1,0); glVertex3d(0,0,0); glVertex3d(0,0,1); glEnd(); // Label axes glRasterPos3d(1,0,0); Print("X"); glRasterPos3d(0,1,0); Print("Y"); glRasterPos3d(0,0,1); Print("Z"); // Display parameters glWindowPos2i(5,5); Print("View Angle=%d,%d; s = %f; b = %f; r = %f",th,ph,s,b,r); // Sanity check ErrCheck("display"); // Flush and swap glFlush(); glutSwapBuffers(); }
void SoundManager::DeleteSound() { //stop all channels for (int index = 0; index < MAX_SOUND; ++index) { pChannel[index]->stop(); } //release all sounds for(int index = 0; index < MAX_SOUND; ++index) { pSound[index]->release(); pSound[index] = NULL; } //and then release/close system ErrCheck(pSystem->close()); ErrCheck(pSystem->release()); }
// Drawing a single tree void drawTree(double heightScale, double widthScale, double xLoc, double yLoc, double zLoc) { ErrCheck("Before drawTree"); glPushMatrix(); //Everything is rotated, so it is weird coordinates glTranslated(xLoc, zLoc, yLoc); //Make sure everything is the right height glScaled(widthScale, heightScale, widthScale); //Draw Cylinder; double treeWidth = (rand()%40+80)/300.0; //Gets a tree trunk around .4 double treeHeight = (rand()%30+100)/20.0; //gets a tree height around 4 glTranslated(0,treeHeight, 0); //Brings the bottom of the tree to zero //Rotate the tree so they don't all look the same glRotated(rand()%360,0,1,0); double treeColor[] = {210.0/255, 105.0/255, 30.0/255}; cylinder::drawCylinder(treeWidth, treeHeight, 60, treeColor, treeTexture, logEndTexture, true); double currentAngle = 0; glTranslated(0,treeHeight*.05, 0); //Moves just above the cylinder while(currentAngle < 720) //Draws three things of leaves { glPushMatrix(); if(currentAngle > 360) { glTranslated(0, -.05, 0); } double thisLeafAngle = rand()%20+40;//Gets an angle between 20 and 40 double leafScaleX = (rand()%10+90)/25; //Changes size a little bit double leafScaleY = (rand()%10+90)/25; //Changes size a little bit double leafScaleZ = (rand()%10+90)/25; //Changes size a little bit glScaled(leafScaleX, leafScaleY * thisLeafAngle/30.0, leafScaleZ); glRotated(currentAngle, 0, 1, 0); glRotated(-(rand()%6+27), 0, 0, 1); //random angle for the pitch glRotated(-(rand()%5-2.5), 1, 0, 0); //Rotates the leaf a bit drawLeaf(); glPopMatrix(); currentAngle += thisLeafAngle; } glPopMatrix(); ErrCheck("After drawTree"); }
void drawGround(double xSize, double ySize, double zSize) { ErrCheck("before drawGround"); // Set specular color to white //float white[] = {1,1,1,1}; float black[] = {0,0,0,1}; glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,black); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black); //glTranslated(0, 0,-zSize/2.0); //Moves ground below orgin ErrCheck("before drawCube in DrawGround"); drawCube(0, 0, -zSize/2.0, xSize, ySize, zSize , grassColor, dirtColor, grassTexture , dirtTexture, grassCrossSectionTexture, true); ErrCheck("in drawGround"); }
// Setup winsock void SetupWinsock() { int err; WSADATA wsadata; err = WSAStartup( MAKEWORD( 2, 2 ), &wsadata ); ErrCheck( err, 108 ); sTCP = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); SOCKADDR_IN saBind; saBind.sin_family = AF_INET; saBind.sin_port = htons( PORT ); saBind.sin_addr.s_addr = INADDR_ANY; err = bind( sTCP, (sockaddr *) &saBind, sizeof( saBind ) ); ErrCheck( err, 118 ); unsigned long u1 = 1; err = ioctlsocket( sTCP, FIONBIO, &u1 ); ErrCheck( err, 122 ); }
void drawRoof(int roofHeight, coordinates houseSize) { glPushMatrix(); glTranslated(0,houseSize.y+roofHeight, -houseSize.z/2.0); drawHalfRoof(roofHeight, houseSize, 15); glPopMatrix(); glPushMatrix(); glTranslated(houseSize.x,houseSize.y+roofHeight, -houseSize.z/2.0); glRotated(180,0,1,0); drawHalfRoof(roofHeight, houseSize, 13); glPopMatrix(); ErrCheck("After drawHalfRoof"); }
/* * Start up GLUT and tell it what to do */ int main(int argc,char* argv[]) { int n; // Initialize GLUT glutInit(&argc,argv); // Request double buffered, true color window with Z buffering at 600x600 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(600,600); glutCreateWindow("Stored Textures"); #ifdef USEGLEW // Initialize GLEW if (glewInit()!=GLEW_OK) Fatal("Error initializing GLEW\n"); if (!GLEW_VERSION_2_0) Fatal("OpenGL 2.0 not supported\n"); #endif // Set callbacks glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(special); glutKeyboardFunc(key); glutIdleFunc(idle); // Make sure enough texture units are available glGetIntegerv(GL_MAX_TEXTURE_UNITS,&n); if (n<4) Fatal("Insufficient texture Units %d\n",n); // Allocate quadric for ball ball = gluNewQuadric(); // Load daytime textures day[0] = LoadTexBMP("day01.bmp"); day[1] = LoadTexBMP("day02.bmp"); day[2] = LoadTexBMP("day03.bmp"); day[3] = LoadTexBMP("day04.bmp"); day[4] = LoadTexBMP("day05.bmp"); day[5] = LoadTexBMP("day06.bmp"); day[6] = LoadTexBMP("day07.bmp"); day[7] = LoadTexBMP("day08.bmp"); day[8] = LoadTexBMP("day09.bmp"); day[9] = LoadTexBMP("day10.bmp"); day[10] = LoadTexBMP("day11.bmp"); day[11] = LoadTexBMP("day12.bmp"); // Load nightime texture glActiveTexture(GL_TEXTURE2); night = LoadTexBMP("night.bmp"); // Load cloud & gloss texture glActiveTexture(GL_TEXTURE3); cloudgloss = LoadTexBMP("cloudgloss.bmp"); // Create shader programs shader = CreateShaderProg("earth.vert","earth.frag"); // Pass control to GLUT so it can interact with the user ErrCheck("init"); glutMainLoop(); return 0; }
void drawWallWithOpening(double height , double width , int logCount , double startX , double startY , double endX , double endY) { ErrCheck("Before drawWallWithOpening"); double openingHeight = endY - startY; int openLogs = int((openingHeight/height)*logCount+.5); int beforeOpeningLogs = int((startY/height)*logCount+.5); int afterOpeningLogs = logCount - openLogs - beforeOpeningLogs; //printf("before logs %d\n", beforeOpeningLogs); //Wall below window drawWall(startY, width, beforeOpeningLogs); // Left of Opening glPushMatrix(); glTranslated(0,startY,0); drawWall(openingHeight, startX, openLogs); glPopMatrix(); // Right of Opening glPushMatrix(); glTranslated(endX,startY,0); drawWall(openingHeight, width - endX, openLogs); glPopMatrix(); // Above Opening glPushMatrix(); glTranslated(0,endY,0); drawWall(height - endY, width, afterOpeningLogs); glPopMatrix(); ErrCheck("After drawWallWithOpening"); }
void Print(const char* format , ...) { char buf[LEN]; char* ch=buf; va_list args; // Turn the parameters into a character string va_start(args,format); vsnprintf(buf,LEN,format,args); va_end(args); // Display the characters one at a time at the current raster position while (*ch) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*ch++); ErrCheck("Print"); }