Example #1
1
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;
}
 virtual void drawImplementation( osg::RenderInfo& renderInfo ) const
 {
     unsigned int contextID = renderInfo.getContextID();
     if ( !_initialized )
     {
         NanoVGDrawable* constMe = const_cast<NanoVGDrawable*>(this);
         glewInit();
         constMe->_vg = nvgCreateGL2( NVG_ANTIALIAS|NVG_STENCIL_STROKES|NVG_DEBUG );
         if ( !constMe->_vg )
         {
             OSG_NOTICE << "[NanoVGDrawable] Failed to create VG context" << std::endl;
             return;
         }
         
         constMe->initializeGL( renderInfo.getState() );
         constMe->_activeContextID = contextID;
         constMe->_initialized = true;
     }
     else if ( _vg && contextID==_activeContextID )
     {
         osg::State* state = renderInfo.getState();
         state->disableAllVertexArrays();
         state->disableTexCoordPointer( 0 );
         
         nvgBeginFrame( _vg, _width, _height, 1.0f );
         updateGL( state );
         nvgEndFrame( _vg );
     }
 }
Example #3
0
NanoVG::Context::Context( int flags )
{
    m_context = nvgCreateGL2( flags );
    if ( !m_context )
    {
        kvsMessageError( "Cannot create a NanoVG context." );
        return;
    }
}
Example #4
0
int main(int argc, char **argv)
{
	glfwInit();

	GLFWwindow *window = glfwCreateWindow(1440, 750, "Desert golfer", NULL, NULL);
	glfwMakeContextCurrent(window);
	glewInit();

	Scene scene;

	ViewInfo viewInfo;
	int width, height, comp;
	stbi_uc *pixels = stbi_load("test5.png", &width, &height, &comp, 3);

	viewInfo.viewData = pixels;
	viewInfo.viewWidth = width;
	viewInfo.viewHeight = height;
	viewInfo.screenWidth = 1334;
	viewInfo.screenHeight = 750;

	VisionScene *vision = visionReadScene(&scene, &viewInfo);

	scene.ballPos.x = 473.0f;
	scene.ballPos.y = 505.0f;
	scene.ballRadius = 5.0f;

	scene.goalMin.x = 1220.0f;
	scene.goalMin.y = 526.0f;
	scene.goalMax.x = 1256.0f;
	scene.goalMax.y = 550.0f;

	PhysicsScene *physics = physicsCreateScene(&scene);

	NVGcontext *nvg = nvgCreateGL2(0);

	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();

		physicsUpdate(physics, 50);

		int windowWidth, windowHeight;
		glfwGetWindowSize(window, &windowWidth, &windowHeight);

		glClearColor(0x64/255.0f, 0x95/255.0f, 0xED/255.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT);

		nvgBeginFrame(nvg, windowWidth, windowHeight, 1.0f);
		physicsRender(physics, nvg);
		nvgEndFrame(nvg);

		glfwSwapBuffers(window);
	}

	return 0;
}
Example #5
0
NVG_::NVG_():
	isInitialized_(false),
	vg_(nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG),nvgDeleteGL2){

	if (vg_ == NULL) {
		printf("Could not init nanovg.\n");
		return;
	}
	isInitialized_ = true;
}
Example #6
0
    //Initialize the renderer
    bool init() {
      m_vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);

      m_font = nvgCreateFont(m_vg, "sans", "Roboto-Regular.ttf");
      nvgCreateFont(m_vg, "sans-bold", "Roboto-Bold.ttf");
      nvgCreateFont(m_vg, "sans-light", "Roboto-Light.ttf");

      m_inited = true;
      return true;
    }
Example #7
0
QNanoPainter::QNanoPainter()
    : m_nvgContext(nullptr)
    , m_textAlign(QNanoPainter::ALIGN_LEFT)
    , m_textBaseline(QNanoPainter::BASELINE_ALPHABETIC)
    , m_devicePixelRatio(1.0)
    , m_fontSet(false)
    , m_pixelAlign(QNanoPainter::PIXEL_ALIGN_NONE)
    , m_pixelAlignText(QNanoPainter::PIXEL_ALIGN_NONE)
{
    // Initialize NanoVG for correct GL version
    // TODO: Allow to enable/disable NVG_DEBUG, possibly some own general debug define
#ifdef QT_OPENGL_ES_2
    m_nvgContext = nvgCreateGLES2(NVG_ANTIALIAS | NVG_DEBUG);
#else
    m_nvgContext = nvgCreateGL2(NVG_ANTIALIAS | NVG_DEBUG);
#endif

    Q_ASSERT_X(m_nvgContext, "QNanoPainter::QNanoPainter", "Could not init nanovg!");


}
Example #8
0
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;
}
Example #9
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;
}
Example #10
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;
}
Example #11
0
		NVGRenderer::NVGRenderer() : m_inFrame(false)
		{
			m_context = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
		}