本文整理汇总了C#中SharpGL.OpenGL类的典型用法代码示例。如果您正苦于以下问题:C# OpenGL类的具体用法?C# OpenGL怎么用?C# OpenGL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenGL类属于SharpGL命名空间,在下文中一共展示了OpenGL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw3D
public override void Draw3D(OpenGL gl)
{
float drawCoord = (int)(y * 2) % pieces;
float size = 2;
double theta = 0;
if (fever)
{
size = 3f;
if (xpos < -4)
theta = (xpos + 4) * Math.PI / 4;
else if (xpos > 4)
theta = (xpos - 4) * Math.PI / 4;
}
gl.Begin(BeginMode.Quads);
{
if (fever)
gl.Color(1.0f, 0.5f, 0.5f);
gl.TexCoord(drawCoord / pieces, 1);
gl.Vertex(xpos * 0.5f - (0.4f * size) * Math.Cos(theta), y - (0.4f * size) * Math.Sin(theta), 0);
gl.TexCoord(drawCoord / pieces, 0);
gl.Vertex(xpos * 0.5f - (0.4f * size) * Math.Cos(theta), y - (0.4f * size) * Math.Sin(theta), size);
gl.TexCoord((drawCoord + 1) / pieces, 0);
gl.Vertex(xpos * 0.5f + (0.4f * size) * Math.Cos(theta), y + (0.4f * size) * Math.Sin(theta), size);
gl.TexCoord((drawCoord + 1) / pieces, 1);
gl.Vertex(xpos * 0.5f + (0.4f * size) * Math.Cos(theta), y + (0.4f * size) * Math.Sin(theta), 0);
gl.Color(1.0f, 1.0f, 1.0f);
}
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: DrawSprite
public void DrawSprite(float posX, float posY, Sprite sprite, OpenGL gl)
{
float[] verts = {
posX, posY,
posX + 32, posY,
posX + 32, posY + 32,
posX, posY + 32
};
float tw = sprite.spriteWidth;
float th = sprite.spriteHeight;
float tx = sprite.spriteX;
float ty = sprite.spriteY;
float[] texVerts = {
tx, ty,
tx + tw, ty,
tx + tw, ty + th,
tx, ty + th
};
gl.Color(1.0, 1.0, 1.0, 1.0); // reset gl color
tex.Bind(gl);
gl.Begin(OpenGL.GL_QUADS);
gl.TexCoord(texVerts[0], texVerts[1]); gl.Vertex(verts[0], verts[1], 0.0f); // Bottom Left Of The Texture and Quad
gl.TexCoord(texVerts[2], texVerts[3]); gl.Vertex(verts[2], verts[3], 0.0f); // Bottom Right Of The Texture and Quad
gl.TexCoord(texVerts[4], texVerts[5]); gl.Vertex(verts[4], verts[5], 0.0f); // Top Right Of The Texture and Quad
gl.TexCoord(texVerts[6], texVerts[7]); gl.Vertex(verts[6], verts[7], 0.0f); // Top Left Of The Texture and Quad
gl.End();
//this is sposed to be better but doesnt seem to work
//gl.VertexPointer(2, OpenGL.GL_FLOAT, 0, verts);
//gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, texVerts);
//gl.DrawArrays(OpenGL.GL_TRIANGLE_STRIP,0,4);
}
示例4: VAO
public VAO(OpenGL gl, IShaderProgram program, VBO vbo)
{
_gl = gl;
_program = program;
VBO = vbo;
var buffers = new uint[1];
gl.GenVertexArrays(1, buffers);
Handle = buffers[0];
using (new Bind(program))
using (new Bind(this))
using (new Bind(vbo))
{
var stride = Vect3f.SizeInBytes * 2 + Vect4f.SizeInBytes;
gl.EnableVertexAttribArray(0);
gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, true, stride, IntPtr.Zero);
gl.BindAttribLocation(program.Handle, 0, "vert_position");
gl.EnableVertexAttribArray(1);
gl.VertexAttribPointer(1, 3, OpenGL.GL_FLOAT, true, stride, new IntPtr(Vect3f.SizeInBytes));
gl.BindAttribLocation(program.Handle, 1, "vert_normal");
gl.EnableVertexAttribArray(2);
gl.VertexAttribPointer(2, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(Vect3f.SizeInBytes * 2));
gl.BindAttribLocation(program.Handle, 2, "vert_colour");
}
}
示例5: Initialise
/// <summary>
/// Initialises the scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="width">The width of the screen.</param>
/// <param name="height">The height of the screen.</param>
public void Initialise(OpenGL gl, float width, float height)
{
// Set a blue clear colour.
gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);
// Create the shader program.
var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
shaderProgram = new ShaderProgram();
shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
shaderProgram.AssertValid(gl);
// Create a perspective projection matrix.
const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);
// Create a view matrix to move us back a bit.
viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));
// Create a model matrix to make the model a little bigger.
modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));
// Now create the geometry for the square.
CreateVerticesForSquare(gl);
}
示例6: Initialise
/// <summary>
/// Initialises the Scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void Initialise(OpenGL gl)
{
// We're going to specify the attribute locations for the position and normal,
// so that we can force both shaders to explicitly have the same locations.
const uint positionAttribute = 0;
const uint normalAttribute = 1;
var attributeLocations = new Dictionary<uint, string>
{
{positionAttribute, "Position"},
{normalAttribute, "Normal"},
};
// Create the per pixel shader.
shaderPerPixel = new ShaderProgram();
shaderPerPixel.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);
// Create the toon shader.
shaderToon = new ShaderProgram();
shaderToon.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);
// Generate the geometry and it's buffers.
trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
}
示例7: CreateDisplayList
private void CreateDisplayList(OpenGL gl)
{
displayList = new DisplayList();
displayList.Generate(gl);
displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);
//Push all attributes, disable lighting and depth testing.
gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.DepthFunc(OpenGL.GL_ALWAYS);
//Set line width.
gl.LineWidth(lineWidth);
//Draw the line.
gl.Begin(OpenGL.GL_LINES);
gl.Color(Convert.ColorToGLColor(c1));
gl.Vertex(v1.X, v1.Y, v1.Z);
gl.Color(Convert.ColorToGLColor(c2));
gl.Vertex(v2.X, v2.Y, v2.Z);
gl.End();
// Restore attributes.
gl.PopAttrib();
displayList.End(gl);
}
示例8: Draw
public static void Draw(OpenGL gl, double height, double length, double width)
{
gl.LineWidth(1);
gl.Color(0.7, 0.7, 0.7);
gl.Begin(OpenGL.GL_LINE_LOOP);
gl.Vertex(0, height, 0 );
gl.Vertex(0, height, width);
gl.Vertex(length, height, width);
gl.Vertex(length, height, 0 );
gl.End();
gl.Begin(OpenGL.GL_LINES);
gl.Vertex(0, height, 0);
gl.Vertex(0, 0, 0);
gl.Vertex(length, height, 0);
gl.Vertex(length, 0, 0);
gl.Vertex(0, height, width);
gl.Vertex(0, 0, width);
gl.Vertex(length, height, width);
gl.Vertex(length, 0, width);
gl.End();
gl.Begin(OpenGL.GL_LINE_LOOP);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 0, width);
gl.Vertex(length, 0, width);
gl.Vertex(length, 0, 0);
gl.End();
}
示例9: InitShader
void IRenderable.Render(OpenGL gl, RenderMode renderMode)
{
if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
{
if (this.shaderProgram == null)
{
this.shaderProgram = InitShader(gl, renderMode);
}
if (this.vertexArrayObject == null)
{
CreateVertexArrayObject(gl, renderMode);
}
BeforeRendering(gl, renderMode);
if (this.RenderGrid && this.vertexArrayObject != null)
{
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
}
AfterRendering(gl, renderMode);
}
}
示例10: DatumPlaneLeaf
public DatumPlaneLeaf(OpenGL gl, IShaderProgram shader, IEnumerable<DatumPlane> planes)
{
_gl = gl;
_shader = shader;
var linedata = new List<Vert>();
var quaddata = new List<Vert>();
const float size = 20f;
foreach (var plane in planes)
{
var v1 = (plane.Transform * Mat4.Translate(new Vect3(-size / 2.0, -size / 2.0, 0))).ToVect3();
var v2 = (plane.Transform * Mat4.Translate(new Vect3(size / 2.0, -size / 2.0, 0))).ToVect3();
var v3 = (plane.Transform * Mat4.Translate(new Vect3(size / 2.0, size / 2.0, 0))).ToVect3();
var v4 = (plane.Transform * Mat4.Translate(new Vect3(-size / 2.0, size / 2.0, 0))).ToVect3();
linedata.Add(new Vert(v1, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v2, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v2, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v3, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v3, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v4, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v4, Vect3.Zero, _edgecolour));
linedata.Add(new Vert(v1, Vect3.Zero, _edgecolour));
quaddata.AddRange(new[] { new Vert(v1, Vect3.Zero, _basecolour), new Vert(v2, Vect3.Zero, _basecolour), new Vert(v3, Vect3.Zero, _basecolour), new Vert(v4, Vect3.Zero, _basecolour) });
quaddata.AddRange(new[] { new Vert(v4, Vect3.Zero, _basecolour), new Vert(v3, Vect3.Zero, _basecolour), new Vert(v2, Vect3.Zero, _basecolour), new Vert(v1, Vect3.Zero, _basecolour) });
}
_lineVAO = new VAO(gl, _shader, new VBO(gl, BeginMode.Lines, linedata));
_quadVAO = new VAO(gl, _shader, new VBO(gl, BeginMode.Quads, quaddata));
}
示例11: BackgroundShader
public BackgroundShader(OpenGL gl)
: base(gl)
{
_program = new ShaderProgram();
var vertex = new VertexShader();
var fragment = new FragmentShader();
vertex.CreateInContext(gl);
vertex.SetSource(File.ReadAllText("Shaders/Background.vert.glsl"));
vertex.Compile();
fragment.CreateInContext(gl);
fragment.SetSource(File.ReadAllText("Shaders/Background.frag.glsl"));
fragment.Compile();
_program.CreateInContext(gl);
_program.AttachShader(vertex);
_program.AttachShader(fragment);
_program.Link();
Debug.WriteLine(_program.InfoLog);
foreach (var attachedShader in _program.AttachedShaders)
{
Debug.WriteLine(attachedShader.InfoLog);
}
}
示例12: LinesBase
public LinesBase(OpenGL gl, List<Tuple<vec3, vec3>> lines, Material material = null, OGLModelUsage usage = OGLModelUsage.StaticRead)
{
var verts = new vec3[lines.Count * 2];
var normals = new vec3[lines.Count * 2];
var indices = new uint[lines.Count * 2];
for (int i = 0; i < lines.Count; i++)
{
var i2 = i * 2;
verts[i2] = lines[i].Item1;
verts[i2 + 1] = lines[i].Item2;
normals[i2] = new vec3(1, 1, 1);
normals[i2 + 1] = new vec3(1, 1, 1);
indices[i2] = (uint)i2;
indices[i2 + 1] = (uint)(i2 + 1);
}
if (material != null)
Material = material;
Vertices = verts;
Normals = normals;
Indices = indices;
GlDrawMode = OpenGL.GL_LINES;
if (gl != null)
GenerateGeometry(gl, usage);
}
示例13: PushObjectSpace
public void PushObjectSpace(OpenGL gl)
{
gl.PushMatrix();
gl.Translate(pos.X, pos.Y, pos.Z);
if (material != null)
material.Push(gl);
}
示例14: Render
public override void Render(OpenGL gl)
{
if (displayList == null)
CreateDisplayList(gl);
else
displayList.Call(gl);
}
示例15: InitTextures
public void InitTextures(OpenGL gl)
{
gl.GenerateMipmapEXT(OpenGL.GL_TEXTURE_2D);
foreach(ImageTexture tex in _textures){
tex.InitTexture(gl);
}
}