(*itor->second).refcount++ //update the reference counterīindTexture((*itor->second). if we get here in the code, we already had that texture loaded by some other object GlTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapflag ) GlTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapflag ) .experiment with GL_CLAMP and GL_REPEAT as well
You have to make calls to various OpenGL functions to create an OpenGL texture out of that data (at which point you can free the image data that stbiload gave you), then use a sampler2d in a fragment shader to retrieve the. the texture stops at the edges with GL_CLAMP_TO_EDGE stbimage.h is a great loader, but it doesnt make OpenGL textures, it just simplifies loading the RGBA data into memory. GlTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy) GlGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest_supported_anisotropy)
the following turns on a special, high-quality filtering mode called "ANISOTROPY" GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) //when we are far away GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) //for when we are close GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) //when we are far away GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) //for when we are close setup texture filtering for when we are close/far away glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask) ĬurrentId = newtex->texId swizzle colors - not needed for stb_image GlTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,Ġ, image_format, GL_UNSIGNED_BYTE, bits) set up some vars for OpenGL texturizing GlActiveTexture(texture_unit) //needed for programmable shaders? If(bits = 0) tLog(Level::Severe) texId = gl_texID if somehow one of these failed (they shouldn't), return failure retrieve the image data, currently force to RGBA (4 components)īits = stbi_load(filename.c_str(), &width, &height, &components, 4) image width and height, and #of components (1= gray scale, 4 = rgba) Newtex->unload = true //currently setting all textures to unload when refcount = 0 we didn't find that texture name, so it is a new texture
Itor = textures.find(filename) //lookup this texture in our std::map
Here is the loading code from a TextureManager class I wrote that uses stb: GLuint TextureManager::LoadTexture(std::string filename, bool useMipMaps, GLuint texture_unit, GLuint wrapflag, bool pixelate) You have to make calls to various OpenGL functions to create an OpenGL texture out of that data (at which point you can free the image data that stbi_load gave you), then use a sampler2d in a fragment shader to retrieve the data from the texture. Stb_image.h is a great loader, but it doesn't make OpenGL textures, it just simplifies loading the RGBA data into memory.