Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aferust/bindbc-nanovg
Dynamic and static bindings to nanovg, compatible with -betterC, @nogc, and nothrow.
https://github.com/aferust/bindbc-nanovg
Last synced: 2 months ago
JSON representation
Dynamic and static bindings to nanovg, compatible with -betterC, @nogc, and nothrow.
- Host: GitHub
- URL: https://github.com/aferust/bindbc-nanovg
- Owner: aferust
- Created: 2020-04-19T11:29:41.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-20T11:26:03.000Z (almost 5 years ago)
- Last Synced: 2024-08-04T01:05:06.507Z (6 months ago)
- Language: D
- Size: 9.77 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-d - bindbc-nanovg
README
## Dynamic and static bindings to nanovg, compatible with -betterC, @nogc, and nothrow.
- based on [DerelictNANOVG](https://github.com/aldocd4/DerelictNANOVG)
- use [arsd:official:nanovega](https://code.dlang.org/packages/arsd-official%3Ananovega) when druntime is available instead.An example with glfw
```d
import core.stdc.stdio;import bindbc.nanovg;
import bindbc.glfw;
import bindbc.opengl;@nogc nothrow:
int initNanovg(){
version(BindNanovg_Static){
// todo: some stuff
}else{
NanovgSupport ret = loadNanovg();
if(ret == NanovgSupport.noLibrary){
printf("noLibrary \n".ptr);
return 1;
}}
return 0;
}bool exit;
extern (C) void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
exit = true;
}extern (C) int main()
{
initNanovg();exit = false;
GLFWSupport glfw = loadGLFW();
printf("GLFW: %d", glfw);
if(!glfwInit()){
return -1;
}if(!glfwInit()){
return -1;
}enum glVersion = 32;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, glVersion / 10);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, glVersion % 10);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, false);
glfwWindowHint(GLFW_SAMPLES, 4);
auto window = glfwCreateWindow(1024, 768, "D yellow rect with nanovg", null, null);
//writeln(window is null);
glfwMakeContextCurrent(window);
glfwSwapInterval(false);
glfwSetKeyCallback(window, &key_callback);// You have a context, you can load opengl
GLSupport gl = loadOpenGL();
//writeln("Opengl: ", gl);auto vg = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_DEBUG);
while(!exit)
{
glViewport(0, 0, 1024, 768);
glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);nvgBeginFrame(vg, 1024, 768, 1);
{
nvgBeginPath(vg);
nvgFillColor(vg, nvgRGBA(255,192,0,255));
nvgRect(vg, 200, 200, 300, 300);
nvgFill(vg);
}
nvgEndFrame(vg);
glfwSwapBuffers(window);
glfwPollEvents();
}nvgDeleteGL3(vg);
return 0;
}
```