Example #1
0
nResult n2dFontImpl::PrintFont(n2dGraphics2D* pGraphic, ncTStr str, nFloat x, nFloat y, nFloat scale, n2dTexture* pTexture)
{
	if (!m_pFTLib)
	{
		return NatErr_IllegalState;
	}

	nBool shouldEnd;
	auto pUsingProgram = m_pRenderer->GetShaderWrapper()->GetCurrentProgram();
	auto pFontProgram = m_pRenderer->GetShaderWrapper()->GetFontProgram();
	if (pGraphic->IsRendering())
	{
		shouldEnd = false;
		pGraphic->Flush();
	}
	else
	{
		shouldEnd = true;
		pGraphic->Begin();
	}
	m_pRenderer->PushMVPMat();
	m_pRenderer->InitMVPMat();
	auto window = m_pRenderer->GetEngine()->GetWindow();
	m_pRenderer->SubmitProjMat(natTransform::ortho(0.0f, static_cast<nFloat>(window->GetWidth()), 0.0f, static_cast<nFloat>(window->GetHeight())));
	auto scope = make_scope([shouldEnd, pGraphic, pUsingProgram, this]
	{
		if (shouldEnd)
		{
			pGraphic->End();
		}
		else
		{
			pGraphic->Flush();
		}

		m_pRenderer->PopMVPMat();
		pUsingProgram->Use();
	});

	pFontProgram->Use();
	GLint textureID = 0;
	pFontProgram->GetUniformReference(1)->SetValue(1, &textureID);
	textureID = 1;
	pFontProgram->GetUniformReference(2)->SetValue(1, &textureID);
	GLint useTexture = GL_TRUE;
	pFontProgram->GetUniformReference(3)->SetValue(1, &useTexture);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, pTexture->GetTextureID());

	return PrintFontImpl(pGraphic, str, x, y, scale);
}
Example #2
0
nResult n2dFontImpl::PrintFont(n2dGraphics2D* pGraphic, ncTStr str, nFloat x, nFloat y, nFloat scale, natVec3<> const& color)
{
	if (!m_pFTLib)
	{
		return NatErr_IllegalState;
	}

	nBool shouldEnd;
	auto pUsingProgram = m_pRenderer->GetShaderWrapper()->GetCurrentProgram();
	auto pFontProgram = m_pRenderer->GetShaderWrapper()->GetFontProgram();
	if (pGraphic->IsRendering())
	{
		shouldEnd = false;
		pGraphic->Flush();
	}
	else
	{
		shouldEnd = true;
		pGraphic->Begin();
	}
	m_pRenderer->PushMVPMat();
	m_pRenderer->InitMVPMat();
	auto window = m_pRenderer->GetEngine()->GetWindow();
	m_pRenderer->SubmitProjMat(natTransform::ortho(0.0f, static_cast<nFloat>(window->GetWidth()), 0.0f, static_cast<nFloat>(window->GetHeight())));
	auto scope = make_scope([shouldEnd, pGraphic, pUsingProgram, this]
	{
		if (shouldEnd)
		{
			pGraphic->End();
		}
		else
		{
			pGraphic->Flush();
		}

		m_pRenderer->PopMVPMat();
		pUsingProgram->Use();
	});

	pFontProgram->Use();
	GLint textureID = 0;
	GLint useTexture = GL_FALSE;
	//auto p = static_cast<n2dShaderProgramImpl::UniformReferenceImpl*>(pFontProgram->GetUniformReference(_T("textColor")));
	//m_pRenderer->GetEngine()->GetLogger().LogMsg(_T("textColor: {0}, type: {1}"), p->GetLocation(), static_cast<nuInt>(p->GetType()));
	pFontProgram->GetUniformReference(1)->SetValue(1, &textureID);
	pFontProgram->GetUniformReference(3)->SetValue(1, &useTexture);
	pFontProgram->GetUniformReference(4)->SetValue(1, &color);

	return PrintFontImpl(pGraphic, str, x, y, scale);
}
static void continuation_test(int continuations)
{
    int i;
    for(i = 0; i < continuations; ++i)
    {
        continuation_block_t continuation = {.block = continuation_0};
        int c = open_continuation(NULL, 0, continuation_release, 0);
        assert(c >= 0);
        printf("Continuation [%d] opened\n", c);
        mark_continuation(c);
        continuation.arg = (void*)make_scope(c);
        assert(add_continuation(c, &continuation, 1) == 0);
    }
    continuation_player();
}