本文整理汇总了C#中Texture2D.SetWrap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.SetWrap方法的具体用法?C# Texture2D.SetWrap怎么用?C# Texture2D.SetWrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.SetWrap方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: init
public static void init()
{
if (shaderUniversal == null){
shaderUniversal = new ShaderProgram("/Application/shaders/Universal.cgx");
shaderUniversal.SetAttributeBinding(0, "a_Position");
shaderUniversal.SetAttributeBinding(1, "a_VertexColor");
shaderUniversal.SetAttributeBinding(2, "a_TexCoord");
shaderUniversal.SetUniformBinding(0, "u_SceneMatrix");
shaderUniversal.SetUniformBinding(1, "u_ScreenMatrix");
shaderUniversal.SetUniformBinding(2, "u_Alpha");
texture = new Texture2D("/Application/assets/texturepack/rymdkapsel-hd.png", false);
texture.SetFilter(TextureFilterMode.Disabled);
texture.SetWrap(TextureWrapMode.ClampToEdge);
texture.SetMaxAnisotropy(0);
}
if (shaderColored == null){
shaderColored = new ShaderProgram("/Application/shaders/Colored.cgx");
shaderColored.SetAttributeBinding(0, "a_Position");
shaderColored.SetAttributeBinding(1, "a_VertexColor");
shaderColored.SetUniformBinding(0, "u_SceneMatrix");
shaderColored.SetUniformBinding(1, "u_ScreenMatrix");
shaderColored.SetUniformBinding(2, "u_Alpha");
}
}
示例2: PlayerClass
public PlayerClass()
{
position.X = 480.0f;
position.Y = 272.0f;
shipTexture = new Texture2D("/Application/textures/Ship1.png", false);
// shipTexture1 = new Texture2D("/Application/textures/tri.png", false);
// shipTexture = new Texture2D("/Application/spaceship.png", false);
// shipTexture1 = new Texture2D("/Application/spaceship1.png", false);
shipTexture.SetWrap(TextureWrapMode.ClampToEdge);
currentAngle = 0;
directionVector = new Vector2(0,-1);
/// flip=false;
// timer = new Timer();
// timer.Reset();
}
示例3: RendererStartup
public RendererStartup(Sprite sprite)
: base(sprite)
{
float[] verts = new float[8];
float[] uvs = new float[8];
texture = new Texture2D("/Application/assets/bootscreen/Vita.png", false);
texture.SetFilter(TextureFilterMode.Disabled);
texture.SetWrap(TextureWrapMode.ClampToEdge);
texture.SetMaxAnisotropy(0);
int offsetX = (Settings.STAGE_W - texture.Width) / 2;
int offsetY = (Settings.STAGE_H - texture.Height) / 2;
verts[0] = (float) offsetX;
verts[1] = (float) offsetY;
verts[2] = (float) offsetX;
verts[3] = (float) offsetY + texture.Height;
verts[6] = (float) offsetX + texture.Width;
verts[7] = (float) offsetY;
verts[4] = (float) offsetX + texture.Width;
verts[5] = (float) offsetY + texture.Height;
uvs[0] = 0;
uvs[1] = 0;
uvs[2] = 0;
uvs[3] = 1;
uvs[6] = 1;
uvs[7] = 0;
uvs[4] = 1;
uvs[5] = 1;
vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
vertexBuffer.SetVertices(0, verts);
vertexBuffer.SetVertices(1, uvs);
}
示例4: LoadTexture2D
public override Texture2D LoadTexture2D(LoadedAsset asset)
{
Bitmap bmp = null;
if (asset.FilePath.EndsWith(".tga"))
{
bmp = ApexEngine.Assets.Util.TargaImage.LoadTargaImage(asset.Data);
}
else
bmp = new Bitmap(asset.Data);
BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Texture2D tex = new Texture2D(Texture.GenTextureID());
tex.TexturePath = asset.FilePath;
tex.Use();
tex.SetWrap(Convert.ToInt32(TextureWrapMode.Repeat), Convert.ToInt32(TextureWrapMode.Repeat));
tex.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, bmp_data.Width, bmp_data.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);
tex.GenerateMipmap();
tex.Width = bmp.Width;
tex.Height = bmp.Height;
bmp.UnlockBits(bmp_data);
Texture2D.Clear();
return tex;
}
示例5: TestOffscreen
public void TestOffscreen(string name, Texture2D texture)
{
const int Width = 32;
const int Height = 32;
ImageRect old_scissor = Director.Instance.GL.Context.GetScissor();
ImageRect old_viewport = Director.Instance.GL.Context.GetViewport();
FrameBuffer old_frame_buffer = Director.Instance.GL.Context.GetFrameBuffer();
ColorBuffer color_buffer = new ColorBuffer(Width, Height, PixelFormat.Rgba);
FrameBuffer frame_buffer = new FrameBuffer();
frame_buffer.SetColorTarget(color_buffer);
System.Console.WriteLine("SetFrameBuffer(): enter");
Director.Instance.GL.Context.SetFrameBuffer(frame_buffer);
System.Console.WriteLine("SetFrameBuffer(): exit");
ShaderProgram.SetAttributeBinding(0, "iPosition");
ShaderProgram.SetAttributeBinding(1, "iUV");
texture.SetWrap(TextureWrapMode.ClampToEdge);
texture.SetFilter(TextureFilterMode.Linear);
Director.Instance.GL.Context.SetTexture(0, texture);
Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer);
Director.Instance.GL.Context.SetShaderProgram(ShaderProgram);
Director.Instance.GL.Context.SetScissor(0, 0, Width, Height);
Director.Instance.GL.Context.SetViewport(0, 0, Width, Height);
float uv_x0 = 0.0f;
float uv_x1 = 1.0f;
float uv_y0 = 0.0f;
float uv_y1 = 1.0f;
VertexDataArray[0] = new VertexData() { position = new Vector2(-1.0f, -1.0f), uv = new Vector2(uv_x0, uv_y1) };
VertexDataArray[1] = new VertexData() { position = new Vector2(-1.0f, +1.0f), uv = new Vector2(uv_x0, uv_y0) };
VertexDataArray[2] = new VertexData() { position = new Vector2(+1.0f, +1.0f), uv = new Vector2(uv_x1, uv_y0) };
VertexDataArray[3] = new VertexData() { position = new Vector2(+1.0f, -1.0f), uv = new Vector2(uv_x1, uv_y1) };
VertexBuffer.SetIndices(IndexDataArray, 0, 0, 4);
VertexBuffer.SetVertices(VertexDataArray, 0, 0, 4);
Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer);
Director.Instance.GL.Context.DrawArrays(DrawMode.TriangleFan, 0, 4);
int count = Width * Height * 4;
byte[] data = new byte[count];
System.Console.WriteLine("ReadPixels(): enter");
Director.Instance.GL.Context.ReadPixels(data, PixelFormat.Rgba, 0, 0, Width, Height);
System.Console.WriteLine("ReadPixels(): exit");
int nonzero = 0;
int nonclear = 0;
for (int i = 0; i < count; ++i)
{
if (data[i] != 0)
nonzero++;
if (data[i] != 0xfe)
nonclear++;
System.Console.Write("{0} ", data[i]);
if (i % Width == 0)
System.Console.WriteLine("");
}
System.Console.WriteLine("");
System.Console.WriteLine("nonzero: {0}, nonclear: {1}", nonzero, nonclear);
Director.Instance.GL.Context.SetVertexBuffer(0, null);
Director.Instance.GL.Context.SetShaderProgram(null);
Director.Instance.GL.Context.SetFrameBuffer(old_frame_buffer);
Director.Instance.GL.Context.SetScissor(old_scissor);
Director.Instance.GL.Context.SetViewport(old_viewport);
System.Console.WriteLine("SwapBuffers(): enter");
Director.Instance.GL.Context.SwapBuffers();
System.Console.WriteLine("SwapBuffers(): exit");
Thread.Sleep(250);
}
示例6: Add
public void Add(string name, Texture2D texture, int tiles_x, int tiles_y)
{
int tile_width = (int)FMath.Round((float)texture.Width / (float)tiles_x);
int tile_height = (int)FMath.Round((float)texture.Height / (float)tiles_y);
tile_width /= ScaleDivisor;
tile_height /= ScaleDivisor;
tile_width = System.Math.Max(1, tile_width);
tile_height = System.Math.Max(1, tile_height);
ColorBuffer color_buffer = new ColorBuffer(tile_width, tile_height, PixelFormat.Rgba);
FrameBuffer frame_buffer = new FrameBuffer();
frame_buffer.SetColorTarget(color_buffer);
FrameBuffer old_frame_buffer = Director.Instance.GL.Context.GetFrameBuffer();
Director.Instance.GL.Context.SetFrameBuffer(frame_buffer);
ShaderProgram.SetAttributeBinding(0, "iPosition");
ShaderProgram.SetAttributeBinding(1, "iUV");
texture.SetWrap(TextureWrapMode.ClampToEdge);
texture.SetFilter(TextureFilterMode.Linear);
Director.Instance.GL.Context.SetTexture(0, texture);
Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer);
Director.Instance.GL.Context.SetShaderProgram(ShaderProgram);
ImageRect old_scissor = Director.Instance.GL.Context.GetScissor();
ImageRect old_viewport = Director.Instance.GL.Context.GetViewport();
Director.Instance.GL.Context.SetScissor(0, 0, tile_width, tile_height);
Director.Instance.GL.Context.SetViewport(0, 0, tile_width, tile_height);
Entry entry = new Entry();
entry.TilesX = tiles_x;
entry.TilesY = tiles_y;
entry.TileWidth = tile_width;
entry.TileHeight = tile_height;
entry.Data = new List<List<byte>>();
for (int i = 0; i < tiles_y * tiles_x; ++i)
entry.Data.Add(new List<byte>());
Vector2 uv_step = new Vector2(1.0f, 1.0f) / new Vector2(tiles_x, tiles_y);
for (int y = 0; y < tiles_y; y++)
{
for (int x = 0; x < tiles_x; x++)
{
float uv_x0 = uv_step.X * (x + 0);
float uv_x1 = uv_step.X * (x + 1);
float uv_y0 = uv_step.Y * (tiles_y - 1 - y + 0);
float uv_y1 = uv_step.Y * (tiles_y - 1 - y + 1);
VertexDataArray[0] = new VertexData() { position = new Vector2(-1.0f, -1.0f), uv = new Vector2(uv_x0, uv_y1) };
VertexDataArray[1] = new VertexData() { position = new Vector2(-1.0f, +1.0f), uv = new Vector2(uv_x0, uv_y0) };
VertexDataArray[2] = new VertexData() { position = new Vector2(+1.0f, +1.0f), uv = new Vector2(uv_x1, uv_y0) };
VertexDataArray[3] = new VertexData() { position = new Vector2(+1.0f, -1.0f), uv = new Vector2(uv_x1, uv_y1) };
VertexBuffer.SetIndices(IndexDataArray, 0, 0, 4);
VertexBuffer.SetVertices(VertexDataArray, 0, 0, 4);
Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer);
Director.Instance.GL.Context.DrawArrays(DrawMode.TriangleFan, 0, 4);
byte[] data = new byte[tile_width * tile_height * 4];
// DEBUG: fill with visible memory pattern
//for (int i = 0; i< tile_width * tile_height * 4; ++i)
//data[i] = (byte)(i % (tile_width / 4));
Director.Instance.GL.Context.ReadPixels(data, PixelFormat.Rgba, 0, 0, tile_width, tile_height);
List<byte> output = entry.Data[tiles_x * y + x];
for (int i = 0; i < tile_width * tile_height * 4; ++i)
output.Add(data[i]);
}
}
Director.Instance.GL.Context.SetVertexBuffer(0, null);
Director.Instance.GL.Context.SetShaderProgram(null);
Director.Instance.GL.Context.SetFrameBuffer(old_frame_buffer);
Director.Instance.GL.Context.SetScissor(old_scissor);
Director.Instance.GL.Context.SetViewport(old_viewport);
TileData[name] = entry;
}
示例7: validateBuffer
public override void validateBuffer()
{
if (texture != null){
texture.Dispose();
texture = null;
}
if (vertexBuffer != null){
vertexBuffer.Dispose();
vertexBuffer = null;
}
if (textfield.text == null || textfield.text.Length == 0){
dirtyBuffer = false;
return;
}
updateSize();
float[] verts = new float[8];
float[] uvs = new float[8];
int maxWidth = (int) textWidth;
if (textfield.defaultTextFormat.align == "right"){
maxWidth = textfield.width;
}
verts[0] = (float) OFFSET_X;
verts[1] = (float) OFFSET_Y;
verts[2] = (float) OFFSET_X;
verts[3] = (float) OFFSET_Y + textHeight;
verts[6] = (float) OFFSET_X + maxWidth;
verts[7] = (float) OFFSET_Y;
verts[4] = (float) OFFSET_X + maxWidth;
verts[5] = (float) OFFSET_Y + textHeight;
uvs[0] = 0;
uvs[1] = 0;
uvs[2] = 0;
uvs[3] = 1;
uvs[6] = 1;
uvs[7] = 0;
uvs[4] = 1;
uvs[5] = 1;
vertexBuffer = new VertexBuffer(4, VertexFormat.Float2, VertexFormat.Float2);
vertexBuffer.SetVertices(0, verts);
vertexBuffer.SetVertices(1, uvs);
int argb = textfield.defaultTextFormat.color;
var image = new Image( ImageMode.Rgba,
new ImageSize((int)maxWidth, (int)textHeight),
new ImageColor(0, 0, 0, 0));
ImagePosition pos = new ImagePosition(0, 0);
for (int i = 0; i < textLines.Length; i++){
pos.X = 0;
pos.Y = i * font.Metrics.Height;
if (textfield.defaultTextFormat.align == "right"){
pos.X = (int) maxWidth - font.GetTextWidth(textLines[i]);
}
image.DrawText(
textLines[i],
new ImageColor((int)((argb >> 16) & 0xff),
(int)((argb >> 8) & 0xff),
(int)((argb >> 0) & 0xff),
255),
font,
pos
);
}
texture = new Texture2D((int)maxWidth, (int)textHeight, false, PixelFormat.Rgba);
texture.SetPixels(0, image.ToBuffer());
texture.SetFilter(TextureFilterMode.Disabled);
texture.SetWrap(TextureWrapMode.ClampToEdge);
texture.SetMaxAnisotropy(0);
image.Dispose();
dirtyBuffer = false;
//Console.WriteLine("buffer validated: " + renderable.commands.length);
}
示例8: CreateFramebuffers
void CreateFramebuffers()
{
deferred_fb = device.CreateFrameBuffer(device.Width, device.Height);
lighting_fb = device.CreateFrameBuffer(device.Width, device.Height);
shadow_fb = device.CreateFrameBuffer(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
if (device.Extensions.NV_depth_buffer_float)
{
has_stencil = true;
depth_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F_Stencil8_NV, device.Width, device.Height);
shadow_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F_NV, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
shadow_texture_cube = device.CreateTextureCubeMap(InternalFormat.DepthComponent32F_NV, SHADOW_MAP_SIZE);
}
else if (device.Extensions.ARB_depth_buffer_float)
{
// TODO: does not work on ATI
//has_stencil = true;
//depth_texture = device.CreateTexture2D(InternalFormat.Depth24Stencil8, device.Width, device.Height);
has_stencil = false;
depth_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F, device.Width, device.Height);
shadow_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
shadow_texture_cube = device.CreateTextureCubeMap(InternalFormat.DepthComponent32F, SHADOW_MAP_SIZE);
}
else
{
throw new System.ApplicationException("no hardware floating shadow maps available!");
}
depth_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest);
depth_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
depth_texture.SetCompareMode(TextureCompareMode.None);
shadow_texture.SetFilter(TextureMagFilter.Linear, TextureMinFilter.Linear);
shadow_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
shadow_texture.SetCompareMode(TextureCompareMode.CompareRToTexture);
shadow_texture.SetCompareFunc(TextureCompareFunc.LEqual);
shadow_texture_cube.SetFilter(TextureMagFilter.Linear, TextureMinFilter.Linear);
shadow_texture_cube.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
//shadow_texture_cube.SetCompareMode(TextureCompareMode.CompareRToTexture);
//shadow_texture_cube.SetCompareFunc(TextureCompareFunc.LEqual);
//color_texture = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height); // fallback
color_texture = device.CreateTexture2D(InternalFormat.RGBA16F, device.Width, device.Height);
color_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest);
color_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
//normal_texture = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height); // fallback
normal_texture = device.CreateTexture2D(InternalFormat.RGBA16F, device.Width, device.Height);
normal_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest);
normal_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
lighting_output = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height);
//lighting_output = device.CreateTexture2D(InternalFormat.RGB16F, device.Width, device.Height); // for HDR
lighting_output.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest);
lighting_output.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
GL.ReadBuffer(ReadBufferMode.None); // TODO
GL.DrawBuffer(DrawBufferMode.None); // TODO
shadow_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, shadow_texture);
System.Diagnostics.Debug.Assert(shadow_fb.Status == FramebufferStatus.Complete);
deferred_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, depth_texture);
if (has_stencil)
{
deferred_fb.SetTexture2D(FramebufferAttachment.StencilAttachment, 0, depth_texture);
}
deferred_fb.SetTexture2D(FramebufferAttachment.Color0, 0, color_texture);
deferred_fb.SetTexture2D(FramebufferAttachment.Color1, 0, normal_texture);
System.Diagnostics.Debug.Assert(deferred_fb.Status == FramebufferStatus.Complete);
lighting_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, depth_texture);
if (has_stencil)
{
lighting_fb.SetTexture2D(FramebufferAttachment.StencilAttachment, 0, depth_texture);
}
lighting_fb.SetTexture2D(FramebufferAttachment.Color0, 0, lighting_output);
System.Diagnostics.Debug.Assert(lighting_fb.Status == FramebufferStatus.Complete);
}