bug of overflow due to IntPtr solved
This commit is contained in:
@@ -15,10 +15,11 @@ namespace StgSharp.Graphics
|
||||
|
||||
public unsafe class Form
|
||||
{
|
||||
internal IntPtr windowPtr;
|
||||
internal formInfo info;
|
||||
|
||||
internal long windowID; //pointer to the form
|
||||
internal formInfo info = new formInfo() ;
|
||||
internal IntPtr shader;
|
||||
internal LinkedList<Pool> allControl = new LinkedList<Pool>();
|
||||
internal LinkedList<Pool> allControl;
|
||||
|
||||
public vec2d Size
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace StgSharp
|
||||
else
|
||||
{
|
||||
windowPtr = glIO.internalGLcreateWindow(
|
||||
width, height, tittle, monitor, (IntPtr)share.windowPtr);
|
||||
width, height, tittle, monitor, (IntPtr)share.windowID);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace StgSharp
|
||||
{
|
||||
Form form = new Form();
|
||||
form.Size = new vec2d(width, height);
|
||||
form.windowPtr = windowPtr;
|
||||
form.windowID = (long)windowPtr;
|
||||
return form;
|
||||
}
|
||||
}
|
||||
@@ -61,41 +61,40 @@ namespace StgSharp
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static unsafe Form GLcreateWindow(int width, int height, string tittle, IntPtr monitor, IntPtr share)
|
||||
{
|
||||
Form form = new Form();
|
||||
form.Size = new vec2d(width, height);
|
||||
|
||||
byte[] tittleCharArray = System.Text.Encoding.UTF8.GetBytes(tittle);
|
||||
IntPtr windowPtr = glIO.internalGLcreateWindow(width, height, tittleCharArray, monitor, share);
|
||||
|
||||
|
||||
form.info.name = tittleCharArray;
|
||||
form.windowPtr = windowPtr;
|
||||
Console.WriteLine(windowPtr);
|
||||
long windowPtr = (long)glIO.internalGLcreateWindow
|
||||
(width, height, tittleCharArray, monitor, share);
|
||||
|
||||
if ((int)windowPtr == -1 || (int)windowPtr == -2)
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
throw new Exception("Cannot create the form!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Form form = new Form();
|
||||
form.Size = new vec2d(width, height);
|
||||
form.windowID = windowPtr;
|
||||
return form;
|
||||
}
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe void GLmakeContexCurrent(Form form)
|
||||
{
|
||||
glIO.internalGLmakeContextCurrent((IntPtr)form.windowPtr);
|
||||
glIO.internalGLmakeContextCurrent((IntPtr)form.windowID);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe bool GLwindowShouldClose(Form form)
|
||||
{
|
||||
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowPtr);
|
||||
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowID);
|
||||
return a != 0;
|
||||
}
|
||||
|
||||
|
||||
public static unsafe void GLswapBuffers(Form form)
|
||||
{
|
||||
glIO.internalGLswapBuffers((IntPtr)form.windowPtr);
|
||||
glIO.internalGLswapBuffers((IntPtr)form.windowID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,16 +8,8 @@ namespace StgSharp
|
||||
{
|
||||
internal static GraphicIOPack glIO;
|
||||
private static bool isGLSet = false;
|
||||
|
||||
/// <summary>
|
||||
/// Init an instance of OpenGL program,
|
||||
/// This method should be called before other
|
||||
/// graphic methods, after LoadGL method.
|
||||
/// </summary>
|
||||
public static void InitGL()
|
||||
{
|
||||
internalIO.InternalInitGL();
|
||||
}
|
||||
private static bool isGLADset = false;
|
||||
private static bool isGLready = false;
|
||||
|
||||
/// <summary>
|
||||
/// Load OpenGL API to StgSharp core programm,
|
||||
@@ -27,7 +19,7 @@ namespace StgSharp
|
||||
/// <exception cref="Exception">If run this method twice, will throw exception</exception>
|
||||
public static unsafe void LoadGL()
|
||||
{
|
||||
if (!isGLSet)
|
||||
if (!isGLADset)
|
||||
{
|
||||
glIO = internalIO.InternalInitGraphicApi();
|
||||
}
|
||||
@@ -37,6 +29,27 @@ namespace StgSharp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Init an instance of OpenGL program,
|
||||
/// This method should be called before other
|
||||
/// graphic methods, after LoadGL method.
|
||||
/// </summary>
|
||||
public static void InitGL()
|
||||
{
|
||||
if (!isGLSet)
|
||||
{
|
||||
internalIO.InternalInitGL();
|
||||
isGLready = isGLSet && isGLADset;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Do not init GL twice");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Attach GLFW API to GLAD,
|
||||
/// this method should be called after LoadGL
|
||||
@@ -45,32 +58,27 @@ namespace StgSharp
|
||||
/// <exception cref="Exception">The accident that program cannot attach GLFW to GLAD</exception>
|
||||
public static unsafe void InitGLAD()
|
||||
{
|
||||
int a = internalIO.InternalInitGLAD();
|
||||
if (a!=0)
|
||||
|
||||
if (!isGLADset)
|
||||
{
|
||||
throw new Exception("Cannot attach GLFW to GLAD!");
|
||||
int a = internalIO.InternalInitGLAD();
|
||||
if (a != 0)
|
||||
{
|
||||
throw new Exception("Cannot attach GLFW to GLAD!");
|
||||
}
|
||||
else
|
||||
{
|
||||
isGLready = isGLSet && isGLADset;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
throw new Exception("Do not init GLAD twice.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static byte[] loadShaderCodeStr(string str)
|
||||
{
|
||||
byte[] cahrStr;
|
||||
try
|
||||
{
|
||||
cahrStr = System.Text.Encoding.ASCII.GetBytes(str);
|
||||
return cahrStr;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user