Exemple #1
0
void Draw::draw(Type type){
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();

	glPushMatrix();
	glOrtho(0, width, height, 0, -1.0, 1.0);

	switch(type){
	case line:
		drawLine();
		break;
	case triangle:
		drawTriangle();
		break;
	case square:
		drawSquare();
		break;
	case better:
		drawBetterSquare();
		break;
	case sky:
		drawSky();
		break;
	}

	glPopMatrix();
	SDL_GL_SwapBuffers();
}
Exemple #2
0
// Renders the requested list of faces
// Normal faces are rendered with vertex arrays and multitexturing. The first TMU handles the 
// lightmap, while the second TMU handles the surface texture itself.
int GLDriver::drawGeometryList(GeometryList* l)
{
	Assert(l != NULL);
	if(lastTime == 0)
		lastTime = timeGetTime();
	renderTime = timeGetTime();
	qmap = l->mapData;

	ShaderUtils::renderTime = renderTime;
	ShaderUtils::qmap = qmap;
	ShaderUtils::textureFactory = textureFactory;
	qsort(l->faces, l->faceCount, sizeof(int), TransSort);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);

	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);

	glDepthFunc(GL_LEQUAL);

	float timeDiff = renderTime - lastTime;
    drawSky(l, timeDiff);
    drawFaces(l, timeDiff);
    drawMeshes(l, timeDiff);
    drawPatches(l);
    //drawFog(l);

	lastTime = renderTime;
	return 0;
}
Exemple #3
0
void display () {

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	enter3D();

	gluLookAt(camera.x, camera.y, camera.z,
			  cameraLookAt.x, cameraLookAt.y, cameraLookAt.z,
			  cameraUp.x, cameraUp.y, cameraUp.z);

	glPushMatrix();
	glScaled(1.0, -1.0, 1.0);

	if (showSky) {
		drawSky();
	}

	// Draw coordinate axis
	// glCallList(axisList);

	for (int i = 0; i < 9; i ++) {
		gravitationalForce[i].draw();
	}

	if (showGround) {
		drawGround();
	}

	if (showPipe) {
		glPushMatrix();
			drawSprinkler(emitterSpacing * emitterCount, sprinkerHeight, 100, 5.0, 40.0);
		glPopMatrix();
	}

	if (showMountains) {
		drawMoutains(3000, 0, 0);
		drawMoutains(4000, 180, -200);
		drawMoutains(5600, 45, -500);
	}

	if (showTrees) {
		drawTrees();
	}

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::set("shine");
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	}

	particleSystem.draw();

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::done();
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}

	/*glPushMatrix();
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(0.0, -100.0, 0.0);
	glScalef(100.0, -100.0, 100.0);
	drawModel();
	glPopMatrix();*/

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	glDisable(GL_DEPTH_TEST);
	enter2D();

	glColor4d(0.0, 0.0, 0.0, 1.0);
	sprintf(fpsText, "FPS:%4.2f", fps);
	drawText(GLUT_BITMAP_HELVETICA_18, windowWidth - 100, 20, fpsText);

	if (showHUD) {

		drawText(GLUT_BITMAP_HELVETICA_18, 10, 20, "Water sprinkler");

		sprintf(cameraText, "%4.2f %4.2f %4.2f", camera.x, camera.y, camera.z);
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 60, cameraText);

		sprintf(particleText, "Particles: %llu", particleSystem.getParticleCount());
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 100, particleText);

		if (menu) {

			// Current option
			glColor4d(0.2, 0.2, 0.2, 0.8);
			glRectd(10, windowHeight - 40, 120, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, options[currentOption]);

			// Current option value
			glColor4d(0.4, 0.4, 0.4, 0.8);
			glRectd(120, windowHeight - 40, 240, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);

			switch (currentOption) {
			case 0: sprintf(optionValue, "%4.2f", Particle::initialVelocity); break;
			case 1: sprintf(optionValue, "%d", initialColour); break;
			case 2: sprintf(optionValue, "%d", gravityIntensity); break;
			case 3: sprintf(optionValue, "%d", Particle::startLifeSpan); break;
			case 4: sprintf(optionValue, "%s", renderModes[renderMode]); break;
			case 5: sprintf(optionValue, "%d", emitterCount); break;
			case 6: sprintf(optionValue, "%d", emitterSpacing); break;
			case 7: sprintf(optionValue, "%s", cameras[currentCamera]); break;
			case 8: sprintf(optionValue, "%4.2f", Particle::airResistance); break;
			case 9: sprintf(optionValue, "%s", cycleColours ? "On" : "Off"); break;
			case 10: sprintf(optionValue, "%d", emitFrequency); break;
			case 11: sprintf(optionValue, "%4.2f", ParticleEmitter::emitSpread); break;
			case 12: sprintf(optionValue, "%d", ParticleSystem::perEmit); break;
			case 13: sprintf(optionValue, "%s", ParticleEmitter::show ? "Yes" : "No"); break;
			case 14: sprintf(optionValue, "%s", wireframe ? "Yes" : "No"); break;
			case 15: sprintf(optionValue, "%s", showMountains ? "On" : "Off"); break;
			case 16: sprintf(optionValue, "%s", showTrees ? "On" : "Off"); break;
			case 17: sprintf(optionValue, "%s", showSky ? "On" : "Off"); break;
			case 18: sprintf(optionValue, "%s", showGround ? "On" : "Off"); break;
			case 19: sprintf(optionValue, "%s", demos[demo]->name.c_str()); break;
			case 20: sprintf(optionValue, "%1.1f", Particle::bounce); break;
			case 21: sprintf(optionValue, "%s", skyTexture ? "On" : "Off"); break;
			case 22: sprintf(optionValue, "%s", grassTexture ? "On" : "Off"); break;
			case 23: sprintf(optionValue, "%s", showPipe ? "On" : "Off"); break;
			case 24: sprintf(optionValue, "%s", ParticleEmitter::randomness ? "On" : "Off"); break;
			case 25: sprintf(optionValue, "%s", Tree::drawLeaves ? "On" : "Off"); break;
			default: sprintf(optionValue, "%s", ""); break;
			}

			drawText(GLUT_BITMAP_HELVETICA_12, 130, windowHeight - 20, optionValue);

		}
		else {
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, "Press m to toggle menu");
		}

		for (int i = 1; i < 10; i++) {
			if (selectedGravitationalForce == i - 1) {
				glColor4d(1.0, 0.4, 0.4, 0.8);
			}
			else {
				glColor4d(0.4, 0.4, 1.0, 0.2);
			}
			glRectd(200 + ((i - 1) * 50), 10, 230 + ((i - 1) * 50), 40);
			glColor4d(0.0, 0.0, 0.0, 1.0);
			sprintf(n, "%d", i);
			drawText(GLUT_BITMAP_HELVETICA_18, 210 + ((i - 1) * 50), 30, n);
		}

	}

	if (currentCamera == 3) {
		glBegin(GL_LINES);
			glColor3d(0.8, 0.8, 0.8);
			glVertex2d((windowWidth / 2) - 30, windowHeight / 2);
			glVertex2d((windowWidth / 2) + 30, windowHeight / 2);
			glVertex2d(windowWidth / 2, (windowHeight / 2) - 30);
			glVertex2d(windowWidth / 2, (windowHeight / 2) + 30);
		glEnd();
	}

	glPopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}
