Ich habe den Quellcode von SharpGL jetzt direkt implementiert und einen Bug darin behoben. Damit kann ich nun auch OpenGL 4.3 verwenden! 😄

master
mono 4 years ago
parent 8426e9ec41
commit 3e47899971

@ -23,35 +23,34 @@
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.canvas1 = new JuicyGraphics.canvas();
((System.ComponentModel.ISupportInitialize)(this.canvas1)).BeginInit();
this.canvas2 = new JuicyGraphics.canvas();
((System.ComponentModel.ISupportInitialize)(this.canvas2)).BeginInit();
this.SuspendLayout();
//
// canvas1
// canvas2
//
this.canvas1.Dock = System.Windows.Forms.DockStyle.Fill;
this.canvas1.Location = new System.Drawing.Point(0, 0);
this.canvas1.Name = "canvas1";
this.canvas1.Size = new System.Drawing.Size(704, 521);
this.canvas1.TabIndex = 0;
this.canvas1.Text = "canvas1";
this.canvas2.Dock = System.Windows.Forms.DockStyle.Fill;
this.canvas2.Location = new System.Drawing.Point(0, 0);
this.canvas2.Name = "canvas2";
this.canvas2.Size = new System.Drawing.Size(704, 521);
this.canvas2.TabIndex = 3;
this.canvas2.Text = "canvas2";
//
// mainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 521);
this.Controls.Add(this.canvas1);
this.Controls.Add(this.canvas2);
this.Name = "mainForm";
this.Text = "JuicyGraphics";
((System.ComponentModel.ISupportInitialize)(this.canvas1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.canvas2)).EndInit();
this.ResumeLayout(false);
}
#endregion
private canvas canvas1;
private canvas canvas2;
}
}

@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -31,15 +32,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpGL, Version=2.4.0.0, Culture=neutral, PublicKeyToken=27fc851303210b27, processorArchitecture=MSIL">
<HintPath>packages\SharpGL.2.4.0.0\lib\net40\SharpGL.dll</HintPath>
</Reference>
<Reference Include="SharpGL.SceneGraph, Version=2.4.0.0, Culture=neutral, PublicKeyToken=27fc851303210b27, processorArchitecture=MSIL">
<HintPath>packages\SharpGL.2.4.0.0\lib\net40\SharpGL.SceneGraph.dll</HintPath>
</Reference>
<Reference Include="SharpGL.WinForms, Version=2.4.0.0, Culture=neutral, PublicKeyToken=27fc851303210b27, processorArchitecture=MSIL">
<HintPath>packages\SharpGL.WinForms.2.4.0.0\lib\net40\SharpGL.WinForms.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -64,6 +56,30 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpGL\DIBSection.cs" />
<Compile Include="SharpGL\Enumerations\OpenGLEnumerations.cs" />
<Compile Include="SharpGL\FontBitmaps.cs" />
<Compile Include="SharpGL\FontOutlines.cs" />
<Compile Include="SharpGL\OpenGL.cs" />
<Compile Include="SharpGL\OpenGLExtensions.cs" />
<Compile Include="SharpGL\RenderContextProviders\DIBSectionRenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\ExternalRenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\FBORenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\HiddenWindowRenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\IRenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\NativeWindowRenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextProviders\RenderContextProvider.cs" />
<Compile Include="SharpGL\RenderContextType.cs" />
<Compile Include="SharpGL\Shaders\Shader.cs" />
<Compile Include="SharpGL\Shaders\ShaderCompilationException.cs" />
<Compile Include="SharpGL\Shaders\ShaderProgram.cs" />
<Compile Include="SharpGL\Tesselators\Delegates.cs" />
<Compile Include="SharpGL\Version\OpenGLVersion.cs" />
<Compile Include="SharpGL\Version\VersionAttribute.cs" />
<Compile Include="SharpGL\VertexBuffers\IndexBuffer.cs" />
<Compile Include="SharpGL\VertexBuffers\VertexBuffer.cs" />
<Compile Include="SharpGL\VertexBuffers\VertexBufferArray.cs" />
<Compile Include="SharpGL\Win32.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
@ -76,7 +92,6 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -90,5 +105,6 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,197 @@
using System;
using System.Runtime.InteropServices;
namespace SharpGL
{
/// <summary>
///
/// </summary>
public class DIBSection : IDisposable
{
/// <summary>
/// Creates the specified width.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitCount">The bit count.</param>
/// <returns></returns>
public virtual unsafe bool Create(IntPtr hDC, int width, int height, int bitCount)
{
this.width = width;
this.height = height;
parentDC = hDC;
// Destroy existing objects.
Destroy();
// Create a bitmap info structure.
Win32.BITMAPINFO info = new Win32.BITMAPINFO();
info.Init();
// Set the data.
info.biBitCount = (short)bitCount;
info.biPlanes = 1;
info.biWidth = width;
info.biHeight = height;
// Create the bitmap.
hBitmap = Win32.CreateDIBSection(hDC, ref info, Win32.DIB_RGB_COLORS,
out bits, IntPtr.Zero, 0);
Win32.SelectObject(hDC, hBitmap);
// Set the OpenGL pixel format.
SetPixelFormat(hDC, bitCount);
return true;
}
/// <summary>
/// Resizes the section.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitCount">The bit count.</param>
public void Resize(int width, int height, int bitCount)
{
// Destroy existing objects.
Destroy();
// Set parameters.
Width = width;
Height = height;
// Create a bitmap info structure.
Win32.BITMAPINFO info = new Win32.BITMAPINFO();
info.Init();
// Set the data.
info.biBitCount = (short)bitCount;
info.biPlanes = 1;
info.biWidth = width;
info.biHeight = height;
// Create the bitmap.
hBitmap = Win32.CreateDIBSection(parentDC, ref info, Win32.DIB_RGB_COLORS,
out bits, IntPtr.Zero, 0);
Win32.SelectObject(parentDC, hBitmap);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Destroy();
}
/// <summary>
/// This function sets the pixel format of the underlying bitmap.
/// </summary>
/// <param name="bitCount">The bitcount.</param>
protected virtual bool SetPixelFormat(IntPtr hDC, int bitCount)
{
// Create the big lame pixel format majoo.
Win32.PIXELFORMATDESCRIPTOR pixelFormat = new Win32.PIXELFORMATDESCRIPTOR();
pixelFormat.Init();
// Set the values for the pixel format.
pixelFormat.nVersion = 1;
pixelFormat.dwFlags = (Win32.PFD_DRAW_TO_BITMAP | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_SUPPORT_GDI);
pixelFormat.iPixelType = Win32.PFD_TYPE_RGBA;
pixelFormat.cColorBits = (byte)bitCount;
pixelFormat.cDepthBits = 32;
pixelFormat.iLayerType = Win32.PFD_MAIN_PLANE;
// Match an appropriate pixel format
int iPixelformat;
if((iPixelformat = Win32.ChoosePixelFormat(hDC, pixelFormat)) == 0 )
return false;
// Sets the pixel format
if (Win32.SetPixelFormat(hDC, iPixelformat, pixelFormat) == 0)
{
int lastError = Marshal.GetLastWin32Error();
return false;
}
return true;
}
/// <summary>
/// Destroys this instance.
/// </summary>
public virtual void Destroy()
{
// Destroy the bitmap.
if(hBitmap != IntPtr.Zero)
{
Win32.DeleteObject(hBitmap);
hBitmap = IntPtr.Zero;
}
}
/// <summary>
/// The parent dc.
/// </summary>
protected IntPtr parentDC = IntPtr.Zero;
/// <summary>
/// The bitmap handle.
/// </summary>
protected IntPtr hBitmap = IntPtr.Zero;
/// <summary>
/// The bits.
/// </summary>
protected IntPtr bits = IntPtr.Zero;
/// <summary>
/// The width.
/// </summary>
protected int width = 0;
/// <summary>
/// The height.
/// </summary>
protected int height = 0;
/// <summary>
/// Gets the handle to the bitmap.
/// </summary>
/// <value>The handle to the bitmap.</value>
public IntPtr HBitmap
{
get {return hBitmap;}
}
/// <summary>
/// Gets the bits.
/// </summary>
public IntPtr Bits
{
get { return bits; }
}
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
public int Width
{
get { return width; }
protected set { width = value; }
}
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>The height.</value>
public int Height
{
get {return height;}
protected set { height = value; }
}
}
}

