// ************************************************************ void RTTexture::LoadFile(char *filename) { if(pixels != NULL) { delete pixels; pixels = NULL; } pixels = readPPMfile(filename, &iWidth, &iHeight); }
void initTextures(void) { /* read in image for texture */ grid = readPPMfile("grid.ppm"); /* create a texture object */ glGenTextures(1,&gridTex); /* make it the current texture */ glBindTexture(GL_TEXTURE_2D,gridTex); /* make it wrap around */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT); /* make it filter nicely */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* and put the image data into the texure object */ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,128,128,0, GL_RGB,GL_UNSIGNED_BYTE,grid); }
/* * Draws the plant. * * ADD YOUR CODE and modify the function to take an L-system depth and * any other necessary arguments. */ void drawTree(int depth) { srand(randomSeed); glDepthMask(GL_FALSE); // disable z buffer before drawing ppm file int w; int h; GLubyte *pixels = readPPMfile("mountains.ppm", &w, &h); glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels); glDepthMask(GL_TRUE); // reenable z buffer scaleFactor = depth; pushMatrix(); initialize(); centerBranch(depth); popMatrix(); } // drawPlant
void display() { glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw Background int pic_w, pic_h; GLubyte* img = readPPMfile ("apple.ppm", &pic_w, &pic_h); glRasterPos3f (-40.0f, -10.0f, -40.0f); glDrawPixels (pic_w, pic_h, GL_RGB, GL_UNSIGNED_BYTE, img); /* See drawplant.c for the definition of this routine */ drawPlant(_iterations, 10.0f); glFlush(); /* Flush all executed OpenGL ops finish */ /* * Since we are using double buffers, we need to call the swap * function every time we are done drawing. */ glutSwapBuffers(); }