本文整理匯總了C#中SharpGL.OpenGL.MakeCurrent方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.MakeCurrent方法的具體用法?C# OpenGL.MakeCurrent怎麽用?C# OpenGL.MakeCurrent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.MakeCurrent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateFontBitmapEntry
private FontBitmapEntry CreateFontBitmapEntry(OpenGL gl, string faceName, int height)
{
// Make the OpenGL instance current.
gl.MakeCurrent();
// Create the font based on the face name.
var hFont = Win32.CreateFont(height, 0, 0, 0, Win32.FW_NORMAL, 0, 0, 0, Win32.DEFAULT_CHARSET,
Win32.OUT_OUTLINE_PRECIS, Win32.CLIP_DEFAULT_PRECIS, Win32.CLEARTYPE_QUALITY, Win32.FIXED_PITCH, faceName);
// Select the font handle.
var hOldObject = Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hFont);
// Create the list base.
var listBase = gl.GenLists(255);
// Create the font bitmaps.
bool result = Win32.wglUseFontBitmaps(gl.RenderContextProvider.DeviceContextHandle, 0, 255, listBase);
// Reselect the old font.
Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hOldObject);
// Free the font.
Win32.DeleteObject(hFont);
// Create the font bitmap entry.
if (result)
{
var fbe = new FontBitmapEntry()
{
HDC = gl.RenderContextProvider.DeviceContextHandle,
HRC = gl.RenderContextProvider.RenderContextHandle,
FaceName = faceName,
Height = height,
ListBase = listBase,
ListCount = 255
};
// Add the font bitmap entry to the internal list.
fontBitmapEntries.Add(fbe);
return fbe;
}
else return null;
}
示例2: Initialize
public void Initialize(IntPtr handle, Viewport viewport)
{
this.viewport = viewport;
gl = new OpenGL();
gl.Create(RenderContextType.NativeWindow, viewport.Width, viewport.Height, 32, handle);
gl.MakeCurrent();
ShaderManager.Initialize(gl);
MaterialManager.Initialize(gl);
renderer = new Renderer();
renderer.Initialize(gl);
camera = new PerspectiveCamera();
camera.LocalTranslate(new Vector(0, 0, 3));
var mesh = new Mesh(gl, MeshType.Points);
mesh.AddBuffer(
new Buffer<Point>(gl,
new Point(-2, -2, 0),
new Point(-1, -1, 0),
new Point( 0, 0, 0),
new Point( 1, -1, 0),
new Point( 2, -2, 0)));
scene = new Scene();
scene.Add(camera);
for (int j = -10; j < 10; j++)
for (int i = -10; i < 10; i++)
{
var e = new PhysicalEntity(mesh, MaterialManager.GetMaterial("Voxels"));
e.GlobalTranslate(Vector.UnitZ * -5 * i);
e.GlobalTranslate(Vector.UnitX * -5 * j);
scene.Add(e);
}
gl.MakeNothingCurrent();
}
示例3: CreateFontBitmapEntry
private FontBitmapEntry CreateFontBitmapEntry(OpenGL gl, string faceName, int height)
{
// Make the OpenGL instance current.
gl.MakeCurrent();
// Create the font based on the face name.
IntPtr hFont = Win32.CreateFont(height, 0, 0, 0, Win32.FW_DONTCARE, 0, 0, 0, Win32.DEFAULT_CHARSET,
Win32.OUT_OUTLINE_PRECIS, Win32.CLIP_DEFAULT_PRECIS, Win32.CLEARTYPE_QUALITY, Win32.VARIABLE_PITCH, faceName);
// Select the font handle.
IntPtr hOldObject = Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hFont);
// Create the font bitmaps.
bool result = Win32.wglUseFontBitmaps(gl.RenderContextProvider.DeviceContextHandle, 0, 255, nextListBase);
// Reselect the old font.
Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hOldObject);
// Free the font.
Win32.DeleteObject(hFont);
// Create the font bitmap entry.
FontBitmapEntry fbe = new FontBitmapEntry()
{
HDC = gl.RenderContextProvider.DeviceContextHandle,
HRC = gl.RenderContextProvider.RenderContextHandle,
FaceName = faceName,
Height = height,
ListBase = nextListBase,
ListCount = 255
};
// Add the font bitmap entry to the internal list.
fontBitmapEntries.Add(fbe);
// Shift the list base.
nextListBase += 1000;
return fbe;
}
示例4: CreateFontOutlineEntry
private FontOutlineEntry CreateFontOutlineEntry(OpenGL gl, string faceName, int height,
float deviation, float extrusion, FontOutlineFormat fontOutlineFormat)
{
// Make the OpenGL instance current.
gl.MakeCurrent();
// Create the font based on the face name.
var hFont = Win32.CreateFont(height, 0, 0, 0, Win32.FW_DONTCARE, 0, 0, 0, Win32.DEFAULT_CHARSET,
Win32.OUT_OUTLINE_PRECIS, Win32.CLIP_DEFAULT_PRECIS, Win32.CLEARTYPE_QUALITY, Win32.VARIABLE_PITCH, faceName);
// Select the font handle.
var hOldObject = Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hFont);
// Create the list base.
var listBase = gl.GenLists(1);
// Create the font bitmaps.
bool result = Win32.wglUseFontOutlines(gl.RenderContextProvider.DeviceContextHandle, 0, 255, listBase,
deviation, extrusion, (int)fontOutlineFormat, IntPtr.Zero);
// Reselect the old font.
Win32.SelectObject(gl.RenderContextProvider.DeviceContextHandle, hOldObject);
// Free the font.
Win32.DeleteObject(hFont);
// Create the font bitmap entry.
var foe = new FontOutlineEntry()
{
HDC = gl.RenderContextProvider.DeviceContextHandle,
HRC = gl.RenderContextProvider.RenderContextHandle,
FaceName = faceName,
Height = height,
ListBase = listBase,
ListCount = 255,
Deviation = deviation,
Extrusion = extrusion,
FontOutlineFormat = fontOutlineFormat
};
// Add the font bitmap entry to the internal list.
fontOutlineEntries.Add(foe);
return foe;
}
示例5: GetModelAtPointHack
/// <summary>
/// Source: http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-an-opengl-hack/
/// It's recommended to read the source before using this algorithm.
/// </summary>
/// <param name="scene">The OpenGLScene.</param>
/// <param name="point">The 2D point.</param>
/// <param name="models">The drawn models.</param>
/// <param name="performanceScaleValue">A factor that affects performance by scaling the size of the temperory viewport.</param>
/// <returns>The model on this location or null.</returns>
public static int GetModelAtPointHack(Point point, IEnumerable<ElementAndTransformation> models,
int[] viewport, ModelView modelview, Projection projection, Normal normal, float performanceScaleValue = 1)
{
return -1; // TODO
int id = -1;
int width = (int)(viewport[2] * performanceScaleValue);
int height = (int)(viewport[3] * performanceScaleValue);
int x = (int)(point.X * performanceScaleValue);
int y = height - (int)(point.Y * performanceScaleValue);
#region create a temperory gl to prevent flickering
OpenGL gl = new OpenGL();
// Create OpenGL.
var openGLVersion = OpenGLVersion.OpenGL2_1;
var renderContextType = RenderContextType.FBO;
gl.Create(openGLVersion, renderContextType, 1, 1, 32, null);
// Set the dimensions and viewport.
gl.SetDimensions(width, height);
gl.Viewport(0, 0, width, height);
// Make GL current.
gl.MakeCurrent();
gl.Enable(OpenGL.GL_DEPTH_TEST);
//gl.Clear(OpenGL.GL_DEPTH_CLEAR_VALUE);
#endregion create a temperory gl to prevent flickering
// Initialize the shader for our new GL.
//var esp = Shaders.LoadSimpleShader(gl);
//var idxModelTransformation = new List<Tuple<int, int>>(); // Item1 = idx in models; Item2 = idx of model.Transformations
//var buffersToBeRemoved = new List<uint>();
//esp.UseProgram(gl, () =>
//{
// // Set the matrices.
// esp.ApplyMVPNMatrices(gl, modelview, projection, normal);
// var curModelId = 0;
// // render models, using a temperory color
// for (int i = 0; i < models.Count(); )
// {
// var model = models.ElementAt(i);
// // Extract the color. Since we don't need the i in this loop anymore, we can use it to set the color.
// i++; // We don't want to use 0 for the color, so we increment it already. ( = black)
// var col = new ColorF(Convert.ToUInt32(i*20));
// esp.ApplyMaterial(gl, new Material() { Ambient = col });
// // Use the transformation in the model, else use the identity matrix (I do this to override previous transformations)
// if (model.Transformation != null)
// esp.ApplyTransformationMatrix(gl, model.Transformation.ResultMatrix);
// else
// esp.ApplyTransformationMatrix(gl, mat4.identity());
// var createdBuffers = OGLVisualSceneElementBase.GenerateAndDrawOnce(gl, (OGLVisualSceneElementBase)model.SceneElement); // model.Render(gl, RenderMode.HitTest);
// buffersToBeRemoved.AddRange(createdBuffers);
// }
//});
//esp.Dispose();
//// Wait for GPU to finish.
//gl.Flush();
//gl.Finish();
//gl.PixelStore(OpenGL.GL_UNPACK_ALIGNMENT, 1);
//uint format = OpenGL.GL_RGBA;
//uint type = OpenGL.GL_UNSIGNED_BYTE;
//byte[] data = new byte[40];
//gl.ReadPixels(x, y, 1, 1, format, type, data);
//// Delete the created buffers.
//gl.DeleteBuffers(buffersToBeRemoved.Count, buffersToBeRemoved.ToArray());
//// Remove the temperory gl from memory.
//gl.RenderContextProvider.Dispose();
//// Get color id from pixel data.
//id = data[0] + data[1] * 255 + data[2] * 65025; // id = r + g * 255 + b * 255².
//// if the pixel is black, then there was nothing selected.
//if (id == 0)
//{
// return -1;
//.........這裏部分代碼省略.........