Exemplo n.º 1
0
void Material::update(NVGcontext* vg, double time)
{
	if (m_framebufferObject == nullptr)
		return;

	if (m_initialized == true && m_animate == false)
		return;

	float circle_size = float((cos(time) + 1.0) * 128.0);

	nvgluBindFramebuffer(m_framebufferObject);
	glViewport(0, 0, m_width, m_height);

	// Any alpha other than zero will fail for some FBO reason
	glClearColor(m_color.r, m_color.g, m_color.b, 0.0f);
	
	glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	nvgBeginFrame(vg, m_width, m_height, /*pixelRatio*/1.0f);

		nvgBeginPath(vg);

		if (m_animate)
			nvgCircle(vg, float(m_width) * 0.5f, float(m_height) * 0.5f, circle_size);
		
		if(m_type == 2)
			nvgFillColor(vg, nvgRGBA(220, 45, 0, 200));
		else if(m_type == 1)
			nvgFillColor(vg, nvgRGBA(0, 220, 45, 200));
		else nvgFillColor(vg, nvgRGBA(10, 145, 200, 200)); 

		nvgFill(vg);

		if(m_type == 2)
		{
			nvgFontFace(vg, "sans");

			nvgFontSize(vg, 80.0f);
			nvgTextAlign(vg, NVG_ALIGN_CENTER);
			nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
			nvgText(vg, float(m_width) * 0.5f, (float(m_height) * 0.5f) + 20.0f, "Add Object", nullptr);
		}

	nvgEndFrame(vg);
	nvgluBindFramebuffer(NULL);

	m_initialized = true;
}
Exemplo n.º 2
0
void renderPattern(NVGcontext* vg, NVGLUframebuffer* fb, float t, float pxRatio)
{
	int winWidth, winHeight;
	int fboWidth, fboHeight;
	int pw, ph, x, y;
	float s = 20.0f;
	float sr = (cosf(t)+1)*0.5f;
	float r = s * 0.6f * (0.2f + 0.8f * sr);

	if (fb == NULL) return;

	nvgImageSize(vg, fb->image, &fboWidth, &fboHeight);
	winWidth = (int)(fboWidth / pxRatio);
	winHeight = (int)(fboHeight / pxRatio);

	// Draw some stuff to an FBO as a test
	nvgluBindFramebuffer(fb);
	glViewport(0, 0, fboWidth, fboHeight);
	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
	nvgBeginFrame(vg, winWidth, winHeight, pxRatio);

	pw = (int)ceilf(winWidth / s);
	ph = (int)ceilf(winHeight / s);

	nvgBeginPath(vg);
	for (y = 0; y < ph; y++) {
		for (x = 0; x < pw; x++) {
			float cx = (x+0.5f) * s;
			float cy = (y+0.5f) * s;
			nvgCircle(vg, cx,cy, r);
		}
	}
	nvgFillColor(vg, nvgRGBA(220,160,0,200));
	nvgFill(vg);

	nvgEndFrame(vg);
	nvgluBindFramebuffer(NULL);
}
Exemplo n.º 3
0
JNIEXPORT void Java_firststep_internal_NVG_bindFramebuffer(JNIEnv *e, jclass c, jlong fb) {
	nvgluBindFramebuffer((NVGLUframebuffer*)fb);
}