Пример #1
0
bool Engine::renderFrame(bool allocateIfNeeded)
{
    if (!mEgl.isReadyToRender(allocateIfNeeded))
        return false;

	if (!initUI())
	{
		LOGW("Could not initialize UI - assets may be missing!");
		ANativeActivity_finish(mApp->activity);
		return false;
	}

	resizeIfNeeded();

	// set up viewport
	glViewport((GLint)0, (GLint)0, 
		(GLsizei)(mEgl.getWidth()), (GLsizei)(mEgl.getHeight()));

	// clear buffers as necessary
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// do some game rendering here
	// ...
	
	// start rendering bitfont text overlaid here.
	NVBFTextRenderPrep();

	m_ui->Render();

	// done rendering overlaid text.
	NVBFTextRenderDone();

	if (mForceRender > 0)
		mForceRender--;

    mEgl.swap();

    return true;
}
Пример #2
0
bool Engine::renderFrame(bool allocateIfNeeded)
{
    if (!mEgl.isReadyToRender(allocateIfNeeded))
        return false;

	if (!initUI())
	{
		LOGW("Could not initialize UI - assets may be missing!");
		ANativeActivity_finish(mApp->activity);
		return false;
	}

    // We've gotten this far, so EGL is ready for us.  Have we loaded our assets?
    // Note that we cannot use APP_STATUS_GLES_LOADED to imply that EGL is
    // ready to render.  We can have a valid context with all GLES resources loaded
    // into it but no surface and thus the context not bound.  These are semi-
    // independent states.
    if (!mGlobeApp)
	{
        if (!allocateIfNeeded)
            return false;

		mGlobeApp = new GlobeApp;
	}

	if (!mGlobeApp->isInitialized())
    {
        if (!allocateIfNeeded)
            return false;

		// If we are initializing and we have a new, known size, set that
		// before the init
        resizeIfNeeded();

        if (!mGlobeApp->init())
            return false;
    }

	resizeIfNeeded();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mGlobeApp->render((float)mTimeVal);

	if (m_clockText)
	{
		NVBFTextRenderPrep();
		NVBFTextRender(m_clockText);
		NVBFTextRenderDone();

		int mins = mTimeVal / 60;
		float secs = (float)mTimeVal - mins*60;
		char str[32];
		sprintf(str, "%03d:%05.2f", mins, secs);
		NVBFTextSetString(m_clockText, str);
	}

	// Render UI if needed
	if (m_uiModeTextures[mCurrentMode])
	{
		int w = mEgl.getWidth();
		int h = mEgl.getHeight();
		mUIHalfSize = 300;
		mUICenterX = w/2;
		mUICenterY = h/2;
		NvDrawRect::setScreenResolution(w, h);
		static const float s_white[4] = {1.0f, 1.0f, 1.0f, 0.7f};
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		mDrawRect->draw(m_uiModeTextures[mCurrentMode], 
			mUICenterX - mUIHalfSize, mUICenterY - mUIHalfSize,
			mUICenterX + mUIHalfSize, mUICenterY + mUIHalfSize, s_white);
		glDisable(GL_BLEND);
	}

	if (mForceRender > 0)
		mForceRender--;

    mEgl.swap();

    // A debug printout every 256 frames so we can see when we're
    // actively rendering and swapping
    if (!(mSwapCount++ & 0x00ff))
    {
		DEBUG("Swap count is %d", mSwapCount);
    }

    return true;
}