-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cs
More file actions
31 lines (27 loc) · 1.31 KB
/
texture.cs
File metadata and controls
31 lines (27 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Drawing;
using System.Drawing.Imaging;
using OpenTK.Graphics.OpenGL;
namespace Template_P3 {
public class Texture
{
// data members
public int id;
// constructor
public Texture( string filename )
{
if (String.IsNullOrEmpty( filename )) throw new ArgumentException( filename );
id = GL.GenTexture();
GL.BindTexture( TextureTarget.Texture2D, id );
// We will not upload mipmaps, so disable mipmapping (otherwise the texture will not appear).
// We can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
// mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
GL.TexParameter( TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear );
GL.TexParameter( TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear );
Bitmap bmp = new Bitmap( filename );
BitmapData bmp_data = bmp.LockBits( new Rectangle( 0, 0, bmp.Width, bmp.Height ), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0 );
bmp.UnlockBits( bmp_data );
}
}
} // namespace Template_P3