using StgSharp.Control;
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace StgSharp
{
public static unsafe partial class Graphic
{
///
/// Creates a form and its associated context.
///
/// Required width
/// Required width
/// Tittle of the window
///
///
/// The instance of created form
///
public static unsafe Form GLcreateWindow(int width, int height, byte[] tittle, IntPtr monitor, Form share)
{
IntPtr windowPtr;
if (share == null)
{
windowPtr = glIO.internalGLcreateWindow(
width, height, tittle, monitor, (IntPtr)0);
}
else
{
windowPtr = glIO.internalGLcreateWindow(
width, height, tittle, monitor, (IntPtr)share.windowID);
}
if ((int)windowPtr == -1 || (int)windowPtr == -2)
{
throw new Exception("Cannot create window instance!");
}
else
{
Form form = new Form();
form.Size = new Vec2d(width, height);
form.windowID = (long)windowPtr;
return form;
}
}
///
/// Creates a window and its associated context.
///
/// Required width
/// Required width
/// Tittle of the window
///
///
/// The handle of created window
///
public static unsafe Form GLcreateWindow(int width, int height, string tittle, IntPtr monitor, IntPtr share)
{
byte[] tittleCharArray = System.Text.Encoding.UTF8.GetBytes(tittle);
long windowPtr = (long)glIO.internalGLcreateWindow
(width, height, tittleCharArray, monitor, share);
if ((int)windowPtr == -1 || (int)windowPtr == -2)
{
throw new Exception("Cannot create the form!");
}
else
{
Form form = new Form();
form.Size = new Vec2d(width, height);
form.windowID = windowPtr;
return form;
}
}
public static unsafe void GLmakeContexCurrent(Form form)
{
glIO.internalGLmakeContextCurrent((IntPtr)form.windowID);
}
public static unsafe bool GLwindowShouldClose(Form form)
{
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowID);
return a != 0;
}
public static unsafe void GLswapBuffers(Form form)
{
glIO.internalGLswapBuffers((IntPtr)form.windowID);
}
}
}