1- using Silk . NET . Core . Contexts ;
2- using Silk . NET . Core . Loader ;
3- using Silk . NET . Maths ;
1+ //using Silk.NET.Core.Contexts;
2+ //using Silk.NET.Core.Loader;
3+ //using TerraFX.Interop.Windows;
4+ //using static TerraFX.Interop.Windows.Windows;
45using Spout . Interop ;
56using System ;
67using System . Collections . Generic ;
78using System . Diagnostics ;
9+ using System . Diagnostics . Eventing . Reader ;
810using System . Drawing ;
911using System . Drawing . Imaging ;
1012using System . Drawing . Text ;
1719using System . Threading . Tasks ;
1820using System . Windows . Forms ;
1921using System . Xml . Linq ;
20- using TerraFX . Interop . DirectX ;
21- using TerraFX . Interop . Windows ;
2222using static System . Net . Mime . MediaTypeNames ;
2323using static System . Runtime . InteropServices . JavaScript . JSType ;
2424using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
25- using static TerraFX . Interop . Windows . Windows ;
25+
2626
2727
2828
2929namespace StreamStartingTimer {
3030
31- public static class OpenGLHandler {
31+ /* public static class OpenGLHandler {
3232 static bool GLInitialised = false;
3333 static IntPtr Handle = Process.GetCurrentProcess().MainWindowHandle;
34+ static HDC dc;
35+ static HGLRC gctx;
36+ static Silk.NET.OpenGL.GL gl;
3437
3538 public static void InitGL() {
36- if ( GLInitialised ) return ;
39+ if (GLInitialised) return;
3740 GLInitialised = true;
3841 SetOpenglPixelFormat((HWND)Handle);
39- var dc = GetDC ( ( HWND ) Handle ) ;
40- var gctx = wglCreateContext ( dc ) ;
42+ dc = GetDC((HWND)Handle);
43+ gctx = wglCreateContext(dc);
4144 wglMakeCurrent(dc, gctx);
4245 ReleaseDC((HWND)Handle, dc);
43- var gl = new Silk . NET . OpenGL . GL ( new WindowsGlNativeContext ( ) ) ;
46+ gl = new Silk.NET.OpenGL.GL(new WindowsGlNativeContext());
47+ }
48+
49+ public static void CloseGL() {
50+ if (!GLInitialised) return;
51+ gl.Dispose();
4452 }
53+
4554 static unsafe void SetOpenglPixelFormat(HWND window) {
4655 // Contains desired pixel format characteristics
4756 PIXELFORMATDESCRIPTOR pfd = new();
@@ -114,6 +123,21 @@ public unsafe bool TryGetProcAddress(string proc, out nint addr, int? slot = nul
114123 return false;
115124 }
116125 }
126+ }*/
127+
128+ public static class OpenGLHandler {
129+ static bool GLInitialised = false ;
130+ static OpenTK . GLControl . GLControl GL ;
131+ public static void InitGL ( ) {
132+ if ( GLInitialised ) { return ; }
133+ GL = new OpenTK . GLControl . GLControl ( ) ;
134+ GL . MakeCurrent ( ) ;
135+ GLInitialised = true ;
136+ }
137+ public static void CloseGL ( ) {
138+ if ( ! GLInitialised ) { return ; }
139+ GL . Dispose ( ) ;
140+ }
117141 }
118142
119143 public class ClockSpout : IDisposable {
@@ -142,11 +166,12 @@ public void GetImageFromTime(int SecondsToGo, nint pClockTexture) {
142166 ColonFix = 0 ;
143167
144168 for ( int Digit = 0 ; Digit < 5 ; Digit ++ ) {
145- if ( Digit == 2 ) {
169+ if ( ! Shared . CurSettings . ShowLeadingZero && ( Digit == 0 ) && ( CurTime [ Digit ] == '0' ) ) {
170+ CurDigit = 11 ;
171+ } else if ( Digit == 2 ) {
146172 ColonFix = ColonWidth - NumberWidth ;
147173 CurDigit = 10 ;
148- } else { }
149- if ( CurTime [ Digit ] == ' ' ) {
174+ } else if ( CurTime [ Digit ] == ' ' ) {
150175 CurDigit = 11 ;
151176 } else {
152177 CurDigit = CurTime [ Digit ] - 48 ;
@@ -164,7 +189,6 @@ public void GetImageFromTime(int SecondsToGo, nint pClockTexture) {
164189
165190 }
166191 }
167- //return ClockTexture;
168192 }
169193
170194 public ClockSpout ( string FontDir ) {
@@ -188,17 +212,10 @@ public ClockSpout(string FontDir) {
188212 ClockArraySize = ( ClockWidth * NumberHeight ) * 4 ;
189213
190214 pClockTexture = Marshal . AllocHGlobal ( ClockArraySize ) ;
191-
192- OpenGLHandler . InitGL ( ) ;
193- spoutSender = new SpoutSender ( ) ;
194- spoutSender . CreateSender ( Shared . CurSettings . SpoutName , ( uint ) ClockWidth , ( uint ) NumberHeight , 0 ) ;
195- }
196-
197- public unsafe async void UpdateTexture ( ) {
198-
199215 Int32 [ ] TempLine = new Int32 [ ColonWidth ] ;
200216 UInt32 TempPixel ;
201217
218+ // Add the : to the clock texture now. It never needs copying again
202219 for ( int y = 0 ; y < NumberHeight ; y ++ ) {
203220 for ( int x = 0 ; x < ColonWidth ; x ++ ) {
204221 TempPixel = ( UInt32 ) ClockFont [ 10 ] . GetPixel ( x , y ) . ToArgb ( ) ;
@@ -208,6 +225,13 @@ public unsafe async void UpdateTexture() {
208225 Marshal . Copy ( TempLine , 0 , pClockTexture + ( y * ClockWidth * 4 ) + ( ( ( 2 * NumberWidth ) ) * 4 ) , ColonWidth ) ;
209226 }
210227
228+ OpenGLHandler . InitGL ( ) ;
229+ spoutSender = new SpoutSender ( ) ;
230+ spoutSender . CreateSender ( Shared . CurSettings . SpoutName , ( uint ) ClockWidth , ( uint ) NumberHeight , 0 ) ;
231+ }
232+
233+ public unsafe void UpdateTexture ( ) {
234+
211235 int i = 0 ;
212236 GetImageFromTime ( Shared . frmClock . SecondsToGo , pClockTexture ) ;
213237 Console . WriteLine ( $ "Sending (i = { i } )") ;
@@ -219,7 +243,8 @@ public unsafe async void UpdateTexture() {
219243 }
220244
221245 public void Dispose ( ) {
222- if ( spoutSender != null ) {
246+ if ( spoutSender != null ) {
247+ spoutSender . ReleaseSender ( ) ;
223248 spoutSender . Dispose ( ) ;
224249 Marshal . FreeHGlobal ( pClockTexture ) ;
225250 }
0 commit comments