Rev 802 |
Rev 1451 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using Tao.OpenGl;
using BauzoidNET.graphics;
namespace BauzoidNET
.graphics.texture
{
public class Texture
: GraphicsObject
{
public enum Filter
{
NEAREST
= Gl
.GL_NEAREST,
LINEAR
= Gl
.GL_LINEAR
}
public enum Wrap
{
MIRRORED_REPEAT
= Gl
.GL_MIRRORED_REPEAT,
CLAMP_TO_EDGE
= Gl
.GL_CLAMP_TO_EDGE,
REPEAT
= Gl
.GL_REPEAT
}
private static int[] TEXTUREID
= new int[1];
private Filter mTextureFilter
= Filter
.LINEAR;
private Wrap mTextureWrap
= Wrap
.CLAMP_TO_EDGE;
private int mWidth
= 0;
private int mHeight
= 0;
private int mTextureID
= 0;
public Texture
(Graphics graphics,
string path
)
: base(graphics
)
{
create
(new Bitmap
(path
));
}
public Texture
(Graphics graphics,
int width,
int height
)
: base(graphics
)
{
create
(new Bitmap
(width, height, PixelFormat
.Format32bppArgb));
}
public void create
(Bitmap image
)
{
image
.RotateFlip(RotateFlipType
.RotateNoneFlipNone);
Rectangle rect
= new Rectangle
(0,
0, image
.Width, image
.Height);
mWidth
= image
.Width;
mHeight
= image
.Height;
BitmapData bitmapdata
= image
.LockBits(rect, ImageLockMode
.ReadOnly, PixelFormat
.Format32bppArgb);
load
(bitmapdata
);
image
.UnlockBits(bitmapdata
);
image
.Dispose();
}
public void load
(BitmapData data
)
{
Gl
.glGenTextures(1, TEXTUREID
);
mTextureID
= TEXTUREID
[0];
Gl
.glEnable(Gl
.GL_TEXTURE_2D);
bind
();
Gl
.glTexImage2D(Gl
.GL_TEXTURE_2D,
0, Gl
.GL_RGBA, mWidth, mHeight,
0, Gl
.GL_BGRA, Gl
.GL_UNSIGNED_BYTE, data
.Scan0);
Gl
.glTexParameteri(Gl
.GL_TEXTURE_2D, Gl
.GL_TEXTURE_MIN_FILTER, Gl
.GL_NEAREST);
Gl
.glTexParameteri(Gl
.GL_TEXTURE_2D, Gl
.GL_TEXTURE_MAG_FILTER, Gl
.GL_NEAREST);
Gl
.glTexParameteri(Gl
.GL_TEXTURE_2D, Gl
.GL_TEXTURE_WRAP_S, Gl
.GL_CLAMP);
Gl
.glTexParameteri(Gl
.GL_TEXTURE_2D, Gl
.GL_TEXTURE_WRAP_T, Gl
.GL_CLAMP);
}
public void dispose
()
{
if (mTextureID
!= 0)
{
TEXTUREID
[0] = mTextureID
;
Gl
.glDeleteTextures(1, TEXTUREID
);
}
}
public void bind
()
{
// TODO: bind using TextureStage/renderstate
Gl
.glBindTexture(Gl
.GL_TEXTURE_2D, mTextureID
);
}
public void setFilter
(Filter minFilter, Filter magFilter
)
{
}
public void setWrap
(Wrap wrapS, Wrap wrapT
)
{
}
public int getTextureHandle
()
{
return mTextureID
;
}
public int getWidth
()
{
return mWidth
;
}
public int getHeight
()
{
return mHeight
;
}
}
}