Files
stgsharp/源代码/StgSharpGraphic/code/StgSharpGraphic.c
T

211 lines
7.7 KiB
C

// StgShqrpGraphic.cpp : 定义 DLL 的导出函数。
//
#include "framework.h"
#include "glad/gl.h"
#include <stdio.h>
#include "StgSharpGraphic.h"
extern char* infolog[512] = { 0 };
GladGLContext* currentContext;
glfwContext* glfw;
void printShaderCode(char* const* code)
{
printf(*code);
}
SSGC_API glfwContext* _cdecl initGL(int majorVersion, int minorVersion, glfwContext* ptr)
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVersion);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfw = ptr;
#pragma region loadapi
glfw->Init = glfwInit;
glfw->Terminate = glfwTerminate;
glfw->InitHint = glfwInitHint;
glfw->GetVersion = glfwGetVersion;
glfw->GetVersionString = glfwGetVersionString;
glfw->GetError = glfwGetError;
glfw->SetErrorCallback = glfwSetErrorCallback;
glfw->GetMonitors = glfwGetMonitors;
glfw->GetPrimaryMonitor = glfwGetPrimaryMonitor;
glfw->GetMonitorPos = glfwGetMonitorPos;
glfw->GetMonitorWorkarea = glfwGetMonitorWorkarea;
glfw->GetMonitorPhysicalSize = glfwGetMonitorPhysicalSize;
glfw->GetMonitorContentScale = glfwGetMonitorContentScale;
glfw->GetMonitorName = glfwGetMonitorName;
glfw->SetMonitorUserPointer = glfwSetMonitorUserPointer;
glfw->GetMonitorUserPointer = glfwGetMonitorUserPointer;
glfw->SetMonitorCallback = glfwSetMonitorCallback;
glfw->GetVideoModes = glfwGetVideoModes;
glfw->GetVideoMode = glfwGetVideoMode;
glfw->SetGamma = glfwSetGamma;
glfw->GetGammaRamp = glfwGetGammaRamp;
glfw->SetGammaRamp = glfwSetGammaRamp;
glfw->DefaultWindowHints = glfwDefaultWindowHints;
glfw->WindowHint = glfwWindowHint;
glfw->WindowHintString = glfwWindowHintString;
glfw->CreateWindowProc = glfwCreateWindow;
glfw->DestroyWindow = glfwDestroyWindow;
glfw->WindowShouldClose = glfwWindowShouldClose;
glfw->SetWindowShouldClose = glfwSetWindowShouldClose;
glfw->SetWindowTitle = glfwSetWindowTitle;
glfw->SetWindowIcon = glfwSetWindowIcon;
glfw->GetWindowPos = glfwGetWindowPos;
glfw->SetWindowPos = glfwSetWindowPos;
glfw->GetWindowSize = glfwGetWindowSize;
glfw->SetWindowSizeLimits = glfwSetWindowSizeLimits;
glfw->SetWindowAspectRatio = glfwSetWindowAspectRatio;
glfw->SetWindowSize = glfwSetWindowSize;
glfw->GetFramebufferSize = glfwGetFramebufferSize;
glfw->GetWindowFrameSize = glfwGetWindowFrameSize;
glfw->GetWindowContentScale = glfwGetWindowContentScale;
glfw->GetWindowOpacity = glfwGetWindowOpacity;
glfw->SetWindowOpacity = glfwSetWindowOpacity;
glfw->IconifyWindow = glfwIconifyWindow;
glfw->RestoreWindow = glfwRestoreWindow;
glfw->MaximizeWindow = glfwMaximizeWindow;
glfw->ShowWindow = glfwShowWindow;
glfw->HideWindow = glfwHideWindow;
glfw->FocusWindow = glfwFocusWindow;
glfw->RequestWindowAttention = glfwRequestWindowAttention;
glfw->GetWindowMonitor = glfwGetWindowMonitor;
glfw->SetWindowMonitor = glfwSetWindowMonitor;
glfw->GetWindowAttrib = glfwGetWindowAttrib;
glfw->SetWindowAttrib = glfwSetWindowAttrib;
glfw->SetWindowUserPointer = glfwSetWindowUserPointer;
glfw->GetWindowUserPointer = glfwGetWindowUserPointer;
glfw->SetWindowPosCallback = glfwSetWindowPosCallback;
glfw->SetWindowSizeCallback = glfwSetWindowSizeCallback;
glfw->SetWindowCloseCallback = glfwSetWindowCloseCallback;
glfw->SetWindowRefreshCallback = glfwSetWindowRefreshCallback;
glfw->SetWindowFocusCallback = glfwSetWindowFocusCallback;
glfw->SetWindowIconifyCallback = glfwSetWindowIconifyCallback;
glfw->SetWindowMaximizeCallback = glfwSetWindowMaximizeCallback;
glfw->SetFramebufferSizeCallback = glfwSetFramebufferSizeCallback;
glfw->SetWindowContentScaleCallback = glfwSetWindowContentScaleCallback;
glfw->PollEvents = glfwPollEvents;
glfw->WaitEvents = glfwWaitEvents;
glfw->WaitEventsTimeout = glfwWaitEventsTimeout;
glfw->PostEmptyEvent = glfwPostEmptyEvent;
glfw->GetInputMode = glfwGetInputMode;
glfw->SetInputMode = glfwSetInputMode;
glfw->RawMouseMotionSupported = glfwRawMouseMotionSupported;
glfw->GetKeyName = glfwGetKeyName;
glfw->GetKeyScancode = glfwGetKeyScancode;
glfw->GetKey = glfwGetKey;
glfw->GetMouseButton = glfwGetMouseButton;
glfw->GetCursorPos = glfwGetCursorPos;
glfw->SetCursorPos = glfwSetCursorPos;
glfw->CreateCursor = glfwCreateCursor;
glfw->CreateStandardCursor = glfwCreateStandardCursor;
glfw->DestroyCursor = glfwDestroyCursor;
glfw->SetCursor = glfwSetCursor;
glfw->SetKeyCallback = glfwSetKeyCallback;
glfw->SetCharCallback = glfwSetCharCallback;
glfw->SetCharModsCallback = glfwSetCharModsCallback;
glfw->SetMouseButtonCallback = glfwSetMouseButtonCallback;
glfw->SetCursorPosCallback = glfwSetCursorPosCallback;
glfw->SetCursorEnterCallback = glfwSetCursorEnterCallback;
glfw->SetScrollCallback = glfwSetScrollCallback;
glfw->SetDropCallback = glfwSetDropCallback;
glfw->JoystickPresent = glfwJoystickPresent;
glfw->GetJoystickAxes = glfwGetJoystickAxes;
glfw->GetJoystickButtons = glfwGetJoystickButtons;
glfw->GetJoystickHats = glfwGetJoystickHats;
glfw->GetJoystickName = glfwGetJoystickName;
glfw->GetJoystickGUID = glfwGetJoystickGUID;
glfw->SetJoystickUserPointer = glfwSetJoystickUserPointer;
glfw->GetJoystickUserPointer = glfwGetJoystickUserPointer;
glfw->JoystickIsGamepad = glfwJoystickIsGamepad;
glfw->SetJoystickCallback = glfwSetJoystickCallback;
glfw->UpdateGamepadMappings = glfwUpdateGamepadMappings;
glfw->GetGamepadName = glfwGetGamepadName;
glfw->GetGamepadState = glfwGetGamepadState;
glfw->SetClipboardString = glfwSetClipboardString;
glfw->GetClipboardString = glfwGetClipboardString;
glfw->GetTime = glfwGetTime;
glfw->SetTime = glfwSetTime;
glfw->GetTimerValue = glfwGetTimerValue;
glfw->GetTimerFrequency = glfwGetTimerFrequency;
glfw->MakeContextCurrent = glfwMakeContextCurrent;
glfw->GetCurrentContext = glfwGetCurrentContext;
glfw->SwapBuffers = glfwSwapBuffers;
glfw->SwapInterval = glfwSwapInterval;
glfw->ExtensionSupported = glfwExtensionSupported;
glfw->GetProcAddress = glfwGetProcAddress;
glfw->VulkanSupported = glfwVulkanSupported;
glfw->GetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions;
#if defined(VK_VERSION_1_0)
glfw->GetInstanceProcAddress = glfwGetInstanceProcAddress;
glfw->GetPhysicalDevicePresentationSupport = glfwGetPhysicalDevicePresentationSupport;
glfw->CreateWindowSurface = glfwCreateWindowSurface;
#endif
#pragma endregion
return glfw;
}
SSGC_API unsigned int loadShaderCode(char* const shaderCode, GLint shadertype)
{
unsigned int shader = currentContext->CreateShader(shadertype);
currentContext->ShaderSource(shader, 1, &shaderCode, NULL);
currentContext->CompileShader(shader);
int success;
currentContext->GetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success)
{
currentContext->GetShaderInfoLog(shader, 512, NULL, infolog);
return 0;
}
else
{
return shader;
}
}
SSGC_API unsigned int linkShaderProgram(GLuint shaderProgram)
{
currentContext->LinkProgram(shaderProgram);
int success;
currentContext->GetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success)
{
currentContext->GetProgramInfoLog(shaderProgram, 512, NULL, infolog);
return 0;
}
else
{
return shaderProgram;
}
}
char* _cdecl readLog()
{
infolog[511] = '\0';
return &infolog;
}
void setCurrentGLContxt(GladGLContext* contextPtr)
{
currentContext = contextPtr;
}