Beispiel #1
0
//draw a frame
void RenderFrame()
{
	//Clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();										//reset modelview matrix


	camera.SetupViewMatrix();
	glMultMatrixf(camera.viewMatrix);

	DrawBackground();


	glPushAttrib(GL_ALL_ATTRIB_BITS);
	
	//Enable vertex program
	glEnable(GL_VERTEX_PROGRAM_NV);

	//Enable register combiners
	glEnable(GL_REGISTER_COMBINERS_NV);

	//Enable textures
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
	
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);

	//Set up CHROMATIC_SINGLE tex units
	if(renderPath==CHROMATIC_SINGLE)
	{
		glActiveTextureARB(GL_TEXTURE2_ARB);
		glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);
		glEnable(GL_TEXTURE_CUBE_MAP_ARB);

		glActiveTextureARB(GL_TEXTURE3_ARB);
		glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);
		glEnable(GL_TEXTURE_CUBE_MAP_ARB);
	}
	
	glActiveTextureARB(GL_TEXTURE0_ARB);

	//Set the texture Matrix to be the inverse view matrix
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMultMatrixf(camera.viewMatrix.GetInverse());
	glMatrixMode(GL_MODELVIEW);

	//Create object display lists
	static GLuint objectLists;
	if(!objectLists)
	{
		objectLists=glGenLists(3);
		
		glNewList(objectLists, GL_COMPILE);
		{
			glutSolidSphere(1.0, 120, 60);
		}
		glEndList();

		glNewList(objectLists+1, GL_COMPILE);
		{
			glutSolidTorus(0.3, 0.7, 120, 60);
		}
		glEndList();

		glNewList(objectLists+2, GL_COMPILE);
		{
			glutSolidTeapot(1.0f);
		}
		glEndList();
	}

	//If using CHROMATIC_TWIN, need to do two passes, so set states every frame
	if(renderPath==CHROMATIC_TWIN)
		InitChromaticTwin1States();

	//draw object
	glCallList(objectLists+objectType);

	//Do the second path if necessary
	if(renderPath==CHROMATIC_TWIN)
	{
		InitChromaticTwin2States();
		glCallList(objectLists+objectType);
	}

	//Reset texture matrix
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glPopAttrib();

	


	fpsCounter.Update();											//update frames per second counter
	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	window.StartTextMode();
	window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps());			//print the fps
	glColor4f(0.5f, 0.0f, 1.0f, 1.0f);
	if(renderPath==CHROMATIC_SINGLE)
		window.Print(0, 48, "Single Pass Chromatic Aberration");
	if(renderPath==SIMPLE_SINGLE)
		window.Print(0, 48, "Single Pass Simple Refraction");
	if(renderPath==CHROMATIC_TWIN)
		window.Print(0, 48, "Two Pass Chromatic Aberration");
	window.EndTextMode();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	if(window.isKeyPressed(VK_F1))
	{
		window.SaveScreenshot();
		window.SetKeyReleased(VK_F1);
	}

	window.SwapBuffers();									//swap buffers

	//check for any opengl errors
	window.CheckGLError();

	//quit if necessary
	if(window.isKeyPressed(VK_ESCAPE))
		PostQuitMessage(0);
}
Beispiel #2
0
//draw a frame
void RenderFrame()
{
	//Draw to pbuffer
	pbuffer.MakeCurrent();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();										//reset modelview matrix

	gluLookAt(	0.0f, 0.0f, 4.0f,
				0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f);

	//Draw scene
	if(drawTextured)
	{
		glBindTexture(GL_TEXTURE_2D, decalTexture);
		glEnable(GL_TEXTURE_2D);
		
		glPushMatrix();
		glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);

		glutSolidTeapot(0.8f);
		
		glPopMatrix();

		glDisable(GL_TEXTURE_2D);
	}
	else
	{
		glPushMatrix();
		glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);
		glRotatef(55.0f, 1.0f, 0.0f, 0.0f);
		glutWireTorus(0.3f, 1.0f, 12, 24);
		glPopMatrix();

		glPushMatrix();
		glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);
		glRotatef(-55.0f, 1.0f, 0.0f, 0.0f);
		glutWireTorus(0.3f, 1.0f, 12, 24);
		glPopMatrix();
	}


	
	//Draw to window
	window.MakeCurrent();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	camera.SetupViewMatrix();
	glLoadMatrixf(camera.viewMatrix);


	glBindTexture(GL_TEXTURE_2D, pbufferTexture);
	//use the pbuffer as the texture
	wglBindTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB);


	//Draw simple rectangle
	glBegin(GL_TRIANGLE_STRIP);
	{
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-1.0f,  1.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f( 1.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f( 1.0f,  1.0f, 0.0f);
	}
	glEnd();

	//release the pbuffer for further rendering
	wglReleaseTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB);



	fpsCounter.Update();											//update frames per second counter
	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	window.StartTextMode();
	window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps());			//print the fps
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	window.Print(0, 48, "%dx Anisotropy", currentAnisotropy);
	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
	window.Print(0, 68, "%s", useMipmapFilter ?	"LINEAR_MIPMAP_LINEAR filtering" :
												"LINEAR filtering");
	window.EndTextMode();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	if(window.isKeyPressed(VK_F1))
	{
		window.SaveScreenshot();
		window.SetKeyReleased(VK_F1);
	}

	window.SwapBuffers();									//swap buffers

	//check for any opengl errors
	window.CheckGLError();

	//quit if necessary
	if(window.isKeyPressed(VK_ESCAPE))
		PostQuitMessage(0);
}
Beispiel #3
0
//draw a frame
void RenderFrame()
{
    //Clear buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();										//reset modelview matrix

    camera.SetupViewMatrix();
    glLoadMatrixf(camera.viewMatrix);

    //Enable box texture
    glEnable(GL_TEXTURE_2D);

    //Enable attenuation textures
    if(codePath==TEXTURE_ATTEN || codePath==GAUSSIAN_ATTEN)
    {
        //2D atten
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_2D);
        //1D atten
        glActiveTextureARB(GL_TEXTURE2_ARB);
        glEnable(GL_TEXTURE_1D);
        glActiveTextureARB(GL_TEXTURE0_ARB);
    }
    else if(codePath==PASS_THROUGH_ATTEN)	//set up pass through states
    {
        //enable texture shaders
        glEnable(GL_TEXTURE_SHADER_NV);
    }
    else if(codePath==TEXTURE_3D_ATTEN)
    {
        //3D atten
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_3D);
        glActiveTextureARB(GL_TEXTURE0_ARB);
    }



    //Enable vertex program
    glEnable(GL_VERTEX_PROGRAM_NV);
    glBindProgramNV(GL_VERTEX_PROGRAM_NV, vertexProgram);

    //Send the light's color to primary color
    glColor4fv(lightColors[currentLightColor]);

    //set the texture matrix
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glTranslatef(0.5f, 0.5f, 0.5f);
    glScalef(0.5f, 0.5f, 0.5f);
    glScalef(1/lightRadius, 1/lightRadius, 1/lightRadius);
    glTranslatef(-lightPosition.x, -lightPosition.y, -lightPosition.z);
    glMatrixMode(GL_MODELVIEW);

    //Enable register combiners
    glEnable(GL_REGISTER_COMBINERS_NV);

    //Draw Cube
    glDrawArrays(GL_QUADS, 0, 24);

    //Disable box texture
    glDisable(GL_TEXTURE_2D);

    //Disable attenuation textures
    if(codePath==TEXTURE_ATTEN || codePath==GAUSSIAN_ATTEN)
    {
        //2D atten
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glDisable(GL_TEXTURE_2D);
        //1D atten
        glActiveTextureARB(GL_TEXTURE2_ARB);
        glDisable(GL_TEXTURE_1D);
        glActiveTextureARB(GL_TEXTURE0_ARB);
    }
    else if(codePath==PASS_THROUGH_ATTEN)	//set up pass through states
    {
        //disable texture shaders
        glDisable(GL_TEXTURE_SHADER_NV);
    }
    else if(codePath==TEXTURE_3D_ATTEN)
    {
        //3D atten
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glDisable(GL_TEXTURE_3D);
        glActiveTextureARB(GL_TEXTURE0_ARB);
    }

    //Disable vertex program
    glDisable(GL_VERTEX_PROGRAM_NV);

    //reset the texture matrix
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);

    //Disable register combiners
    glDisable(GL_REGISTER_COMBINERS_NV);


    //Draw light in a display list
    glColor4fv(lightColors[currentLightColor]);
    glTranslatef(lightPosition.x, lightPosition.y, lightPosition.z);
    static GLuint sphereList=0;
    if(!sphereList)
    {
        sphereList=glGenLists(1);
        glNewList(sphereList, GL_COMPILE);
        {
            gluSphere(sphere, 0.1f, 24, 12);
        }
        glEndList();
    }
    glCallList(sphereList);
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);



    fpsCounter.Update();											//update frames per second counter
    glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
    window.StartTextMode();
    window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps());			//print the fps
    glColor4f(1.0f, 1.0f, 0.0f, 0.0f);
    if(codePath==TEXTURE_ATTEN)
        window.Print(0, 48, "Using Texture Attenuation");
    if(codePath==PASS_THROUGH_ATTEN)
        window.Print(0, 48, "Using Pass Through Attenuation");
    if(codePath==TEXTURE_3D_ATTEN)
        window.Print(0, 48, "Using 3D Texture Attenuation");
    if(codePath==GAUSSIAN_ATTEN)
        window.Print(0, 48, "Using Gaussian Texture Attenuation");
    window.EndTextMode();
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    if(window.isKeyPressed(VK_F1))
    {
        window.SaveScreenshot();
        window.SetKeyReleased(VK_F1);
    }

    window.SwapBuffers();									//swap buffers

    //check for any opengl errors
    window.CheckGLError();

    //quit if necessary
    if(window.isKeyPressed(VK_ESCAPE))
        PostQuitMessage(0);
}