@ -0,0 +1,695 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpGL.Enumerations
{
/// <summary>
/// AccumOp
/// </summary>
public enum AccumOperation : uint
{
Accum = OpenGL.GL_ACCUM,
Load = OpenGL.GL_LOAD,
Return = OpenGL.GL_RETURN,
Multiple = OpenGL.GL_MULT,
Add = OpenGL.GL_ADD
}
/// <summary>
/// The alpha function
/// </summary>
public enum AlphaTestFunction : uint
{
Never = OpenGL.GL_NEVER,
Less = OpenGL.GL_LESS,
Equal = OpenGL.GL_EQUAL,
LessThanOrEqual = OpenGL.GL_LEQUAL,
Great = OpenGL.GL_GREATER,
NotEqual = OpenGL.GL_NOTEQUAL,
GreaterThanOrEqual = OpenGL.GL_GEQUAL,
Always = OpenGL.GL_ALWAYS,
}
/// <summary>
/// The OpenGL Attribute flags.
/// </summary>
[Flags]
public enum AttributeMask : uint
{
None = 0,
Current = OpenGL.GL_CURRENT_BIT,
Point = OpenGL.GL_POINT_BIT,
Line = OpenGL.GL_LINE_BIT,
Polygon = OpenGL.GL_POLYGON_BIT,
PolygonStipple = OpenGL.GL_POLYGON_STIPPLE_BIT,
PixelMode = OpenGL.GL_PIXEL_MODE_BIT,
Lighting = OpenGL.GL_LIGHTING_BIT,
Fog = OpenGL.GL_FOG_BIT,
DepthBuffer = OpenGL.GL_DEPTH_BUFFER_BIT,
AccumBuffer = OpenGL.GL_ACCUM_BUFFER_BIT,
StencilBuffer = OpenGL.GL_STENCIL_BUFFER_BIT,
Viewport = OpenGL.GL_VIEWPORT_BIT,
Transform = OpenGL.GL_TRANSFORM_BIT,
Enable = OpenGL.GL_ENABLE_BIT,
ColorBuffer = OpenGL.GL_COLOR_BUFFER_BIT,
Hint = OpenGL.GL_HINT_BIT,
Eval = OpenGL.GL_EVAL_BIT,
List = OpenGL.GL_LIST_BIT,
Texture = OpenGL.GL_TEXTURE_BIT,
Scissor = OpenGL.GL_SCISSOR_BIT,
All = OpenGL.GL_ALL_ATTRIB_BITS,
}
/// <summary>
/// The begin mode.
/// </summary>
public enum BeginMode : uint
{
Points = OpenGL.GL_POINTS,
Lines = OpenGL.GL_LINES,
LineLoop = OpenGL.GL_LINE_LOOP,
LineStrip = OpenGL.GL_LINE_STRIP,
Triangles = OpenGL.GL_TRIANGLES,
TriangleString = OpenGL.GL_TRIANGLE_STRIP,
TriangleFan = OpenGL.GL_TRIANGLE_FAN,
Quads= OpenGL.GL_QUADS,
QuadStrip = OpenGL.GL_QUAD_STRIP,
Polygon = OpenGL.GL_POLYGON
}
/// <summary>
/// BlendingDestinationFactor
/// </summary>
public enum BlendingDestinationFactor : uint
{
Zero = OpenGL.GL_ZERO,
One = OpenGL.GL_ONE,
SourceColor = OpenGL.GL_SRC_COLOR,
OneMinusSourceColor = OpenGL.GL_ONE_MINUS_SRC_COLOR,
SourceAlpha = OpenGL.GL_SRC_ALPHA,
OneMinusSourceAlpha = OpenGL.GL_ONE_MINUS_SRC_ALPHA,
DestinationAlpha = OpenGL.GL_DST_ALPHA,
OneMinusDestinationAlpha = OpenGL.GL_ONE_MINUS_DST_ALPHA,
}
/// <summary>
/// The blending source factor.
/// </summary>
public enum BlendingSourceFactor : uint
{
DestinationColor = OpenGL.GL_DST_COLOR,
OneMinusDestinationColor = OpenGL.GL_ONE_MINUS_DST_COLOR,
SourceAlphaSaturate = OpenGL.GL_SRC_ALPHA_SATURATE,
/// <summary>
///
/// </summary>
SourceAlpha = OpenGL.GL_SRC_ALPHA
}
/// <summary>
/// The Clip Plane Name
/// </summary>
public enum ClipPlaneName : uint
{
ClipPlane0 = OpenGL.GL_CLIP_PLANE0,
ClipPlane1 = OpenGL.GL_CLIP_PLANE1,
ClipPlane2 = OpenGL.GL_CLIP_PLANE2,
ClipPlane3 = OpenGL.GL_CLIP_PLANE3,
ClipPlane4 = OpenGL.GL_CLIP_PLANE4,
ClipPlane5 = OpenGL.GL_CLIP_PLANE5
}
/// <summary>
/// The Cull Face mode.
/// </summary>
public enum FaceMode : uint
{
/// <summary>
///
/// </summary>
Front = OpenGL.GL_FRONT,
FrontAndBack = OpenGL.GL_FRONT_AND_BACK,
Back = OpenGL.GL_BACK,
}
/// <summary>
/// The Data Type.
/// </summary>
public enum DataType : uint
{
Byte = OpenGL.GL_BYTE,
UnsignedByte = OpenGL.GL_UNSIGNED_BYTE,
Short = OpenGL.GL_SHORT,
UnsignedShort = OpenGL.GL_UNSIGNED_SHORT,
Int = OpenGL.GL_INT,
UnsignedInt = OpenGL.GL_UNSIGNED_INT,
Float = OpenGL.GL_FLOAT,
TwoBytes = OpenGL.GL_2_BYTES,
ThreeBytes = OpenGL.GL_3_BYTES,
FourBytes = OpenGL.GL_4_BYTES,
/// <summary>
///
/// </summary>
Double= OpenGL.GL_DOUBLE
}
/// <summary>
/// The depth function
/// </summary>
public enum DepthFunction : uint
{
Never = OpenGL.GL_NEVER,
Less = OpenGL.GL_LESS,
Equal = OpenGL.GL_EQUAL,
LessThanOrEqual = OpenGL.GL_LEQUAL,
Great = OpenGL.GL_GREATER,
NotEqual = OpenGL.GL_NOTEQUAL,
GreaterThanOrEqual = OpenGL.GL_GEQUAL,
Always = OpenGL.GL_ALWAYS,
}
/// <summary>
/// The Draw Buffer Mode
/// </summary>
public enum DrawBufferMode : uint
{
None = OpenGL.GL_NONE,
FrontLeft = OpenGL.GL_FRONT_LEFT,
FrontRight = OpenGL.GL_FRONT_RIGHT,
BackLeft = OpenGL.GL_BACK_LEFT,
BackRight = OpenGL.GL_BACK_RIGHT,
Front = OpenGL.GL_FRONT,
Back = OpenGL.GL_BACK,
Left = OpenGL.GL_LEFT,
Right = OpenGL.GL_RIGHT,
FrontAndBack = OpenGL.GL_FRONT_AND_BACK,
Auxilliary0= OpenGL.GL_AUX0,
Auxilliary1 = OpenGL.GL_AUX1,
Auxilliary2 = OpenGL.GL_AUX2,
Auxilliary3 = OpenGL.GL_AUX3,
}
/// <summary>
/// Error Code
/// </summary>
public enum ErrorCode : uint
{
NoError = OpenGL.GL_NO_ERROR,
InvalidEnum = OpenGL.GL_INVALID_ENUM,
InvalidValue = OpenGL.GL_INVALID_VALUE,
InvalidOperation = OpenGL.GL_INVALID_OPERATION,
StackOverflow = OpenGL.GL_STACK_OVERFLOW,
StackUnderflow = OpenGL.GL_STACK_UNDERFLOW,
OutOfMemory = OpenGL.GL_OUT_OF_MEMORY
}
/// <summary>
/// FeedBackMode
/// </summary>
public enum FeedbackMode : uint
{
TwoD = OpenGL.GL_2D,
ThreeD = OpenGL.GL_3D,
FourD = OpenGL.GL_4D_COLOR,
ThreeDColorTexture = OpenGL.GL_3D_COLOR_TEXTURE,
FourDColorTexture = OpenGL.GL_4D_COLOR_TEXTURE
}
/// <summary>
/// The Feedback Token
/// </summary>
public enum FeedbackToken : uint
{
PassThroughToken = OpenGL.GL_PASS_THROUGH_TOKEN,
PointToken = OpenGL.GL_POINT_TOKEN,
LineToken = OpenGL.GL_LINE_TOKEN,
PolygonToken = OpenGL.GL_POLYGON_TOKEN,
BitmapToken = OpenGL.GL_BITMAP_TOKEN,
DrawPixelToken = OpenGL.GL_DRAW_PIXEL_TOKEN,
CopyPixelToken = OpenGL.GL_COPY_PIXEL_TOKEN,
LineResetToken = OpenGL.GL_LINE_RESET_TOKEN
}
/// <summary>
/// The Fog Mode.
/// </summary>
public enum FogMode : uint
{
Exp = OpenGL.GL_EXP,
/// <summary>
///
/// </summary>
Exp2 = OpenGL.GL_EXP2,
}
/// <summary>
/// GetMapTarget
/// </summary>
public enum GetMapTarget : uint
{
Coeff = OpenGL.GL_COEFF,
Order = OpenGL.GL_ORDER,
Domain = OpenGL.GL_DOMAIN
}
public enum GetTarget : uint
{
CurrentColor = OpenGL.GL_CURRENT_COLOR,
CurrentIndex = OpenGL.GL_CURRENT_INDEX,
CurrentNormal = OpenGL.GL_CURRENT_NORMAL,
CurrentTextureCoords = OpenGL.GL_CURRENT_TEXTURE_COORDS,
CurrentRasterColor = OpenGL.GL_CURRENT_RASTER_COLOR,
CurrentRasterIndex = OpenGL.GL_CURRENT_RASTER_INDEX,
CurrentRasterTextureCoords = OpenGL.GL_CURRENT_RASTER_TEXTURE_COORDS,
CurrentRasterPosition = OpenGL.GL_CURRENT_RASTER_POSITION,
CurrentRasterPositionValid = OpenGL.GL_CURRENT_RASTER_POSITION_VALID,
CurrentRasterDistance = OpenGL.GL_CURRENT_RASTER_DISTANCE,
PointSmooth = OpenGL.GL_POINT_SMOOTH,
PointSize = OpenGL.GL_POINT_SIZE,
PointSizeRange = OpenGL.GL_POINT_SIZE_RANGE,
PointSizeGranularity = OpenGL.GL_POINT_SIZE_GRANULARITY,
LineSmooth = OpenGL.GL_LINE_SMOOTH,
LineWidth = OpenGL.GL_LINE_WIDTH,
LineWidthRange = OpenGL.GL_LINE_WIDTH_RANGE,
LineWidthGranularity = OpenGL.GL_LINE_WIDTH_GRANULARITY,
LineStipple = OpenGL.GL_LINE_STIPPLE,
LineStipplePattern = OpenGL.GL_LINE_STIPPLE_PATTERN,
LineStippleRepeat = OpenGL.GL_LINE_STIPPLE_REPEAT,
ListMode = OpenGL.GL_LIST_MODE,
MaxListNesting = OpenGL.GL_MAX_LIST_NESTING,
ListBase = OpenGL.GL_LIST_BASE,
ListIndex = OpenGL.GL_LIST_INDEX,
PolygonMode = OpenGL.GL_POLYGON_MODE,
PolygonSmooth = OpenGL.GL_POLYGON_SMOOTH,
PolygonStipple = OpenGL.GL_POLYGON_STIPPLE,
EdgeFlag = OpenGL.GL_EDGE_FLAG,
CullFace = OpenGL.GL_CULL_FACE,
CullFaceMode = OpenGL.GL_CULL_FACE_MODE,
FrontFace = OpenGL.GL_FRONT_FACE,
Lighting = OpenGL.GL_LIGHTING,
LightModelLocalViewer = OpenGL.GL_LIGHT_MODEL_LOCAL_VIEWER,
LightModelTwoSide = OpenGL.GL_LIGHT_MODEL_TWO_SIDE,
LightModelAmbient = OpenGL.GL_LIGHT_MODEL_AMBIENT,
ShadeModel = OpenGL.GL_SHADE_MODEL,
ColorMaterialFace = OpenGL.GL_COLOR_MATERIAL_FACE,
ColorMaterialParameter = OpenGL.GL_COLOR_MATERIAL_PARAMETER,
ColorMaterial = OpenGL.GL_COLOR_MATERIAL,
Fog = OpenGL.GL_FOG,
FogIndex = OpenGL.GL_FOG_INDEX,
FogDensity = OpenGL.GL_FOG_DENSITY,
FogStart = OpenGL.GL_FOG_START,
FogEnd = OpenGL.GL_FOG_END,
FogMode = OpenGL.GL_FOG_MODE,
FogColor = OpenGL.GL_FOG_COLOR,
DepthRange = OpenGL.GL_DEPTH_RANGE,
DepthTest = OpenGL.GL_DEPTH_TEST,
DepthWritemask = OpenGL.GL_DEPTH_WRITEMASK,
DepthClearValue = OpenGL.GL_DEPTH_CLEAR_VALUE,
DepthFunc = OpenGL.GL_DEPTH_FUNC,
AccumClearValue = OpenGL.GL_ACCUM_CLEAR_VALUE,
StencilTest = OpenGL.GL_STENCIL_TEST,
StencilClearValue = OpenGL.GL_STENCIL_CLEAR_VALUE,
StencilFunc = OpenGL.GL_STENCIL_FUNC,
StencilValueMask = OpenGL.GL_STENCIL_VALUE_MASK,
StencilFail = OpenGL.GL_STENCIL_FAIL,
StencilPassDepthFail = OpenGL.GL_STENCIL_PASS_DEPTH_FAIL,
StencilPassDepthPass = OpenGL.GL_STENCIL_PASS_DEPTH_PASS,
StencilRef = OpenGL.GL_STENCIL_REF,
StencilWritemask = OpenGL.GL_STENCIL_WRITEMASK,
MatrixMode = OpenGL.GL_MATRIX_MODE,
Normalize = OpenGL.GL_NORMALIZE,
Viewport = OpenGL.GL_VIEWPORT,
ModelviewStackDepth = OpenGL.GL_MODELVIEW_STACK_DEPTH,
ProjectionStackDepth = OpenGL.GL_PROJECTION_STACK_DEPTH,
TextureStackDepth = OpenGL.GL_TEXTURE_STACK_DEPTH,
ModelviewMatix = OpenGL.GL_MODELVIEW_MATRIX,
ProjectionMatrix = OpenGL.GL_PROJECTION_MATRIX,
TextureMatrix = OpenGL.GL_TEXTURE_MATRIX,
AttribStackDepth = OpenGL.GL_ATTRIB_STACK_DEPTH,
ClientAttribStackDepth = OpenGL.GL_CLIENT_ATTRIB_STACK_DEPTH,
AlphaTest = OpenGL.GL_ALPHA_TEST,
AlphaTestFunc = OpenGL.GL_ALPHA_TEST_FUNC,
AlphaTestRef = OpenGL.GL_ALPHA_TEST_REF,
Dither = OpenGL.GL_DITHER,
BlendDst = OpenGL.GL_BLEND_DST,
BlendSrc = OpenGL.GL_BLEND_SRC,
Blend = OpenGL.GL_BLEND,
LogicOpMode = OpenGL.GL_LOGIC_OP_MODE,
IndexLogicOp = OpenGL.GL_INDEX_LOGIC_OP,
ColorLogicOp = OpenGL.GL_COLOR_LOGIC_OP,
AuxBuffers = OpenGL.GL_AUX_BUFFERS,
DrawBuffer = OpenGL.GL_DRAW_BUFFER,
ReadBuffer = OpenGL.GL_READ_BUFFER,
ScissorBox = OpenGL.GL_SCISSOR_BOX,
ScissorTest = OpenGL.GL_SCISSOR_TEST,
IndexClearValue = OpenGL.GL_INDEX_CLEAR_VALUE,
IndexWritemask = OpenGL.GL_INDEX_WRITEMASK,
ColorClearValue = OpenGL.GL_COLOR_CLEAR_VALUE,
ColorWritemask = OpenGL.GL_COLOR_WRITEMASK,
IndexMode = OpenGL.GL_INDEX_MODE,
RgbaMode = OpenGL.GL_RGBA_MODE,
DoubleBuffer = OpenGL.GL_DOUBLEBUFFER,
Stereo = OpenGL.GL_STEREO,
RenderMode = OpenGL.GL_RENDER_MODE,
PerspectiveCorrectionHint = OpenGL.GL_PERSPECTIVE_CORRECTION_HINT,
PointSmoothHint = OpenGL.GL_POINT_SMOOTH_HINT,
LineSmoothHint = OpenGL.GL_LINE_SMOOTH_HINT,
PolygonSmoothHint = OpenGL.GL_POLYGON_SMOOTH_HINT,
FogHint = OpenGL.GL_FOG_HINT,
TextureGenS = OpenGL.GL_TEXTURE_GEN_S,
TextureGenT = OpenGL.GL_TEXTURE_GEN_T,
TextureGenR = OpenGL.GL_TEXTURE_GEN_R,
TextureGenQ = OpenGL.GL_TEXTURE_GEN_Q,
PixelMapItoI = OpenGL.GL_PIXEL_MAP_I_TO_I,
PixelMapStoS = OpenGL.GL_PIXEL_MAP_S_TO_S,
PixelMapItoR = OpenGL.GL_PIXEL_MAP_I_TO_R,
PixelMapItoG = OpenGL.GL_PIXEL_MAP_I_TO_G,
PixelMapItoB = OpenGL.GL_PIXEL_MAP_I_TO_B,
PixelMapItoA = OpenGL.GL_PIXEL_MAP_I_TO_A,
PixelMapRtoR = OpenGL.GL_PIXEL_MAP_R_TO_R,
PixelMapGtoG = OpenGL.GL_PIXEL_MAP_G_TO_G,
PixelMapBtoB = OpenGL.GL_PIXEL_MAP_B_TO_B,
PixelMapAtoA = OpenGL.GL_PIXEL_MAP_A_TO_A,
PixelMapItoISize = OpenGL.GL_PIXEL_MAP_I_TO_I_SIZE,
PixelMapStoSSize = OpenGL.GL_PIXEL_MAP_S_TO_S_SIZE,
PixelMapItoRSize = OpenGL.GL_PIXEL_MAP_I_TO_R_SIZE,
PixelMapItoGSize = OpenGL.GL_PIXEL_MAP_I_TO_G_SIZE,
PixelMapItoBSize = OpenGL.GL_PIXEL_MAP_I_TO_B_SIZE,
PixelMapItoASize = OpenGL.GL_PIXEL_MAP_I_TO_A_SIZE,
PixelMapRtoRSize = OpenGL.GL_PIXEL_MAP_R_TO_R_SIZE,
PixelMapGtoGSize = OpenGL.GL_PIXEL_MAP_G_TO_G_SIZE,
PixelMapBtoBSize = OpenGL.GL_PIXEL_MAP_B_TO_B_SIZE,
PixelMapAtoASize = OpenGL.GL_PIXEL_MAP_A_TO_A_SIZE,
UnpackSwapBytes = OpenGL.GL_UNPACK_SWAP_BYTES,
LsbFirst = OpenGL.GL_UNPACK_LSB_FIRST,
UnpackRowLength = OpenGL.GL_UNPACK_ROW_LENGTH,
UnpackSkipRows = OpenGL.GL_UNPACK_SKIP_ROWS,
UnpackSkipPixels = OpenGL.GL_UNPACK_SKIP_PIXELS,
UnpackAlignment = OpenGL.GL_UNPACK_ALIGNMENT,
PackSwapBytes = OpenGL.GL_PACK_SWAP_BYTES,
PackLsbFirst = OpenGL.GL_PACK_LSB_FIRST,
PackRowLength = OpenGL.GL_PACK_ROW_LENGTH,
PackSkipRows = OpenGL.GL_PACK_SKIP_ROWS,
PackSkipPixels = OpenGL.GL_PACK_SKIP_PIXELS,
PackAlignment = OpenGL.GL_PACK_ALIGNMENT,
MapColor = OpenGL.GL_MAP_COLOR,
MapStencil = OpenGL.GL_MAP_STENCIL,
IndexShift = OpenGL.GL_INDEX_SHIFT,
IndexOffset = OpenGL.GL_INDEX_OFFSET,
RedScale = OpenGL.GL_RED_SCALE,
RedBias = OpenGL.GL_RED_BIAS,
ZoomX = OpenGL.GL_ZOOM_X,
ZoomY = OpenGL.GL_ZOOM_Y,
GreenScale = OpenGL.GL_GREEN_SCALE,
GreenBias = OpenGL.GL_GREEN_BIAS,
BlueScale = OpenGL.GL_BLUE_SCALE,
BlueBias = OpenGL.GL_BLUE_BIAS,
AlphaScale = OpenGL.GL_ALPHA_SCALE,
AlphaBias = OpenGL.GL_ALPHA_BIAS,
DepthScale = OpenGL.GL_DEPTH_SCALE,
DepthBias = OpenGL.GL_DEPTH_BIAS,
MapEvalOrder = OpenGL.GL_MAX_EVAL_ORDER,
MaxLights = OpenGL.GL_MAX_LIGHTS,
MaxClipPlanes = OpenGL.GL_MAX_CLIP_PLANES,
MaxTextureSize = OpenGL.GL_MAX_TEXTURE_SIZE,
MapPixelMapTable = OpenGL.GL_MAX_PIXEL_MAP_TABLE,
MaxAttribStackDepth = OpenGL.GL_MAX_ATTRIB_STACK_DEPTH,
MaxModelviewStackDepth = OpenGL.GL_MAX_MODELVIEW_STACK_DEPTH,
MaxNameStackDepth = OpenGL.GL_MAX_NAME_STACK_DEPTH,
MaxProjectionStackDepth = OpenGL.GL_MAX_PROJECTION_STACK_DEPTH,
MaxTextureStackDepth = OpenGL.GL_MAX_TEXTURE_STACK_DEPTH,
MaxViewportDims = OpenGL.GL_MAX_VIEWPORT_DIMS,
MaxClientAttribStackDepth = OpenGL.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH,
SubpixelBits = OpenGL.GL_SUBPIXEL_BITS,
IndexBits = OpenGL.GL_INDEX_BITS,
RedBits = OpenGL.GL_RED_BITS,
GreenBits = OpenGL.GL_GREEN_BITS,
BlueBits = OpenGL.GL_BLUE_BITS,
AlphaBits = OpenGL.GL_ALPHA_BITS,
DepthBits = OpenGL.GL_DEPTH_BITS,
StencilBits = OpenGL.GL_STENCIL_BITS,
AccumRedBits = OpenGL.GL_ACCUM_RED_BITS,
AccumGreenBits = OpenGL.GL_ACCUM_GREEN_BITS,
AccumBlueBits = OpenGL.GL_ACCUM_BLUE_BITS,
AccumAlphaBits = OpenGL.GL_ACCUM_ALPHA_BITS,
NameStackDepth = OpenGL.GL_NAME_STACK_DEPTH,
AutoNormal = OpenGL.GL_AUTO_NORMAL,
Map1Color4 = OpenGL.GL_MAP1_COLOR_4,
Map1Index = OpenGL.GL_MAP1_INDEX,
Map1Normal = OpenGL.GL_MAP1_NORMAL,
Map1TextureCoord1 = OpenGL.GL_MAP1_TEXTURE_COORD_1,
Map1TextureCoord2 = OpenGL.GL_MAP1_TEXTURE_COORD_2,
Map1TextureCoord3 = OpenGL.GL_MAP1_TEXTURE_COORD_3,
Map1TextureCoord4 = OpenGL.GL_MAP1_TEXTURE_COORD_4,
Map1Vertex3 = OpenGL.GL_MAP1_VERTEX_3,
Map1Vertex4 = OpenGL.GL_MAP1_VERTEX_4,
Map2Color4 = OpenGL.GL_MAP2_COLOR_4,
Map2Index = OpenGL.GL_MAP2_INDEX,
Map2Normal = OpenGL.GL_MAP2_NORMAL,
Map2TextureCoord1 = OpenGL.GL_MAP2_TEXTURE_COORD_1,
Map2TextureCoord2 = OpenGL.GL_MAP2_TEXTURE_COORD_2,
Map2TextureCoord3 = OpenGL.GL_MAP2_TEXTURE_COORD_3,
Map2TextureCoord4 = OpenGL.GL_MAP2_TEXTURE_COORD_4,
Map2Vertex3 = OpenGL.GL_MAP2_VERTEX_3,
Map2Vertex4 = OpenGL.GL_MAP2_VERTEX_4,
Map1GridDomain = OpenGL.GL_MAP1_GRID_DOMAIN,
Map1GridSegments = OpenGL.GL_MAP1_GRID_SEGMENTS,
Map2GridDomain = OpenGL.GL_MAP2_GRID_DOMAIN,
Map2GridSegments = OpenGL.GL_MAP2_GRID_SEGMENTS,
Texture1D = OpenGL.GL_TEXTURE_1D,
Texture2D = OpenGL.GL_TEXTURE_2D,
FeedbackBufferPointer = OpenGL.GL_FEEDBACK_BUFFER_POINTER,
FeedbackBufferSize = OpenGL.GL_FEEDBACK_BUFFER_SIZE,
FeedbackBufferType = OpenGL.GL_FEEDBACK_BUFFER_TYPE,
SelectionBufferPointer = OpenGL.GL_SELECTION_BUFFER_POINTER,
SelectionBufferSize = OpenGL.GL_SELECTION_BUFFER_SIZE
}
/// <summary>
/// The Front Face Mode.
/// </summary>
public enum FrontFaceMode : uint
{
ClockWise = OpenGL.GL_CW,
CounterClockWise = OpenGL.GL_CCW,
}
/// <summary>
/// The hint mode.
/// </summary>
public enum HintMode : uint
{
DontCare = OpenGL.GL_DONT_CARE,
Fastest = OpenGL.GL_FASTEST,
/// <summary>
/// The
/// </summary>
Nicest = OpenGL.GL_NICEST
}
/// <summary>
/// The hint target.
/// </summary>
public enum HintTarget : uint
{
PerspectiveCorrection = OpenGL.GL_PERSPECTIVE_CORRECTION_HINT,
PointSmooth = OpenGL.GL_POINT_SMOOTH_HINT,
LineSmooth = OpenGL.GL_LINE_SMOOTH_HINT,
PolygonSmooth = OpenGL.GL_POLYGON_SMOOTH_HINT,
Fog = OpenGL.GL_FOG_HINT
}
/// <summary>
/// LightName
/// </summary>
public enum LightName : uint
{
Light0 = OpenGL.GL_LIGHT0 ,
Light1 = OpenGL.GL_LIGHT1,
Light2 = OpenGL.GL_LIGHT2,
Light3 = OpenGL.GL_LIGHT3,
Light4 = OpenGL.GL_LIGHT4,
Light5 = OpenGL.GL_LIGHT5,
Light6 = OpenGL.GL_LIGHT6,
Light7 = OpenGL.GL_LIGHT7
}
/// <summary>
/// LightParameter
/// </summary>
public enum LightParameter : uint
{
Ambient = OpenGL.GL_AMBIENT,
Diffuse = OpenGL.GL_DIFFUSE,
Specular = OpenGL.GL_SPECULAR,
Position = OpenGL.GL_POSITION,
SpotDirection = OpenGL.GL_SPOT_DIRECTION,
SpotExponent = OpenGL.GL_SPOT_EXPONENT,
SpotCutoff = OpenGL.GL_SPOT_CUTOFF,
ConstantAttenuatio = OpenGL.GL_CONSTANT_ATTENUATION,
LinearAttenuation = OpenGL.GL_LINEAR_ATTENUATION,
QuadraticAttenuation = OpenGL.GL_QUADRATIC_ATTENUATION
}
/// <summary>
/// The Light Model Parameter.
/// </summary>
public enum LightModelParameter : uint
{
LocalViewer = OpenGL.GL_LIGHT_MODEL_LOCAL_VIEWER,
TwoSide = OpenGL.GL_LIGHT_MODEL_TWO_SIDE,
Ambient = OpenGL.GL_LIGHT_MODEL_AMBIENT
}
/// <summary>
/// The Logic Op
/// </summary>
public enum LogicOp : uint
{
Clear = OpenGL.GL_CLEAR,
And = OpenGL.GL_AND,
AndReverse = OpenGL.GL_AND_REVERSE,
Copy = OpenGL.GL_COPY,
AndInverted = OpenGL.GL_AND_INVERTED,
NoOp= OpenGL.GL_NOOP,
XOr = OpenGL.GL_XOR,
Or = OpenGL.GL_OR,
NOr= OpenGL.GL_NOR,
Equiv = OpenGL.GL_EQUIV,
Invert = OpenGL.GL_INVERT,
OrReverse = OpenGL.GL_OR_REVERSE,
CopyInverted = OpenGL.GL_COPY_INVERTED,
OrInverted = OpenGL.GL_OR_INVERTED,
NAnd= OpenGL.GL_NAND,
Set = OpenGL.GL_SET,
}
/// <summary>
/// The matrix mode.
/// </summary>
public enum MatrixMode : uint
{
Modelview = OpenGL.GL_MODELVIEW,
Projection = OpenGL.GL_PROJECTION,
Texture = OpenGL.GL_TEXTURE
}
/// <summary>
/// The pixel transfer parameter name
/// </summary>
public enum PixelTransferParameterName : uint
{
MapColor = OpenGL.GL_MAP_COLOR,
MapStencil = OpenGL.GL_MAP_STENCIL,
IndexShift = OpenGL.GL_INDEX_SHIFT,
IndexOffset = OpenGL.GL_INDEX_OFFSET,
RedScale = OpenGL.GL_RED_SCALE,
RedBias = OpenGL.GL_RED_BIAS,
ZoomX = OpenGL.GL_ZOOM_X,
ZoomY = OpenGL.GL_ZOOM_Y,
GreenScale = OpenGL.GL_GREEN_SCALE,
GreenBias = OpenGL.GL_GREEN_BIAS,
BlueScale = OpenGL.GL_BLUE_SCALE,
BlueBias = OpenGL.GL_BLUE_BIAS,
AlphaScale = OpenGL.GL_ALPHA_SCALE,
AlphaBias = OpenGL.GL_ALPHA_BIAS,
DepthScale = OpenGL.GL_DEPTH_SCALE,
DepthBias = OpenGL.GL_DEPTH_BIAS
}
/// <summary>
/// The Polygon mode.
/// </summary>
public enum PolygonMode : uint
{
/// <summary>
/// Render as points.
/// </summary>
Points = OpenGL.GL_POINT,
/// <summary>
/// Render as lines.
/// </summary>
Lines = OpenGL.GL_LINE,
/// <summary>
/// Render as filled.
/// </summary>
Filled = OpenGL.GL_FILL
}
/// <summary>
/// Rendering Mode
/// </summary>
public enum RenderingMode: uint
{
Render = OpenGL.GL_RENDER,
Feedback = OpenGL.GL_FEEDBACK,
Select = OpenGL.GL_SELECT
}
/// <summary>
/// ShadingModel
/// </summary>
public enum ShadeModel : uint
{
Flat = OpenGL.GL_FLAT,
Smooth = OpenGL.GL_SMOOTH
}
/// <summary>
/// The stencil function
/// </summary>
public enum StencilFunction : uint
{
Never = OpenGL.GL_NEVER,
Less = OpenGL.GL_LESS,
Equal = OpenGL.GL_EQUAL,
LessThanOrEqual = OpenGL.GL_LEQUAL,
Great = OpenGL.GL_GREATER,
NotEqual = OpenGL.GL_NOTEQUAL,
GreaterThanOrEqual = OpenGL.GL_GEQUAL,
Always = OpenGL.GL_ALWAYS,
}
/// <summary>
/// The stencil operation.
/// </summary>
public enum StencilOperation : uint
{
Keep = OpenGL.GL_KEEP,
Replace = OpenGL.GL_REPLACE,
Increase = OpenGL.GL_INCR,
Decrease = OpenGL.GL_DECR,
Zero = OpenGL.GL_ZERO,
IncreaseWrap = OpenGL.GL_INCR_WRAP,
DecreaseWrap = OpenGL.GL_DECR_WRAP,
Invert = OpenGL.GL_INVERT
}
/// <summary>
/// GetTextureParameter
/// </summary>
public enum TextureParameter : uint
{
TextureWidth = OpenGL.GL_TEXTURE_WIDTH,
TextureHeight = OpenGL.GL_TEXTURE_HEIGHT,
TextureInternalFormat = OpenGL.GL_TEXTURE_INTERNAL_FORMAT,
TextureBorderColor = OpenGL.GL_TEXTURE_BORDER_COLOR,
TextureBorder = OpenGL.GL_TEXTURE_BORDER
}
/// <summary>
/// Texture target.
/// </summary>
public enum TextureTarget : uint
{
Texture1D = OpenGL.GL_TEXTURE_1D,
Texture2D = OpenGL.GL_TEXTURE_2D,
Texture3D = OpenGL.GL_TEXTURE_3D
}
}

