本文整理汇总了C#中SharpGL.OpenGL.BindTexture方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.BindTexture方法的具体用法?C# OpenGL.BindTexture怎么用?C# OpenGL.BindTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.BindTexture方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawQuadsWithTexture
private void DrawQuadsWithTexture(OpenGL gl, int texture, params int[][][] quads)
{
gl.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[texture]);
gl.Begin(OpenGL.GL_QUADS);
foreach (var quad in quads)
{
gl.TexCoord(0.0f, 0.0f); gl.Vertex(quad[0]);
gl.TexCoord(1.0f, 0.0f); gl.Vertex(quad[1]);
gl.TexCoord(1.0f, 1.0f); gl.Vertex(quad[2]);
gl.TexCoord(0.0f, 1.0f); gl.Vertex(quad[3]);
}
gl.End();
}
示例2: InitTexture
public void InitTexture(OpenGL gl)
{
_texture = new SharpGL.SceneGraph.Assets.Texture();
_texture.Create(gl, _image);
Id = _texture.TextureName;
gl.BindTexture(OpenGL.GL_TEXTURE_2D, _texture.TextureName);
}
示例3: BindBitmapToTexture
private void BindBitmapToTexture(OpenGL gl, Bitmap bmp, int textureNumber)
{
gl.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[textureNumber]);
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, bmp.Width, bmp.Height, 0,
OpenGL.GL_BGR,
OpenGL.GL_UNSIGNED_BYTE,
bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb
).Scan0
);
// Specify linear filtering.
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
// the texture wraps over at the edges (repeat)
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
}
示例4: Draw
public void Draw(OpenGL gl)
{
gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureID);
int[] amb_diff = { Colour.A, Colour.B, Colour.G, Colour.A };
gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT_AND_DIFFUSE, amb_diff);
gl.Begin(OpenGL.GL_TRIANGLES);
for (int i = 0; i < 3; i++)
{
Position point = Verts[i].Point;
UV uv = Verts[i].UV;
if (uv != null)
gl.TexCoord(uv.U, uv.V);
gl.Vertex(point.X, point.Y, point.Z);
}
gl.End();
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
}
示例5: AfterRendering
protected void AfterRendering(OpenGL gl, RenderMode renderMode)
{
gl.Disable(OpenGL.GL_POLYGON_SMOOTH);
shaderProgram.Unbind(gl);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
gl.Disable(OpenGL.GL_TEXTURE_2D);
}
示例6: Draw
public override void Draw(ref OpenGL gl)
{
if (!TexturesInitialised)
{
InitializeTexture(ref gl);
}
// Clear the color and depth buffer.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
// Load the identity matrix.
gl.LoadIdentity();
gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.Enable(OpenGL.GL_LIGHTING);
gl.Enable(OpenGL.GL_LIGHT0);
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.Enable(OpenGL.GL_NORMALIZE);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
gl.Color(1.0f, 1.0f, 1.0f, 0.1f);
gl.Begin(OpenGL.GL_QUADS);
gl.FrontFace(OpenGL.GL_FRONT_FACE);
gl.TexCoord(1.0f, 1.0f);
gl.Vertex(gImage1.Width, gImage1.Height, 1.0f);
gl.TexCoord(0.0f, 1.0f);
gl.Vertex(0.0f, gImage1.Height, 1.0f);
gl.TexCoord(0.0f, 0.0f);
gl.Vertex(0.0f, 0.0f, 1.0f);
gl.TexCoord(1.0f, 0.0f);
gl.Vertex(gImage1.Width, 0.0f, 1.0f);
gl.End();
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
gl.Ortho(0.0, (double)gImage1.Width, (double)gImage1.Height, 0.0, -1.0, 1.0);
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.Disable(OpenGL.GL_DEPTH_TEST);
}
示例7: InitializeTexture
private void InitializeTexture(ref OpenGL gl)
{
gImage1 = new Bitmap(@"C:\Users\Lee\Documents\GitHub\SmackBrosClient\SmackBrosClient\files\meleemenu1.jpg");
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, gImage1.Width, gImage1.Height);
gbitmapdata = gImage1.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
gImage1.UnlockBits(gbitmapdata);
gl.GenTextures(1, gtexture);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, gImage1.Width, gImage1.Height, 0, OpenGL.GL_BGR_EXT, OpenGL.GL_UNSIGNED_BYTE, gbitmapdata.Scan0);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
TexturesInitialised = true;
}
示例8: RenderObjects
public void RenderObjects(OpenGL gl, GameObject[] objects)
{
//clears the screen
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
//St matrix mode to PROJECTION so we can move the camera
gl.MatrixMode(OpenGL.GL_PROJECTION);
// Load the identity matrix.
gl.LoadIdentity();
//Move the camera
CamController.SetCam(gl);
//Set matrix mode back to Modelview so we can draw objects
gl.MatrixMode(OpenGL.GL_MODELVIEW);
if (_mode == RenderMode.WireFrame || _mode == RenderMode.Hitboxes)
{
foreach(GameObject obj in objects){
//Draw the object with texture
obj.Draw(gl);
//Unbind texture so we can draw lines
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
if ( _mode == RenderMode.Hitboxes)
{
obj.DrawVelocity(gl);
DrawCircle(gl, obj.GetPosition().x,obj.GetPosition().y, obj.GetPhysSize());
}
else
{
obj.DrawWireFrame(gl);
}
}
}
else
{
foreach ( GameObject obj in objects )
{
//Draw the object with texture
obj.Draw(gl);
}
}
//Unbind texture
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
}
示例9: Create
/// <summary>
/// This function creates the texture from an image file.
/// </summary>
/// <param name="gl">The OpenGL object.</param>
/// <param name="path">The path to the image file.</param>
/// <returns>True if the texture was successfully loaded.</returns>
public virtual bool Create(OpenGL gl, string path)
{
// Create the underlying OpenGL object.
Create(gl);
// Try and load the bitmap. Return false on failure.
Bitmap image = new Bitmap(path);
if (image == null)
return false;
// Get the maximum texture size supported by OpenGL.
int[] textureMaxSize = { 0 };
gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);
// Find the target width and height sizes, which is just the highest
// posible power of two that'll fit into the image.
int targetWidth = textureMaxSize[0];
int targetHeight = textureMaxSize[0];
for (int size = 1; size <= textureMaxSize[0]; size *= 2)
{
if (image.Width < size)
{
targetWidth = size / 2;
break;
}
if (image.Width == size)
targetWidth = size;
}
for (int size = 1; size <= textureMaxSize[0]; size *= 2)
{
if (image.Height < size)
{
targetHeight = size / 2;
break;
}
if (image.Height == size)
targetHeight = size;
}
// If need to scale, do so now.
if (image.Width != targetWidth || image.Height != targetHeight)
{
// Resize the image.
Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);
// Destory the old image, and reset.
image.Dispose();
image = (Bitmap)newImage;
}
// Create an array of pixels the correct size.
pixelData = new byte[image.Width * image.Height * 4];
int index = 0;
// TODO: The loop below is staggeringly slow and needs speeding up.
// Go through the pixels backwards, this seems to be how OpenGL wants the data.
for (int y = image.Height - 1; y >= 0; y--)
{
for (int x = 0; x < image.Width; x++)
{
Color pixel = image.GetPixel(x, y);
pixelData[index++] = pixel.R;
pixelData[index++] = pixel.G;
pixelData[index++] = pixel.B;
pixelData[index++] = pixel.A;
}
}
// Set the width and height.
width = image.Width;
height = image.Height;
// Dispose of the image file.
image.Dispose();
// Bind our texture object (make it the current texture).
gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);
// Set the image data.
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
width, height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE,
pixelData);
// Set linear filtering mode.
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
// We're done!
return true;
}
示例10: Bind
/// <summary>
/// This wraps the OpenGL function that makes the texture 'current'.
/// </summary>
public virtual void Bind(OpenGL gl)
{
// Bind our texture object (make it the current texture).
gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);
}
示例11: InitTexture
public void InitTexture(OpenGL renderer)
{
if (String.IsNullOrEmpty(Texture))
{
return;
}
// We need to load the texture from file.
var textureImage = new Bitmap(Texture);
renderer.Enable(OpenGL.GL_TEXTURE_2D);
// Get one texture id, and stick it into the textures array.
renderer.GenTextures(1, _textures);
// Bind the texture.
renderer.BindTexture(OpenGL.GL_TEXTURE_2D, _textures[0]);
// Tell OpenGL where the texture data is.
renderer.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE,
textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);
// Specify linear filtering.
renderer.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
}
示例12: AfterRendering
protected void AfterRendering(OpenGL gl, RenderMode renderMode)
{
shaderProgram.Unbind(gl);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
gl.Disable(OpenGL.GL_POINT_SPRITE_ARB);
gl.Disable(OpenGL.GL_POINT_SMOOTH);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
}