本文整理汇总了C#中Texture.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.Create方法的具体用法?C# Texture.Create怎么用?C# Texture.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: openGLControl1_OpenGLInitialized
/// <summary>
/// Handles the OpenGLInitialized event of the openGLControl1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
{
// Get OpenGL.
var gl = openGLControl1.OpenGL;
// Load identity modelview.
gl.MatrixMode(MatrixMode.Modelview);
gl.LoadIdentity();
// Shading states
gl.ShadeModel(ShadeModel.Smooth);
gl.ClearColor(1f, 1f, 1f, 0.0f);
gl.Color(1.0f, 1.0f, 1.0f, 1.0f);
gl.Hint(HintTarget.PerspectiveCorrection, HintMode.Nicest);
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
// Depth states
gl.ClearDepth(1.0f);
gl.DepthFunc(DepthFunction.LessThanOrEqual);
gl.Enable(OpenGL.GL_DEPTH_TEST);
// Enable cull face.
gl.Enable(OpenGL.GL_CULL_FACE);
// Load decal texture
decalImage = new Texture();
decalImage.Create(gl, "decal.bmp");
decalImage.Bind(gl);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
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);
// Load normal map
normalMap = new Texture();
normalMap.Create(gl, "Normal map.bmp");
normalMap.Bind(gl);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
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);
// Create normalisation cube map
uint[] textures = new uint[1];
gl.GenTextures(1, textures);
normalisationCubeMap = textures[0];
// Bind and generate the normalisation cube map.
gl.BindTexture(OpenGL.GL_TEXTURE_CUBE_MAP, normalisationCubeMap);
GenerateNormalisationCubeMap();
// Set the cube map parameters.
// Extensions: Note - you can use the old fasioned extension name (as below)...
gl.TexParameter(OpenGL.GL_TEXTURE_CUBE_MAP_EXT, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_CUBE_MAP_EXT, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
// Extensions: ...or the standard OpenGL name. For example, EXT_Texture_Cube_Map
// became standard in OpenGL 1.3 - but we still have the old fasioned extension functions,
// constants etc.
gl.TexParameter(OpenGL.GL_TEXTURE_CUBE_MAP, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
gl.TexParameter(OpenGL.GL_TEXTURE_CUBE_MAP, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);
gl.TexParameter(OpenGL.GL_TEXTURE_CUBE_MAP, OpenGL.GL_TEXTURE_WRAP_R, OpenGL.GL_CLAMP_TO_EDGE);
}
示例2: LoadMaterials
private void LoadMaterials(string path, Scene scene)
{
// Create a stream reader.
using (StreamReader reader = new StreamReader(path))
{
Material mtl = null;
float alpha = 1;
// Read line by line.
string line = null;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
// Skip any comments (lines that start with '#').
if (line.StartsWith("#"))
continue;
// newmatl indicates start of material definition.
if (line.StartsWith("newmtl"))
{
// Add new material to scene's assets.
mtl = new Material();
scene.Assets.Add(mtl);
// Name of material is on same line, immediately follows newmatl.
mtl.Name = ReadMaterialValue(line);
// Reset assumed alpha.
alpha = 1;
}
// Read properties of material.
if (mtl != null)
{
if (line.StartsWith("Ka"))
mtl.Ambient = ReadMaterialColor(line, alpha);
else if (line.StartsWith("Kd"))
mtl.Diffuse = ReadMaterialColor(line, alpha);
else if (line.StartsWith("Ks"))
mtl.Specular = ReadMaterialColor(line, alpha);
else if (line.StartsWith("Ns"))
mtl.Shininess = Convert.ToSingle(ReadMaterialValue(line));
else if (line.StartsWith("map_Ka") ||
line.StartsWith("map_Kd") ||
line.StartsWith("map_Ks"))
{
// Get texture map.
string textureFile = ReadMaterialValue(line);
// Check for existing textures. Create if does not exist.
Texture theTexture = null;
var existingTextures = scene.Assets.Where(t => t is Texture && t.Name == textureFile);
if (existingTextures.Count() >= 1)
theTexture = existingTextures.FirstOrDefault() as Texture;
else
{
// Does the texture file exist?
if (File.Exists(textureFile) == false)
{
// It doesn't, assume its in the same location
// as the obj file.
textureFile = Path.Combine(Path.GetDirectoryName(path),
Path.GetFileName(textureFile));
}
// Create/load texture.
theTexture = new Texture();
theTexture.Create(scene.OpenGL, textureFile);
}
// Set texture for material.
mtl.Texture = theTexture;
}
else if (line.StartsWith("d") || line.StartsWith("Tr"))
{
alpha = Convert.ToSingle(ReadMaterialValue(line));
SetAlphaForMaterial(mtl, alpha);
}
// TODO: Handle illumination mode (illum)
}
}
}
}