@ -0,0 +1,318 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpGL
{
/// <summary>
/// A FontOutline entry contains the details of a font face.
/// </summary>
internal class FontOutlineEntry
{
/// <summary>
/// Gets or sets the HDC.
/// </summary>
/// <value>
/// The HDC.
/// </value>
public IntPtr HDC
{
get;
set;
}
/// <summary>
/// Gets or sets the HRC.
/// </summary>
/// <value>
/// The HRC.
/// </value>
public IntPtr HRC
{
get;
set;
}
/// <summary>
/// Gets or sets the name of the face.
/// </summary>
/// <value>
/// The name of the face.
/// </value>
public string FaceName
{
get;
set;
}
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public int Height
{
get;
set;
}
/// <summary>
/// Gets or sets the list base.
/// </summary>
/// <value>
/// The list base.
/// </value>
public uint ListBase
{
get;
set;
}
/// <summary>
/// Gets or sets the list count.
/// </summary>
/// <value>
/// The list count.
/// </value>
public uint ListCount
{
get;
set;
}
/// <summary>
/// Gets or sets the deviation.
/// </summary>
/// <value>
/// The deviation.
/// </value>
public float Deviation
{
get;
set;
}
/// <summary>
/// Gets or sets the extrusion.
/// </summary>
/// <value>
/// The extrusion.
/// </value>
public float Extrusion
{
get;
set;
}
/// <summary>
/// Gets or sets the font outline format.
/// </summary>
/// <value>
/// The font outline format.
/// </value>
public FontOutlineFormat FontOutlineFormat
{
get;
set;
}
/// <summary>
/// Gets or sets the glyph metrics.
/// </summary>
/// <value>
/// The glyph metrics.
/// </value>
public GLYPHMETRICSFLOAT[] GlyphMetrics
{
get; set;
}
}
/// <summary>
/// The font outline format.
/// </summary>
public enum FontOutlineFormat
{
/// <summary>
/// Render using lines.
/// </summary>
Lines = 0,
/// <summary>
/// Render using polygons.
/// </summary>
Polygons = 1
}
/// <summary>
/// The GLYPHMETRICSFLOAT structure contains information about the placement and orientation of a glyph in a character cell.
/// </summary>
public struct GLYPHMETRICSFLOAT
{
/// <summary>
/// Specifies the width of the smallest rectangle (the glyph's black box) that completely encloses the glyph..
/// </summary>
public float gmfBlackBoxX;
/// <summary>
/// Specifies the height of the smallest rectangle (the glyph's black box) that completely encloses the glyph.
/// </summary>
public float gmfBlackBoxY;
/// <summary>
/// Specifies the x and y coordinates of the upper-left corner of the smallest rectangle that completely encloses the glyph.
/// </summary>
public POINTFLOAT gmfptGlyphOrigin;
/// <summary>
/// Specifies the horizontal distance from the origin of the current character cell to the origin of the next character cell.
/// </summary>
public float gmfCellIncX;
/// <summary>
/// Specifies the vertical distance from the origin of the current character cell to the origin of the next character cell.
/// </summary>
public float gmfCellIncY;
}
/// <summary>
/// Point structure used in Win32 interop.
/// </summary>
public struct POINTFLOAT
{
/// <summary>
/// The x coord value.
/// </summary>
public float x;
/// <summary>
/// The y coord value.
/// </summary>
public float y;
}
/// <summary>
/// This class wraps the functionality of the wglUseFontOutlines function to
/// allow straightforward rendering of text.
/// </summary>
public class FontOutlines
{
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 space for the glyph metrics.
var glyphMetrics = new GLYPHMETRICSFLOAT[255];
// Create the font bitmaps.
bool result = Win32.wglUseFontOutlines(gl.RenderContextProvider.DeviceContextHandle, 0, 255, listBase,
deviation, extrusion, (int)fontOutlineFormat, glyphMetrics);
// 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,
GlyphMetrics = glyphMetrics
};
// Add the font bitmap entry to the internal list.
fontOutlineEntries.Add(foe);
return foe;
}
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="gl">The gl.</param>
/// <param name="faceName">Name of the face.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="deviation">The deviation.</param>
/// <param name="extrusion">The extrusion.</param>
/// <param name="text">The text.</param>
public void DrawText(OpenGL gl, string faceName, float fontSize,
float deviation, float extrusion, string text)
{
// Pass to the glyph metrics version of the function.
GLYPHMETRICSFLOAT[] glyphMetrics;
DrawText(gl, faceName, fontSize, deviation, extrusion, text, out glyphMetrics);
}
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="gl">The gl.</param>
/// <param name="faceName">Name of the face.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="deviation">The deviation.</param>
/// <param name="extrusion">The extrusion.</param>
/// <param name="text">The text.</param>
/// <param name="glyphMetrics"> </param>
public void DrawText(OpenGL gl, string faceName, float fontSize, float deviation, float extrusion, string text, out GLYPHMETRICSFLOAT[] glyphMetrics)
{
// Get the font size in pixels.
var fontHeight = (int)(fontSize * (16.0f / 12.0f));
// Do we have a font bitmap entry for this OpenGL instance and face name?
var result = (from fbe in fontOutlineEntries
where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
&& fbe.HRC == gl.RenderContextProvider.RenderContextHandle
&& String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0
&& fbe.Height == fontHeight
&& fbe.Deviation == deviation
&& fbe.Extrusion == extrusion
select fbe).ToList();
// Get the FBE or null.
var fontOutlineEntry = result.FirstOrDefault();
// If we don't have the FBE, we must create it.
if (fontOutlineEntry == null)
fontOutlineEntry = CreateFontOutlineEntry(gl, faceName, fontHeight, deviation, extrusion, FontOutlineFormat.Polygons);
// Set the list base.
gl.ListBase(fontOutlineEntry.ListBase);
// Create an array of lists for the glyphs.
var lists = text.Select(c => (byte) c).ToArray();
// Call the lists for the string.
gl.CallLists(lists.Length, lists);
gl.Flush();
// Return the glyph metrics used.
glyphMetrics = fontOutlineEntry.GlyphMetrics;
}
/// <summary>
/// The cache of font outline entries.
/// </summary>
private readonly List<FontOutlineEntry> fontOutlineEntries = new List<FontOutlineEntry>();
}
}

