Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region --- License --- |
| 2 | /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos |
||
| 3 | * See license.txt for license info |
||
| 4 | */ |
||
| 5 | #endregion |
||
| 6 | |||
| 7 | using System; |
||
| 8 | using System.Collections.Generic; |
||
| 9 | using System.Text; |
||
| 10 | using System.Runtime.InteropServices; |
||
| 11 | |||
| 12 | using OpenTK.Graphics.OpenGL; |
||
| 13 | |||
| 14 | namespace OpenTK.Graphics |
||
| 15 | { |
||
| 16 | /// <summary> |
||
| 17 | /// Provides text printing through OpenGL 1.5 vertex buffer objects. |
||
| 18 | /// </summary> |
||
| 19 | [Obsolete] |
||
| 20 | class VboTextPrinter : ITextPrinterImplementation |
||
| 21 | { |
||
| 22 | static int allocated_handles; |
||
| 23 | static int vector2_size = Marshal.SizeOf(new Vector2()); |
||
| 24 | |||
| 25 | #region --- IPrinter Members --- |
||
| 26 | |||
| 27 | public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count) |
||
| 28 | { |
||
| 29 | VboTextHandle handle = new VboTextHandle(++allocated_handles); |
||
| 30 | |||
| 31 | GL.GenBuffers(1, out handle.vbo_id); |
||
| 32 | GL.BindBuffer(BufferTarget.ArrayBuffer, handle.vbo_id); |
||
| 33 | GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * vector2_size), vertices, |
||
| 34 | BufferUsageHint.StaticDraw); |
||
| 35 | GL.BindBuffer(BufferTarget.ArrayBuffer, 0); |
||
| 36 | |||
| 37 | GL.GenBuffers(1, out handle.ebo_id); |
||
| 38 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.ebo_id); |
||
| 39 | GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, |
||
| 40 | BufferUsageHint.StaticDraw); |
||
| 41 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); |
||
| 42 | |||
| 43 | handle.element_count = indices.Length; |
||
| 44 | return handle; |
||
| 45 | } |
||
| 46 | |||
| 47 | public void Draw(TextHandle handle) |
||
| 48 | { |
||
| 49 | VboTextHandle vbo = (VboTextHandle)handle; |
||
| 50 | |||
| 51 | //GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit); |
||
| 52 | |||
| 53 | //GL.EnableClientState(EnableCap.TextureCoordArray); |
||
| 54 | GL.EnableClientState(EnableCap.VertexArray); |
||
| 55 | |||
| 56 | GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.vbo_id); |
||
| 57 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo.ebo_id); |
||
| 58 | |||
| 59 | GL.TexCoordPointer(2, TexCoordPointerType.Float, vector2_size, (IntPtr)vector2_size); |
||
| 60 | GL.VertexPointer(2, VertexPointerType.Float, vector2_size, IntPtr.Zero); |
||
| 61 | |||
| 62 | GL.DrawElements(BeginMode.Triangles, vbo.element_count, DrawElementsType.UnsignedShort, IntPtr.Zero); |
||
| 63 | //GL.DrawArrays(BeginMode.LineLoop, 0, vbo.element_count); |
||
| 64 | |||
| 65 | GL.BindBuffer(BufferTarget.ArrayBuffer, 0); |
||
| 66 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); |
||
| 67 | |||
| 68 | GL.DisableClientState(EnableCap.VertexArray); |
||
| 69 | //GL.DisableClientState(EnableCap.TextureCoordArray); |
||
| 70 | |||
| 71 | //GL.PopClientAttrib(); |
||
| 72 | } |
||
| 73 | |||
| 74 | public void Draw(Vector2[] vertices, ushort[] indices, int index_count) |
||
| 75 | { |
||
| 76 | throw new NotImplementedException(); |
||
| 77 | } |
||
| 78 | |||
| 79 | #endregion |
||
| 80 | } |
||
| 81 | |||
| 82 | #region class VboTextHandle : TextHandle |
||
| 83 | |||
| 84 | /// <summary> |
||
| 85 | /// Contains the necessary information to print text through the VboTextPrinter implementation. |
||
| 86 | /// </summary> |
||
| 87 | [Obsolete] |
||
| 88 | class VboTextHandle : TextHandle |
||
| 89 | { |
||
| 90 | public VboTextHandle(int handle) : base(handle) { } |
||
| 91 | |||
| 92 | internal int vbo_id; // vertex buffer object id. |
||
| 93 | internal int ebo_id; // index buffer object id. |
||
| 94 | internal int element_count; // Number of elements in the ebo. |
||
| 95 | |||
| 96 | public override string ToString() |
||
| 97 | { |
||
| 98 | return String.Format("TextHandle (vbo): {0} ({1} element(s), vbo id: {2}, ebo id: {3}", |
||
| 99 | Handle, element_count / 6, vbo_id, ebo_id); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | #endregion |
||
| 104 | } |