/* function: init() This function is to initailize the texture Source: Tutorial*/ void init() { tex = LoadPPM("copter.ppm", &width, &height, &max1); glClearColor(0, 0, 0, 0); glColor3f(1, 1, 1); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glOrtho(-2, 2, -2, 2, -2, 2); //glLightfv(GL_LIGHT0, GL_POSITION, light_pos); gluPerspective (75,1,2,5000); glEnable(GL_TEXTURE_2D); // glGenTextures(1, &tex); // glBindTexture(GL_TEXTURE_2D, &tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glDisable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, tex); // printf("%d\n", glGetError()); }
// // Load a new image from an image file (PPM, JPEG // and PNG formats are supported). // Returns NULL on failure. // STImage::STImage(const std::string& filename) : mWidth(-1) , mHeight(-1) , mPixels(NULL) { // Determine the right routine based on the file's extension. // The format-specific subroutines are each implemented in // a different file. std::string ext = STGetExtension( filename ); if (ext.compare("PPM") == 0) { LoadPPM(filename); } else if (ext.compare("PNG") == 0) { LoadPNG(filename); } else if (ext.compare("JPG") == 0 || ext.compare("JPEG") == 0) { LoadJPG(filename); } else { fprintf(stderr, "STImage::STImage() - Unknown image file type \"%s\".\n", filename.c_str()); throw new std::runtime_error("Error creating STImage"); } }
int Texture::Load(const char *name){ rgbimg<float> rgb; if(LoadPPM(rgb,name)) return 1; int i; for(i=0;i<rgb.size();i++) rgb[i]/=255; cmpdtxtr.SetTexture(&rgb[0],rgb.szx,rgb.szy,4); return 0; }
int main( int argc, char *argv[] ) { int i; unsigned char* img = 0; int w, h; FILE *output; char basename[200]; if ( argc != 2 && argc != 3 ) { fprintf( stderr, "USAGE: %s input.ppm [output.cpp]\n", argv[0] ); return 1; } LoadPPM( argv[1], img, w, h ); if ( img ) { strcpy( basename, argv[1] ); basename[ strlen(basename)-4 ] = '\0'; if (argc == 3) output = fopen( argv[2], "w" ); else output = stdout; if ( !output ) { fprintf( stderr, "ERROR: File '%s' could not be opened for writing\n", argv[2] ); return 1; } VFlip(img,w,h); /* Opengl bitmaps are specified bottom-to-top */ fprintf( output, "\n\n"); fprintf( output, "int %s[] = {", basename ); fprintf( output, " %d, %d, /* width, height */\n", w, h); fprintf( output, " " ); for( i=0; i<w * h; i++ ) { fprintf( output, "%3d,%3d,%3d, ", img[i*3+0], img[i*3+1], img[i*3+2] ); if ( (i%5) == 4 ) { fprintf( output, "\n " ); } } fprintf( output, "\n};\n" ); fclose( output ); } else { fprintf( stderr, "ERROR: Image '%s' invalid\n", argv[1] ); return 1; } return 0; }