Waterflow
Visualize water in terrain
src/sdlTexture.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 #include "sdlTexture.h"
00005 
00006 // ===== Constructor =====
00007 
00008 sdlTexture::sdlTexture(std::string tPath, GLuint gTexID)
00009 {
00010     gTextureID = gTexID;
00011     texPath = tPath;
00012     // The ifdef below breaks this class for non-Windows, but is as of now needed in order to run branch on Linux.
00013 #ifdef _WINDOWS
00014     try
00015     {
00016         Surface = IMG_Load(texPath.c_str());
00017     }
00018     catch (const char* msg)
00019     {
00020         printError("Invalid terrain image path!");
00021         printError(msg);
00022     }
00023 #endif
00024     if (Surface != NULL)
00025     {
00026         glGenTextures(1, &gTextureID);
00027         glBindTexture(GL_TEXTURE_2D, gTextureID);
00028 
00029         int Mode = GL_RGB;
00030 
00031         if (Surface->format->BytesPerPixel == 4) {
00032             Mode = GL_RGBA;
00033         }
00034         // Bind image to the texture.
00035         glTexImage2D(GL_TEXTURE_2D, 0, Mode, Surface->w, Surface->h, 0, Mode, GL_UNSIGNED_BYTE, Surface->pixels);
00036     }
00037     else
00038     {
00039         // If any error was encountered when loading the image,
00040         // such as incorrect file or incorrect path, gTextureID
00041         // will be set to -1 to indicate such an error.
00042         gTextureID = -1;
00043     }
00044 }
00045 
00046 // ===== Getter =====
00047 
00048 GLuint sdlTexture::getTexID()
00049 {
00050     return gTextureID;
00051 }
 All Classes Files Functions Variables Enumerations