int main(int argc, char **argv) { if (!glfwInit()) { printf("Failed to init GLFW."); return -1; } glfwSetErrorCallback(errorcb); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1); GLFWwindow* window = glfwCreateWindow(1024, 768, "scanner", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwSetCharCallback(window, charevent); glfwSetCursorPosCallback(window, cursorpos); glfwSetMouseButtonCallback(window, mousebutton); glfwSetScrollCallback(window, scrollevent); glfwMakeContextCurrent(window); glfwSwapInterval(1); // vsync glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { printf("Could not init glew.\n"); return -1; } glGetError(); // GLEW generates GL error because it calls glGetString(GL_EXTENSIONS). struct NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS); if (vg == NULL) { printf("Could not init nanovg.\n"); return -1; } UIcontext *uictx = uiCreateContext(4096, 1 << 20); uiMakeCurrent(uictx); uiSetHandler(ui_handler); uiInit(vg, "oui-blendish/DejaVuSans.ttf", "oui-blendish/blender_icons16.png"); gui_init(vg); glfwSetTime(0); while (!glfwWindowShouldClose(window)) { double mx, my; glfwGetCursorPos(window, &mx, &my); int winWidth, winHeight; glfwGetWindowSize(window, &winWidth, &winHeight); int fbWidth, fbHeight; glfwGetFramebufferSize(window, &fbWidth, &fbHeight); float pxRatio = (float)fbWidth / (float)winWidth; gui_frame(vg, winWidth, winHeight, pxRatio, glfwGetTime()); glfwSwapBuffers(window); glfwPollEvents(); } gui_quit(vg); uiDestroyContext(uictx); nvgDeleteGL2(vg); glfwTerminate(); return 0; }
NanoVG::Context::~Context() { if ( m_context ) { nvgDeleteGL2( m_context ); } }
NVGRenderer::~NVGRenderer() { if (m_context) { nvgDeleteGL2(m_context); m_context = nullptr; } }
QNanoPainter::~QNanoPainter() { if (m_nvgContext) { #ifdef QT_OPENGL_ES_2 nvgDeleteGLES2(m_nvgContext); #else nvgDeleteGL2(m_nvgContext); #endif } qDeleteAll(m_dataCache); }
virtual void releaseGLObjects( osg::State* state=0 ) const { if ( state && state->getGraphicsContext() ) { osg::GraphicsContext* gc = state->getGraphicsContext(); if ( gc->makeCurrent() ) { NanoVGDrawable* constMe = const_cast<NanoVGDrawable*>(this); if ( constMe->_vg ) { constMe->deinitializeGL( state ); nvgDeleteGL2( constMe->_vg ); } gc->releaseContext(); } } }
int main() { GLFWwindow* window; struct DemoData data; struct NVGcontext* vg = NULL; struct PerfGraph fps; double prevt = 0; if (!glfwInit()) { printf("Failed to init GLFW."); return -1; } initGraph(&fps, GRAPH_RENDER_FPS, "Frame Time"); glfwSetErrorCallback(errorcb); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); #ifdef DEMO_MSAA glfwWindowHint(GLFW_SAMPLES, 4); #endif window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL); // window = glfwCreateWindow(1000, 600, "NanoVG", glfwGetPrimaryMonitor(), NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwMakeContextCurrent(window); #ifdef NANOVG_GLEW if(glewInit() != GLEW_OK) { printf("Could not init glew.\n"); return -1; } #endif #ifdef DEMO_MSAA vg = nvgCreateGL2(512, 512, 0); #else vg = nvgCreateGL2(512, 512, NVG_ANTIALIAS); #endif if (vg == NULL) { printf("Could not init nanovg.\n"); return -1; } if (loadDemoData(vg, &data) == -1) return -1; glfwSwapInterval(0); glfwSetTime(0); prevt = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double mx, my, t, dt; int winWidth, winHeight; int fbWidth, fbHeight; float pxRatio; t = glfwGetTime(); dt = t - prevt; prevt = t; updateGraph(&fps, dt); glfwGetCursorPos(window, &mx, &my); glfwGetWindowSize(window, &winWidth, &winHeight); glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Calculate pixel ration for hi-dpi devices. pxRatio = (float)fbWidth / (float)winWidth; // Update and render glViewport(0, 0, fbWidth, fbHeight); if (premult) glClearColor(0,0,0,0); else glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); nvgBeginFrame(vg, winWidth, winHeight, pxRatio, premult ? NVG_PREMULTIPLIED_ALPHA : NVG_STRAIGHT_ALPHA); renderDemo(vg, mx,my, winWidth,winHeight, t, blowup, &data); renderGraph(vg, 5,5, &fps); nvgEndFrame(vg); if (screenshot) { screenshot = 0; saveScreenShot(fbWidth, fbHeight, premult, "dump.png"); } glfwSwapBuffers(window); glfwPollEvents(); } freeDemoData(vg, &data); nvgDeleteGL2(vg); glfwTerminate(); return 0; }
int main() { GLFWwindow* window; struct DemoData data; struct NVGcontext* vg = NULL; struct FPScounter fps; double prevt = 0; if (!glfwInit()) { printf("Failed to init GLFW."); return -1; } initFPS(&fps); glfwSetErrorCallback(errorcb); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwMakeContextCurrent(window); #ifdef NANOVG_GLEW if(glewInit() != GLEW_OK) { printf("Could not init glew.\n"); return -1; } #endif vg = nvgCreateGL2(512,512); if (vg == NULL) { printf("Could not init nanovg.\n"); return -1; } if (loadDemoData(vg, &data) == -1) return -1; glfwSwapInterval(0); glfwSetTime(0); prevt = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double mx, my, t, dt; int width, height; t = glfwGetTime(); dt = t - prevt; prevt = t; updateFPS(&fps, dt); glfwGetCursorPos(window, &mx, &my); glfwGetFramebufferSize(window, &width, &height); // Update and render glViewport(0, 0, width, height); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glColor4ub(255,255,255,255); nvgBeginFrame(vg, width, height); renderDemo(vg, mx,my, width,height, t, blowup, &data); renderFPS(vg, 5,5, &fps); glEnable(GL_DEPTH_TEST); glfwSwapBuffers(window); glfwPollEvents(); } freeDemoData(vg, &data); nvgDeleteGL2(vg); glfwTerminate(); return 0; }
int main() { GLFWwindow* window; NVGcontext *vg; if(!glfwInit()) { fprintf(stderr, "Failed to start glfw\n"); return -1; } //Set OpenGL Revision glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); //Create Window window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL); if (!window) { fprintf(stderr, "Failed to make window\n"); glfwTerminate(); return -1; } //Setup Context glfwSetKeyCallback(window, key); glfwSetMouseButtonCallback(window, mouse_event); glfwSetCursorPosCallback(window, mouse_hover); glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { fprintf(stderr, "Failed to start GLEW\n"); return -1; } vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG); nvgCreateFont(vg, "sans", "Roboto-Regular.ttf"); nvgCreateFont(vg, "icons", "entypo.ttf"); glfwSwapInterval(0); glfwSetTime(0); long prevt = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double mx, my; int winWidth, winHeight; int fbWidth, fbHeight; float pxRatio; glfwGetCursorPos(window, &mx, &my); glfwGetWindowSize(window, &winWidth, &winHeight); glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Calculate pixel ration for hi-dpi devices. pxRatio = (float)fbWidth / (float)winWidth; // Update and render glViewport(0, 0, fbWidth, fbHeight); //glClearColor(0x06/255.0, 0x27/255.0, 0x37/255.0, 1.0f); glClearColor(0, 0, 0, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); //#define M_PI 3.14159 nvgBeginFrame(vg, winWidth, winHeight, pxRatio); //float in[100] = {0.0, 0.0, 0.5, 0.2, 0.3, 0.7,0.9,0.8,0.0,1.0}; //drawHarmonicPlot(vg, in, 100, 0,0,winWidth, winHeight); //drawPowButton(vg, 0,0,winWidth, winHeight); drawPanDial(vg, "100", 0.4, 0, 0, winWidth, winHeight); //nvgBeginPath(vg); //float cx = 30.0, cy = 30.0, h = 80; //nvgArc(vg, cx, cy, 0.4*h, 0, 1.0/2.0*M_PI, 1); //nvgArc(vg, cx, cy, 0.2*h, 1.0/2.0*M_PI, 0, 2); //nvgClosePath(vg); //nvgFillColor(vg, nvgRGBA(0x11,0x45,0x75,255)); //nvgFill(vg); nvgEndFrame(vg); // nvgBeginFrame(vg, winWidth, winHeight, pxRatio); // // //viewReverb(vg, 0,0, winWidth, winHeight); // viewModule(vg, "afilter", 0,0,winWidth, winHeight); // //viewLFO(vg, 0,0, winWidth, winHeight); // //viewFilterEnv(vg, 0,0, winWidth, winHeight); // //y x y x y x y x y x // //float in[10] = {0.0, 0.0, 0.5, 0.2, 0.3, 0.7,-0.9,0.8,0.0,1.0}; // //drawEnvEdit(vg, in, 5, 3, 0, 0, winWidth, winHeight); // //#if 0 // dial_t dial = {60, 0, 0, 100, "label"}; // renderDial(vg, dial); // drawButton(vg, "banana", 100, 25, 100, 50); // drawOptButton(vg, "opt", 200, 25, 100, 50); // drawButtonGrid(vg, 4,4, 300, 0, 100, 100); // drawAltDial(vg, 400, 0, 100, 100); // drawGrid(vg, 8, 8, 500, 0, 200, 200); // drawSin(vg, 500, 0, 200, 200); //#endif // // nvgEndFrame(vg); glfwSwapBuffers(window); glfwPollEvents(); } nvgDeleteGL2(vg); glfwTerminate(); return 0; }