Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Mesh::LoadTexture(const char* filename)
- {
- //Pointless use of bmp file type
- // load bmp through SDL
- //SDL_Surface* image = SDL_LoadBMP(filename);
- //Replacement for bitmap fileloading using IMG_Load
- //this supports the use of many different image file types
- SDL_Surface* image = IMG_Load(filename);
- // check if the image has loaded if not throw a hissy fit
- if (!image)
- {
- system("cd");
- std::cout << "FAILED : Cannot open file:" << filename << std::endl;
- return;
- }
- //if successfull tell everyone about it
- std::cout << "SUCCESS : Texture loaded" << std::endl;
- // generate texture from inported data using glew
- glGenTextures(1, &diffuseTexID);
- glBindTexture(GL_TEXTURE_2D, diffuseTexID);
- //try catch to see if anything fails - stuff likes to fail
- try {
- //set up image data and pass into glTexImage2D which converts our image to a texture
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->w, image->h, 0, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
- //free the poor loaded image
- SDL_FreeSurface(image);
- //Applyparameters to texturing
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- }
- catch(...)
- {
- std::cout << "texture could not be loaded, check filename and filetype\n";
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement