コード例 #1
0
/**
 * Renders a scene not to the screen but into a texture
 */
void drawSceneToSpecificFramebuffer(GLuint fbo, int renderToTexture) {
    /**
     * Drawing into the given framebuffer-object
     */
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    if (renderToTexture) {
        glClearColor(0.0, 0.8, 0.8, 0.0);
    } else {
        glClearColor(0.0, 1.0, 1.0, 0.0);
    }
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glDisable(GL_CULL_FACE);
    glViewport (0, 0, G_Width, G_Height);
    setProjection ((double)G_Width/G_Height);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt (getCameraPosition(0), getCameraPosition(1), getCameraPosition(2),
         0.0, 0.0, 0.0,
         0.0, 1.0, 0.0);

    glDisable(GL_TEXTURE_2D);
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
        printf ("Framebuffer is not correct!\n");
    }

    drawDemo(renderToTexture);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: mvwicky/NotesMiscellanea
void display(void)
{
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	if( m_pDemo->m_enableLighting )
	{
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
	}
	else
	{
		glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	}

	glLoadIdentity();
	{
		setPerspectiveProjMatrix();
		setModelViewMatrix();
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glColor3f(1, 1, 1);

	if( m_pDemo->m_enableLighting )
	{
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

		glEnable(GL_COLOR_MATERIAL);
		glEnable(GL_NORMALIZE);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		float lightPos[] = {0,2,2,1};
		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
		float s = 0.3f;
		float ambColor[] = {s,s,s,1.f};
		glLightfv(GL_LIGHT0, GL_AMBIENT, ambColor);
	}
	else
	{
		glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	}

	drawDemo();

	if( m_pDemo->m_enableLighting )
	{
		glDisable(GL_LIGHT0);
		glDisable(GL_LIGHTING);
	}

	if( drawText )
	{
		setOrthoProjMatrix();
		glLoadIdentity();
		drawDemo2D();
	}

	glutSwapBuffers();
}
コード例 #3
0
ファイル: GraphicsDemo.cpp プロジェクト: AydinSakar/JUCE
    void paint (Graphics& g) override
    {
        double startTime = 0.0;

        {
            // A ScopedSaveState will return the Graphics context to the state it was at the time of
            // construction when it goes out of scope. We use it here to avoid clipping the fps text
            const Graphics::ScopedSaveState state (g);

            if (controls.clipToRectangle.getToggleState())  clipToRectangle (g);
            if (controls.clipToPath     .getToggleState())  clipToPath (g);
            if (controls.clipToImage    .getToggleState())  clipToImage (g);

            g.setImageResamplingQuality (controls.quality.getToggleState() ? Graphics::highResamplingQuality
                                                                           : Graphics::mediumResamplingQuality);

            // take a note of the time before the render
            startTime = Time::getMillisecondCounterHiRes();

            // then let the demo draw itself..
            drawDemo (g);
        }

        double now = Time::getMillisecondCounterHiRes();
        double filtering = 0.08;

        const double elapsedMs = now - startTime;
        averageTimeMs += (elapsedMs - averageTimeMs) * filtering;

        const double sinceLastRender = now - lastRenderStartTime;
        lastRenderStartTime = now;

        const double effectiveFPS = 1000.0 / averageTimeMs;
        const double actualFPS = sinceLastRender > 0 ? (1000.0 / sinceLastRender) : 0;
        averageActualFPS += (actualFPS - averageActualFPS) * filtering;

        GlyphArrangement ga;
        ga.addFittedText (displayFont,
                          "Time: " + String (averageTimeMs, 2)
                            + " ms\nEffective FPS: " + String (effectiveFPS, 1)
                            + "\nActual FPS: " + String (averageActualFPS, 1),
                          0, 10.0f, getWidth() - 10.0f, (float) getHeight(), Justification::topRight, 3);

        g.setColour (Colours::white.withAlpha (0.5f));
        g.fillRect (ga.getBoundingBox (0, ga.getNumGlyphs(), true).getSmallestIntegerContainer().expanded (4));

        g.setColour (Colours::black);
        ga.draw (g);
    }