/// <summary> /// Loads a texture from a file, binds it to the current GL context, specifies some GL parameters, /// generates a mipmap, and adds the generated texture's id to the loadedTextures dictionary. Does not output the width and height of the image. /// </summary> private void InitTexture(string folderPath, string fileName, string fileType) { int width, height; var data = LoadTexture(folderPath, fileName, fileType, out width, out height); int texture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.Float, IntPtr.Zero); GL.TextureSubImage2D(texture, 0, 0, 0, width, height, PixelFormat.Bgra, PixelType.Float, data); GL.Enable(EnableCap.Texture2D); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); // defines sampling behavior when scaling image down GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); // defines sampling behavior when scaling image up GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); // defines border behavior in the x directions GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); // defines border behavior in the y directions GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); Texture tex = new Texture(texture, width, height, 1); tex.AddSubTextureLocation(new SubTextureLocation(new Vector2(0f, 0f), new Vector2(1f, 1f))); loadedTextures.Add(fileName, _loadedTextureCount); _loadedTextures[_loadedTextureCount] = tex; _loadedTextureCount++; }