//--------------------------------------------------
void Skybox::render(bool activateShaders)
{
	Shader::disable();
	//configuration:
	float skySize = 30000.0f;
	float sunOrbit = 28000.0f;
	float orbitBias = 0.05f;
	float orbitRotation = 0.1f;
	int numberOfStars = 1000;

	//Rotate the sun ----------------------------------------
	Vector3f sunPosition = Vector3f(sunOrbit, 0.0f, 0.0f);

	Matrix3f m3 = Matrix3f::createRotationAroundAxis(0.0f, orbitRotation * 2.0f * (float)M_PI, 0.0f);
	Matrix3f m1 = Matrix3f::createRotationAroundAxis(0.0f, 0.0f, dayTime * 2.0f * (float)M_PI);
	Matrix3f m2 = Matrix3f::createRotationAroundAxis(orbitBias * 2.0f * (float)M_PI, 0.0f, 0.0f);

	sunPosition = m1 * sunPosition;
	sunPosition = m2 * sunPosition;
	sunPosition = m3 * sunPosition;

	//direction:
	sunDirection = sunPosition;
	sunDirection.normalize();

	//sky colors:
	Vector4f blue = Vector4f(0.2f, 0.4f, 0.8f, 1.0f);
	Vector4f white = Vector4f(0.52f, 0.63f, 0.87f, 1.0f);

	Vector4f orange = Vector4f(0.75f, 0.35f, 0.0f, 1.0f);
	Vector4f red = Vector4f(0.85f, 0.15f, 0.0f, 1.0f);

	Vector4f black = Vector4f(0.0f, 0.0f, 0.0f, 0.0f);

	//mix sky colors:
	Vector4f color1 = Vector4f(0.0f, 0.0f, 0.0f, 0.0f);
	Vector4f color2 = Vector4f(0.0f, 0.0f, 0.0f, 0.0f);
	float d = sunDirection.y;

	if (d >= 0.3f)
	{
		color1 = blue;
		color2 = white;
	}
	else
	{
		if (d >= 0.2f)
		{
			color1 = blue * (d - 0.2f) * 10.0f + orange * (1 - (d - 0.2f) * 10.0f);
			color2 = white * (d - 0.2f) * 10.0f + red * (1 - (d - 0.2f) * 10.0f);
		}
		else
		{
			color1 = orange * d * 5.0f + black * (1 - d * 5.0f);
			color2 = red * d * 5.0f  + black * (1 - d * 5.0f);
		}
	}

	//weapon (this is an easter egg)
	/*glPushMatrix();
	glLoadIdentity();
	glRotatef(20.0, 0, 0, 1);
	glRotatef(-20.0, 1, 0, 0);
	glTranslatef(20.0, 10.0, -50.0);
	weapon->showS();
	glPopMatrix();*/

	//draw everything ------------------------------------------
	glPushMatrix();
	glPushAttrib(GL_ENABLE_BIT);

	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_POINT_SMOOTH);

	resetTranslation();
	drawStars(numberOfStars);
	drawSky(skySize, color1, color2);
	drawSun(sunPosition);

	//restore matrix and attributes
	glPopAttrib();
	glPopMatrix();
	Shader::useDefaultShader();
}
void TerrainTessellation::draw(void)
{
    glClearColor( 0.7f, 0.8f, 1.0f, 1.0f);
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);

    //
    // Compute matrices without the legacy matrix stack support
    //
    nv::matrix4f projectionMatrix;
    nv::perspective( projectionMatrix, 45.0f * 2.0f*NV_PI / 360.0f, (float)m_width/(float)m_height, 0.01f, 100.0f);
    nv::matrix4f invProjection = nv::inverse(projectionMatrix);

    nv::matrix4f viewMatrix;
    viewMatrix = m_transformer->getModelViewMat();
    nv::matrix4f invView = nv::inverse(viewMatrix);

    // compute frustum planes for culling
    nv::vec4f frustumPlanes[6];
    computeFrustumPlanes(viewMatrix, projectionMatrix, frustumPlanes);

    glViewport(0, 0, m_width, m_height);

    glBindProgramPipeline(0);

    //
    // update struct representing UBO
    //
    mParams.ModelView = viewMatrix;
    mParams.ModelViewProjection= projectionMatrix * viewMatrix;
    mParams.Projection = projectionMatrix;
    mParams.InvProjection = invProjection;
    mParams.InvView = invView;

    mParams.cull = mCull;
    mParams.lod = mLod;
    mParams.viewport = nv::vec4f(0.0, 0.0, (float) m_width, (float) m_height);
    mParams.lightDirWorld = mLightDir;
    mParams.lightDir = nv::vec3f(viewMatrix * nv::vec4f(normalize(mLightDir), 0.0));   // transform to eye space
    mParams.smoothNormals = mSmoothNormals;
    mParams.time = mTime;
    mParams.eyePosWorld = invView * nv::vec4f(0.0f, 0.0f, 0.0f, 1.0f);

    if (mAnimate) {
        mParams.translate.y -= getFrameDeltaTime()*2.0f;
    }

    for(int i=0; i<6; i++) {
        mParams.frustumPlanes[i] = frustumPlanes[i];
    }

    // bind the buffer for the UBO, and update it with the latest values from the CPU-side struct
    glBindBufferBase( GL_UNIFORM_BUFFER, 1, mUBO);
    glBindBuffer( GL_UNIFORM_BUFFER, mUBO);
    glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(TessellationParams), &mParams);

    // enable / disable wireframe
    glPolygonMode( GL_FRONT_AND_BACK, mWireframe ? GL_LINE : GL_FILL);

    // query number of primitives
    glBeginQuery(GL_PRIMITIVES_GENERATED, mGPUQuery);

    drawTerrain();

    glEndQuery(GL_PRIMITIVES_GENERATED);

    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);

    drawSky();

    // update triangle count so we can display in UI
    glGetQueryObjectuiv(mGPUQuery, GL_QUERY_RESULT, &mNumPrimitives);
    mStatsText->SetValue(mNumPrimitives);

    if (mReload) {
        loadShaders();
        mReload = false;
        mTweakBar->syncValues();
    }
}
void playGame() {
	glEnable(GL_LIGHTING);	
	glEnable(GL_LIGHT2);
	glEnable(GL_LIGHT3);
	glEnable(GL_LIGHT4);
	glEnable(GL_LIGHT5);
	glEnable(GL_LIGHT6);
	glEnable(GL_LIGHT7);
	glPushMatrix();
	if (eThunder > 0)
		drawThunder();

		GLfloat spotlightPostition2[] = {11,-40,-120*(lightpos+1),1};
		GLfloat spotlightDirection2[] = {0,-1,0,0};
		glLightfv(GL_LIGHT2, GL_SPECULAR, white_light);
		glLightfv(GL_LIGHT2, GL_AMBIENT, white_light);
		glLightfv(GL_LIGHT2, GL_DIFFUSE, white_light);
		glLightfv (GL_LIGHT2, GL_SPOT_DIRECTION, spotlightDirection2);
		glLightfv(GL_LIGHT2, GL_POSITION, spotlightPostition2);
		glLightf (GL_LIGHT2, GL_SPOT_CUTOFF, 45);
		GLfloat spotlightPostition3[] = {-11,-40,-120*(lightpos+1),1};
		GLfloat spotlightDirection3[] = {0,-1,0,0};
		glLightfv(GL_LIGHT3, GL_SPECULAR, white_light);
		glLightfv(GL_LIGHT3, GL_AMBIENT, white_light);
		glLightfv(GL_LIGHT3, GL_DIFFUSE, white_light);
		glLightfv (GL_LIGHT3, GL_SPOT_DIRECTION, spotlightDirection3);
		glLightfv(GL_LIGHT3, GL_POSITION, spotlightPostition3);
		glLightf (GL_LIGHT3, GL_SPOT_CUTOFF, 45);

		GLfloat spotlightPostition4[] = {11,-40,-120*lightpos,1};
		GLfloat spotlightDirection4[] = {0,-1,0,0};
		glLightfv(GL_LIGHT4, GL_SPECULAR, white_light);
		glLightfv(GL_LIGHT4, GL_AMBIENT, white_light);
		glLightfv(GL_LIGHT4, GL_DIFFUSE, white_light);
		glLightfv (GL_LIGHT4, GL_SPOT_DIRECTION, spotlightDirection4);
		glLightfv(GL_LIGHT4, GL_POSITION, spotlightPostition4);
		glLightf (GL_LIGHT4, GL_SPOT_CUTOFF, 45);
		GLfloat spotlightPostition5[] = {-11,-40,-120*lightpos,1};
		GLfloat spotlightDirection5[] = {0,-1,0,0};
		glLightfv(GL_LIGHT5, GL_SPECULAR, white_light);
		glLightfv(GL_LIGHT5, GL_AMBIENT, white_light);
		glLightfv(GL_LIGHT5, GL_DIFFUSE, white_light);
		glLightfv (GL_LIGHT5, GL_SPOT_DIRECTION, spotlightDirection5);
		glLightfv(GL_LIGHT5, GL_POSITION, spotlightPostition5);
		glLightf (GL_LIGHT5, GL_SPOT_CUTOFF, 45);

		if (c.isThirdPerson()) {
			glColor3f(0,0,0);
			glTranslatef(hx, hy, 0);
			drawHeadLight();
			drawHelicopter();
		}
	glPopMatrix();


	//

	
	//
	glBindTexture(GL_TEXTURE_2D, _swtextureId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glColor4f(1.0f, 1.0f, 1.0f,0.6);
		glColor3f(1,0,0);
	for (int i = 0; i < 70; ++i) {
		drawRightSidewalk(numSide + i);
		drawLeftSidewalk(numSide + i);
	}
	for (int i = 0; i <= 9; ++i) {

		drawRightScene((numBuild1 + i)%NUM_BUILDINGS);
		drawLeftScene((numBuild2 + i)%NUM_BUILDINGS);
	}


	glColor3f(0,0,1);
	glPushMatrix();
//	glTranslatef(0,0,m.getZ());
		drawSky();
	glPopMatrix();


	glDisable(GL_TEXTURE_2D);
//	glColor3f(0,1,1);

	drawLampost(lightpos-1);
	drawLampost(lightpos);
	drawLampost(lightpos+1);
	glPushMatrix();

	glTranslatef(0,0,m.getZ());
		drawStreet();
	glPopMatrix();

	drawBridges();

	glDisable(GL_LIGHT0);
	glDisable(GL_LIGHT1);
	glDisable(GL_LIGHT2);
	glDisable(GL_LIGHT3);
	glDisable(GL_LIGHT4);
	glDisable(GL_LIGHT5);
	glDisable(GL_LIGHT6);
}