public static int CreateTexture(string filename) { int res; PBitmap pBitmap = new PBitmap("textures\\" + filename); // Load the bitmap and store the data Gl.glGenTextures(1, out res); // This sets the alignment requirements for the start of each pixel row in memory. Gl.glPixelStorei(Gl.GL_UNPACK_ALIGNMENT, 1); Gl.glBindTexture(Gl.GL_TEXTURE_2D, res); // Build Mipmaps (builds different versions of the picture for distances - looks better) Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, 3, pBitmap.Width, pBitmap.Height, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, pBitmap.data); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR); // The default GL_TEXTURE_WRAP_S and ""_WRAP_T property is GL_REPEAT. // We need to turn this to GL_CLAMP_TO_EDGE, otherwise it creates ugly seems // in our sky box. GL_CLAMP_TO_EDGE does not repeat when bound to an object. // Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE); // Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE); pBitmap = null; return(res); }
public static int CreateTexture(string filename) { int res; PBitmap pBitmap = new PBitmap("textures\\" + filename); Gl.glGenTextures(1, out res); Gl.glPixelStorei(Gl.GL_UNPACK_ALIGNMENT, 1); Gl.glBindTexture(Gl.GL_TEXTURE_2D, res); Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, 3, pBitmap.Width, pBitmap.Height, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, pBitmap.data); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR); pBitmap = null; return(res); }