@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpGL
{
/// <summary>
/// A FontBitmap entry contains the details of a font face.
/// </summary>
internal class FontBitmapEntry
{
public IntPtr HDC
{
get;
set;
}
public IntPtr HRC
{
get;
set;
}
public string FaceName
{
get;
set;
}
public int Height
{
get;
set;
}
public uint ListBase
{
get;
set;
}
public uint ListCount
{
get;
set;
}
}
/// <summary>
/// This class wraps the functionality of the wglUseFontBitmaps function to
/// allow straightforward rendering of text.
/// </summary>
public class FontBitmaps
{
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_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.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.
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;
}
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="gl">The gl.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="r">The r.</param>
/// <param name="g">The g.</param>
/// <param name="b">The b.</param>
/// <param name="faceName">Name of the face.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="text">The text.</param>
public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
{
// Get the font size in pixels.
var fontHeight = (int)(fontSize * (16.0f / 12.0f));
// Do we have a font bitmap entry for this OpenGL instance and face name?
var result = (from fbe in fontBitmapEntries
where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
&& fbe.HRC == gl.RenderContextProvider.RenderContextHandle
&& String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0
&& fbe.Height == fontHeight
select fbe).ToList();
// Get the FBE or null.
var fontBitmapEntry = result.FirstOrDefault();
// If we don't have the FBE, we must create it.
if (fontBitmapEntry == null)
fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);
double width = gl.RenderContextProvider.Width;
double height = gl.RenderContextProvider.Height;
// Create the appropriate projection matrix.
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.PushMatrix();
gl.LoadIdentity();
int[] viewport = new int[4];
gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
gl.Ortho(0, width, 0, height, -1, 1);
// Create the appropriate modelview matrix.
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.PushMatrix();
gl.LoadIdentity();
gl.Color(r, g, b);
gl.RasterPos(x, y);
gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
gl.Color(r, g, b);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.Disable(OpenGL.GL_DEPTH_TEST);
gl.RasterPos(x, y);
// Set the list base.
gl.ListBase(fontBitmapEntry.ListBase);
// Create an array of lists for the glyphs.
var lists = text.Select(c => (byte) c).ToArray();
// Call the lists for the string.
gl.CallLists(lists.Length, lists);
gl.Flush();
// Reset the list bit.
gl.PopAttrib();
// Pop the modelview.
gl.PopMatrix();
// back to the projection and pop it, then back to the model view.
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.PopMatrix();
gl.MatrixMode(OpenGL.GL_MODELVIEW);
}
/// <summary>
/// Cache of font bitmap enties.
/// </summary>
private readonly List<FontBitmapEntry> fontBitmapEntries = new List<FontBitmapEntry>();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpGL.Version;
namespace SharpGL.RenderContextProviders
{
public class DIBSectionRenderContextProvider : RenderContextProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="DIBSectionRenderContextProvider"/> class.
/// </summary>
public DIBSectionRenderContextProvider()
{
// We can layer GDI drawing on top of open gl drawing.
GDIDrawingEnabled = true;
}
/// <summary>
/// Creates the render context provider. Must also create the OpenGL extensions.
/// </summary>
/// <param name="openGLVersion">The desired OpenGL version.</param>
/// <param name="gl">The OpenGL context.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitDepth">The bit depth.</param>
/// <param name="parameter">The extra parameter.</param>
/// <returns></returns>
public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter)
{
// Call the base.
base.Create(openGLVersion, gl, width, height, bitDepth, parameter)