void c3_exercise_1::loadTextures(std::array<GLuint, 2> &textures, GLuint shaderProgram) { glGenTextures(2, textures.data()); int width, height; unsigned char *image; std::string basePath = getBasePath(); std::string kittenTexPath = basePath + "Content\\sample.png"; std::string puppyTexPath = basePath + "Content\\sample2.png"; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); image = SOIL_load_image(kittenTexPath.c_str(), &width, &height, 0, SOIL_LOAD_RGB); printf("%s\n", SOIL_last_result()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); glUniform1i(glGetUniformLocation(shaderProgram, "texKitten"), 0); setTextureParameters(); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); image = SOIL_load_image(puppyTexPath.c_str(), &width, &height, 0, SOIL_LOAD_RGB); printf("%s\n", SOIL_last_result()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); glUniform1i(glGetUniformLocation(shaderProgram, "texPuppy"), 1); setTextureParameters(); }
shmup_game * shmup_game_init() { ENetAddress e; shmup_game *g; g = malloc(sizeof(shmup_game)); glfwGetWindowSize(&g->window_width, &g->window_height); g->render_type = 2; g->quit = 0; g->emitter = v2(g->window_width / 2, g->window_height / 2); g->gravity = v2(0, -250); g->bpool = bpool_new(8000); g->bpool->tex[0] = SOIL_load_OGL_texture("./data/flare.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0); if(g->bpool->tex[0] == 0) fprintf(stderr, "loading error: '%s'\n", SOIL_last_result()); g->bpool->tex[1] = SOIL_load_OGL_texture("./data/arrow.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0); if(g->bpool->tex[1] == 0) fprintf(stderr, "loading error: '%s'\n", SOIL_last_result()); g->bpool->prog = load_shaders("./data/glsl/bullets.vsh", "./data/glsl/bullets.fsh"); if (enet_initialize () != 0) { fprintf (stderr, "An error occurred while initializing ENet.\n"); exit(EXIT_FAILURE); } if (g->network_type == SERVER) { e.host = ENET_HOST_ANY; e.port = 4000; g->host = enet_host_create(&e, 4, 2, 0, 0); } else { g->host = enet_host_create(NULL, 4, 2, 0, 0); } g->player[0].pos = v2(g->window_width/2, g->window_height/2); g->player[0].vel = v2zero; g->player[0].acc = v2zero; // fire(g, 1000, 0); // fire(g, 1000, 1); return g; }
void Level::setLevelSprite(float w, float h) { GLuint tex_2d = SOIL_load_OGL_texture ( "sky.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); levelSprite = Sprite(); levelSprite.initializeSprite(tex_2d, 0, 0, w, h); if( 0 == tex_2d ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } tex_2d = SOIL_load_OGL_texture ( "grass.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); levelSpriteGroundTop = Sprite(); levelSpriteGroundTop.initializeSprite(tex_2d, 0, 0, 68, 9); if( 0 == tex_2d ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } tex_2d = SOIL_load_OGL_texture ( "ground.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); levelSpriteGroundBottom = Sprite(); levelSpriteGroundBottom.initializeSprite(tex_2d, 0, 0, 68, 15); if( 0 == tex_2d ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } }
util(BE2DTextureData, BE2DTextureData*, newWithPathnameType, const char* path, unsigned type) { BE2DTextureData* data = new(BE2DTextureData); char decodepath[PATH_MAX] = {0}; MCString_percentDecode(path, decodepath); size_t psize = strlen(decodepath) * sizeof(char); data->path = strcpy(malloc(psize), decodepath); off_t buffsize; const char* buff = MCFileCopyContentWithPathGetBufferSize(path, &buffsize); data->raw = SOIL_load_image_from_memory((const unsigned char*)buff, (int)buffsize, &data->width, &data->height, &data->channels, SOIL_LOAD_AUTO); MCFileReleaseContent((void*)buff); if (!data->raw) { error_log("BE2DTextureData - load texture failed: %s (%s)\n", SOIL_last_result(), path); release(data); return null; } return data; }
RegTexture::RegTexture(std::string gName, std::string path){ name = gName.c_str(); const char* s = path.c_str(); texture = SOIL_load_OGL_texture ( s, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); if( 0 == texture){ std::cout<<"SOIL: Error loading image (" << name << ", " << path << "): " << SOIL_last_result() << "\n"; texture = SOIL_load_OGL_texture ( "res/defaultTexture.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); } glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); }
HRESULT STDMETHODCALLTYPE GLSExtensionLib::loadTexture (BSTR path, long *texid) { UINT length = ::SysStringLen(path); char *szmbs_path = new char [length + 1]; ::wcstombs (szmbs_path, path, length); szmbs_path [length] = '\0'; GLuint textid = SOIL_load_OGL_texture ( szmbs_path, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); delete szmbs_path; /* check for an error during the load process */ if( 0 == textid ) { printf ( "SOIL loading error: '%s'\n", SOIL_last_result() ); return E_FAIL; } *texid = (long)texid; return NOERROR; }
unsigned int LoadTexture(const std::string& dataPath) { glEnable(GL_TEXTURE_2D); std::string fPath = GetCurrentDir(); // Get current directory, SOIL doesn't seem to work from executable directory fPath.append("img\\" + dataPath); unsigned int tex_2d = SOIL_load_OGL_texture ( fPath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if (tex_2d == 0) { std::string s = "\n\n---- SOIL ERROR ----\nFilename: " + fPath; s.append("\nSOIL Message: "); s.append(SOIL_last_result()); s.append("\n\n"); Log::Write(s.c_str(), ENGINE_LOG); } glBindTexture(GL_TEXTURE_2D, tex_2d); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); return tex_2d; }
void Texture::init(unsigned int flag, unsigned int interalFormat, unsigned int format, const char*imageFile) { int width, height, channels; unsigned char* ht_map = SOIL_load_image(imageFile,&width, &height, &channels, flag); if (ht_map == 0) { printf("load texture %s fail...,and the error is %s", imageFile, SOIL_last_result()); return; } glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, interalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, ht_map); glGenerateMipmap(GL_TEXTURE_2D); // Parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); SOIL_free_image_data(ht_map); }
void _loadTexture2D(Texture2D* texture2D, std::string path) { tex2DMutex.lock(); glfwMakeContextCurrent(Renderer::instance->GetSecondContext()); unsigned int texId = SOIL_load_OGL_texture(path.c_str(), SOIL_LOAD_RGBA, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y); if (0 == texId) { printf("SOIL loading error: '%s'\n", SOIL_last_result()); } unsigned int width, height; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, (GLint*)&width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, (GLint*)&height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); texture2D->SetDimensions(width, height); texture2D->SetTextureId(texId); texture2D->IsReady(true); glfwMakeContextCurrent(0); tex2DMutex.unlock(); }
Texture::Texture(std::string path) { int width = 0, height = 0; //std::cout << "\"" << std::string("textures/" + path).c_str() << "\""; GLuint image = SOIL_load_OGL_texture (std::string("textures/" + path).c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_POWER_OF_TWO); if (image) { glBindTexture(GL_TEXTURE_2D, image); 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_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); m_glTexture = image; m_width = width; m_height = height; m_path = path; } else std::cout << "Unable to load texture \"" << path << "\": " << SOIL_last_result() << std::endl; }
int Tile::loadTexture() { // Load Bitmaps And Convert To Texture this->texture = SOIL_load_OGL_texture ( "/home/angela/Documents/Comp371Project/data/tilefloor.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); if(this->texture == 0) { printf( "SOIL loading error: '%s'\n", SOIL_last_result()); return false; } // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, this->texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); return true; // Return Success }
GLuint TextureUtils::loadTextureCube(const char* PosXFilename, const char* NegXFilename, const char* PosYFilename, const char* NegYFilename, const char* PosZFilename, const char* NegZFilename) { GLuint texture = SOIL_load_OGL_cubemap( ResourcesUtils::getResourcePathforFile(PosXFilename), ResourcesUtils::getResourcePathforFile(NegXFilename), ResourcesUtils::getResourcePathforFile(PosYFilename), ResourcesUtils::getResourcePathforFile(NegYFilename), ResourcesUtils::getResourcePathforFile(PosZFilename), ResourcesUtils::getResourcePathforFile(NegZFilename), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS// | SOIL_FLAG_INVERT_Y ); OGLCall(glBindTexture(GL_TEXTURE_CUBE_MAP, texture)); OGLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); // glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); if (0 == texture) { OErrLog("SOIL loading error: "<< SOIL_last_result() << " \n"); } return texture; }
//todo: append date/time info so I get unique screenshot names //todo: save as png void asdf_multiplat_t::save_screenshot(std::string file_path) const { // if the last 3 characters aren't "bmp", tack on ".bmp" // check the length first, rather than trying to compare with a substring of size - 3 where size might be smaller than 3 if (file_path.size() > 4 && (file_path.compare(file_path.size() - 3, 3, "bmp") != 0)) { file_path += ".bmp"; } auto save_result = SOIL_save_screenshot ( file_path.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, settings.resolution_width, settings.resolution_height ); //soil returns 0 for failure apparently if(save_result == 0) { LOG("ERROR: SOIL failed saving screenshot {%zu,%zu} \"%s\"" , settings.resolution_width, settings.resolution_height, file_path.c_str()); LOG(" SOIL: %s", SOIL_last_result()); } else { LOG("Screenshot saved to: \"%s\"", file_path.c_str()); } }
bool CubemapTexture::Load() { glGenTextures(1, &m_textureObj); glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureObj); for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(types) ; i++) { int width = 0; int height = 0; unsigned char * image = SOIL_load_image(m_fileNames[i].c_str(), &width, &height, 0, SOIL_LOAD_RGB); if (image == 0 ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); SOIL_free_image_data(image); return false; } glTexImage2D(types[i], 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); return true; }
void Terrain::defineTexture() { loc2 = glGetUniformLocation(program, "tex2"); try { glActiveTexture(GL_TEXTURE0); /* load an image file directly as a new OpenGL texture */ texID = SOIL_load_OGL_texture("images/ground.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); /* check for an error during the load process */ if (texID == 0) { printf("TexID SOIL loading error: '%s'\n", SOIL_last_result()); } if (loc >= 0) { std::cout << "sending image to shader" << std::endl; glBindTexture(GL_TEXTURE_2D, texID); // Set our "myTextureSampler" sampler to user Texture Unit 0 glUniform1i(loc, 0); } } catch (std::exception &e) { printf("\nImage file loading failed."); } }
bool assign_texture(GLuint & vao, GLuint tex_id, char * TEXTURE) { //glUseProgram (shaderProgramID); tex_id = SOIL_load_OGL_texture ( TEXTURE, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); if (0 == tex_id) { printf("SOIL f*****g loading error: '%s'\n", SOIL_last_result()); return false; } glGenerateMipmap (GL_TEXTURE_2D); // printf ("mipmaps generated %s\n", TEXTURE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glGenTextures (1, &tex_id); glBindTexture (GL_TEXTURE_2D, tex_id); // return true; // }
unsigned int Entity::loadTexture(const char* a_pFileName, int & a_iWidth, int & a_iHeight, int a_iBPP) { unsigned int uiTextureID = 0; //check if the file exists if (a_pFileName != nullptr) { //read in image data from file unsigned char* pImageData = SOIL_load_image(a_pFileName, &a_iWidth, &a_iHeight, &a_iBPP, SOIL_LOAD_AUTO); //check for a successful read if (pImageData) { //create openGL texture handle uiTextureID = SOIL_create_OGL_texture(pImageData, a_iWidth, a_iHeight, a_iBPP, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); //clear what was read in from file now that it's stored in the handle SOIL_free_image_data(pImageData); } //check for errors if (uiTextureID == 0) { std::cerr << "SOIL loading error: " << SOIL_last_result() << std::endl; } return uiTextureID; } }
Texture2D ResourceManager::loadTextureFromFile(const GLchar *file, GLboolean alpha, GLboolean repeat) { // Create Texture object Texture2D texture; if (alpha) { texture.Internal_Format = GL_RGBA; texture.Image_Format = GL_RGBA; } if (repeat) { texture.Wrap_S = GL_REPEAT; texture.Wrap_T = GL_REPEAT; } // Load image int width, height; unsigned char* image = SOIL_load_image(file, &width, &height, 0, texture.Image_Format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB); if (!image){ std::cout << "ERROR::TEXTURE: " << SOIL_last_result() << std::endl; return texture; } // Now generate texture texture.Generate(width, height, image); // And finally free image data SOIL_free_image_data(image); return texture; }
bool LoadTGA(TextureImage *texture, const char *filename) { int texID = SOIL_load_OGL_texture( filename, SOIL_LOAD_RGBA, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y ); if(0 == texID) { printf( "SOIL loading error: %s '%s'\n", filename, SOIL_last_result() ); return false; } GLint width, height, border; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border); width -= border; height -= border; texture->texID = texID; texture->width=width; texture->height=height; return true; }
int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(800,800); glutCreateWindow("My Adventure Game"); glutFullScreen(); GLuint tex_2d = SOIL_load_OGL_texture ( "download.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); /* check for an error during the load process */ if( 0 == tex_2d ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } // glutDisplayFunc(drawScene); // glutIdleFunc(drawScene); glutMainLoop(); return 0; }
void TexManager::loadTexture(string filename, bool alpha) { unsigned int flags = SOIL_FLAG_MIPMAPS; if (alpha) flags = flags | SOIL_FLAG_MULTIPLY_ALPHA; #ifdef DEVICE char app_dir[256]; PDL_GetCallingPath(app_dir, 256); string full_path(app_dir); full_path.append(filename); #else string full_path = filename; #endif inst->texture[inst->texture_ref] = SOIL_load_OGL_texture ( full_path.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, flags ); if (inst->texture[inst->texture_ref] == 0) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } else { printf("loaded\n"); } inst->texture_ref++; }
GLuint TextureManager::createTexture(const std::string& name) { const std::string &dir = FileHelper::resourcesDirectory(); const char* formats[] = { ".dds", ".bmp", ".png", ".tga", ".jpg" }; GLuint textureId = -1; std::string imgPath = ""; for (const char* format: formats) { imgPath = dir + "resources/" + name + format; textureId = SOIL_load_OGL_texture(imgPath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0); std::cout << "'" << SOIL_last_result() << "'" << std::endl; if (textureId > 0) { break; } } assert(textureId > 0); _textures[name] = textureId; return textureId; }
void Geometry::LoadTexture(string imgPath) /// Laod and link texture { if(gPtr != nullptr) if(gPtr->texture == 0) { if(Tools::Settings::TextureLoadModern) { gPtr->texture = SOIL_load_OGL_texture(imgPath.c_str(),SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y); if (0 == gPtr->texture) cout << "SOIL loading error: " << SOIL_last_result() << endl; } else { int width, height; unsigned char* image; glGenTextures( 1, &gPtr->texture ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap( GL_TEXTURE_2D ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, gPtr->texture ); image = SOIL_load_image( imgPath.c_str() , &width, &height, 0, SOIL_LOAD_RGB ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,GL_UNSIGNED_BYTE, image ); SOIL_free_image_data( image ); } } }
//Takes image path as parameter //Returns id of created texture GLint LoadGLTexture(const char *filename) { GLuint _texture; _texture = SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture ( filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_MIPMAPS ); // check for an error during the load process if(_texture == 0) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } glBindTexture(GL_TEXTURE_2D, _texture); // select our current texture glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // texture should tile glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); return _texture; }
void Sprite::LoadTexture(const char* textureName) { //check file exists if(textureName != nullptr) { //read in image data from file unsigned char* pImageData = SOIL_load_image(textureName, &m_width, &m_height, &m_bpp, SOIL_LOAD_AUTO); //check for successful read if(pImageData) { //create opengl texture handle m_ID = SOIL_create_OGL_texture(pImageData, m_width, m_height, m_bpp, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS| SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); //clear what was read in from file now that it is stored in the handle SOIL_free_image_data(pImageData); } //check for errors if(m_ID == 0) { std::cerr << "SOIL loading error: " << SOIL_last_result() << std::endl; } } }
bool GLS_IMG_Image::_Init (const char *lpsz_image_path) { // set bitmap size m_textid = SOIL_load_OGL_texture ( lpsz_image_path, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | /*SOIL_FLAG_INVERT_Y |*/ SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); /* check for an error during the load process */ if( 0 == m_textid ) { printf ( "SOIL loading error: '%s'\n", SOIL_last_result() ); return false; } // m_bmp_width = (short)bmphdr.biWidth; // m_bmp_height = (short)bmphdr.biHeight; // m_width = m_bmp_width; // m_height = m_bmp_height; // setup vertices array... SetupVertices (); SetupTextureVertices (); m_initialized = true; return true; }
/** load texture data from file using SOIL */ void Texture::loadFromFile ( const std::string& path ) { LOG << log_info << "Loading Texture " << path << log_endl; if ( !SOIL_load_OGL_texture ( path.c_str(), SOIL_LOAD_AUTO, _id, 0 ) ) { LOG << log_alert << "SOIL error: " << SOIL_last_result() << log_endl; } }
bool Texture::Load() { int Index = m_FileName.find("."); if(m_FileName.substr(Index) == ".png") { std::vector<uByte> Image; unsigned error = lodepng::decode(Image, m_Width, m_Height, m_FileName); if(error != 0) { BC_LOG("Error %u : %s\n", error, lodepng_error_text(error)); return false; } size_t u2 = 1; while(u2 < m_Width) u2 *= 2; size_t v2 = 1; while(v2 < m_Height) v2 *= 2; double u3 = (double)m_Width / u2; double v3 = (double)m_Height / v2; std::vector<unsigned char> image2(u2 * v2 * 4); for(size_t y = 0; y < m_Height; y++) for(size_t x = 0; x < m_Width; x++) for(size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = Image[4 * m_Width * y + 4 * x + c]; } GLfloat fLargest; glGetFloatv(GL_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest); glGenTextures(1, &m_Texture); glBindTexture(GL_TEXTURE_2D, m_Texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image2[0]); m_Width = u2; m_Height = v2; } else { m_Texture = SOIL_load_OGL_texture ( m_FileName.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if( 0 == m_Texture ) { BC_LOG("image loading error: '%s'\n", SOIL_last_result()); } glBindTexture(GL_TEXTURE_2D, m_Texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } return true; }
void drawSkybox(std::vector<float> & vp, int & g_point, GLuint & vao) { int length = sizeof(sky_points) / sizeof(float); std::cout << length <<"\n\n"; for(int i = 0; i < length; i++) { vp.push_back (sky_points[i]); } loc1 = glGetAttribLocation(shaderProgramID, "vertex_position"); if(length != vp.size()) std::cout << length << "- length\tvp - " << vp.size() << std::endl; g_point = length; unsigned int vbo = 0; glGenBuffers (1, &vbo); glBindBuffer (GL_ARRAY_BUFFER, vbo); glBufferData (GL_ARRAY_BUFFER, 3 * 36 * sizeof (float), &vp[0], GL_STATIC_DRAW); std::cout << "vao dae: "<< vao <<std::endl; glGenVertexArrays (1, &vao); glBindVertexArray (vao); glEnableVertexAttribArray (loc1); glBindBuffer (GL_ARRAY_BUFFER, vbo); glVertexAttribPointer (loc1, 3, GL_FLOAT, GL_FALSE, 0, NULL); texs[0] = SOIL_load_OGL_cubemap ( RIGHT, LEFT, BOTTOM, TOP, BACK, FRONT, SOIL_LOAD_RGB, SOIL_CREATE_NEW_ID, 0 ); glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (0 == texs[0]) { printf("SOIL loading error: '%s'\n", SOIL_last_result()); } // glBindVertexArray(vao); // glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, texs[0]); }
CAltitude::CAltitude(void) { int width = MAP_SIZE; int height = MAP_SIZE; int channals = 1; g_HeightMap = SOIL_load_image("../images/terrain/heightmap.png",&width, &height, &channals, SOIL_LOAD_L); if (0 == g_HeightMap) { printf("SOIL loading error:'%s'\n", SOIL_last_result()); exit(0); } }