Пример #1
0
void Scene::renderGameStatistics()
{
	// Show intro
	if( m_fTimer < 3.0f )
	{
		scene->renderFont( 255, 0, 255, 0, 3.0f, GAME_WIDTH / 2.0f, 30.0f, HGETEXT_CENTER, "-=SURVIVAL=-" ); 
	}

	// Show statistics
	std::string atp( "attempts: " );
	atp += std::to_string( attempts ); 
	renderFont( 255, 128, 128, 128, 1.0f, GAME_WIDTH - 140.0f, 10.0f, HGETEXT_LEFT, atp );

	std::string str( "health: ");
	int health = static_cast<int>( objects->getTank( )->getHealth( ) * 100 );
	str += std::to_string( health ); 
	renderFont( 255, 128, 128, 128, 1.0f, GAME_WIDTH - 140.0f, 40.0f, HGETEXT_LEFT, str );

	std::string timer( "timer: "); 
	timer += std::to_string( static_cast<int>(SURVIVAL_TIME) - static_cast<int>(m_fTimer) );
	timer += "s";
	renderFont( 255, 128, 128, 128, 1.0f, GAME_WIDTH - 140.0f, 70.0f, HGETEXT_LEFT, timer );

	std::string bst( "beasts: ") ;
	bst += std::to_string( objects->getDeadBeastQuantity( ) ); 
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, 10.0f, HGETEXT_LEFT, bst );

	std::string dmn( "daemons: ");
	dmn += std::to_string( objects->getDeadDaemonQuantity( ) ); 
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, 40.0f, HGETEXT_LEFT, dmn );

	std::string rpt( "reptiles: "); 
	rpt += std::to_string( objects->getDeadReptileQuantity( ) );
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, 70.0f, HGETEXT_LEFT, rpt );

	std::string blt( "bullets: ");
	blt += std::to_string( Weapon::getBulletsQuantity( ) );
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, GAME_HEIGHT - 90.0f, HGETEXT_LEFT, blt );

	std::string shl( "shells: ");
	shl += std::to_string( Weapon::getShellsQuantity( ) );
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, GAME_HEIGHT - 60.0f, HGETEXT_LEFT, shl );

	std::string rct( "rockets: ");
	rct += std::to_string( Weapon::getRocketsQuantity( ) );
	renderFont( 255, 128, 128, 128, 1.0f, 10.0f, GAME_HEIGHT - 30.0f, HGETEXT_LEFT, rct );
}
Пример #2
0
//Renders to the device.
bool AlwynD3DInterfaceImpl::render()
{
	//Update the fps counter.
	fpsCounter->render();

	//Set the gammecorrection.
	gammaCorrectionVar->SetFloat(gammaCorrection);

	//Construct the viewing frustum, used for draw predicated (occlusion logic).
	viewingFrustum->constructFrustum(depth, mvpMatrix, camera);

	device->device->ClearRenderTargetView(device->renderTView, bgColor);

	//poll all input devices.
	device->getInput(input);

	D3DXMatrixIdentity(&tmp);
	D3DXMatrixIdentity(&tmp2);

	/**
	//translate camera position according to user input.	
	D3DXMatrixTranslation(&tmp, side, down, fwd);
	device->multiplyMatrix(&tmp2, camera->viewMatrix, &tmp);

	//rotate camera y axis according to user input.	
	D3DXMatrixRotationY(&tmp, rotY);
	device->multiplyMatrix(&tmp2, camera->viewMatrix, &tmp);

	//rotate camera x axis according to user input.	
	D3DXMatrixRotationX(&tmp, rotX);
	device->multiplyMatrix(&tmp2, camera->viewMatrix, &tmp);
	*/
		
	//Set the world matrix effect variable on the shader effect.
	mvpMatrix->setWorldMatrixEffVar();

	//Camera Movement
	//Change velocity according to user input.
	if (fwd != 0.0f)
		camera->moveForward(fwd);
	if (side != 0.0f)
		camera->strafe(side);

	//Calculate where the camera would be if current velocity applied (for collision detection)
	camera->precalculations();

	//Have to apply the collision detection before moving the camera.
	applyFPSGravity(device);
	applyWallCollision(device);

	//Move the camera, Pitch and Yaw as well.
	camera->render();

	//Set the view matrix effect variable on the shader effect.
	mvpMatrix->setViewMatrixEffVar(camera->viewMatrix);

	//Combine matrices to save calculation time
	device->copyMatrix(&wvp, mvpMatrix->world);
	device->multiplyMatrix(&tmp2, &wvp, camera->viewMatrix);
	device->multiplyMatrix(&tmp2, &wvp, mvpMatrix->proj);
	wvpMatrixVar->SetMatrix((float *) &wvp);


	renderFont(device);
	renderFontFramework(device);

	if (device->filtering)
	{
		filterTypeVar->SetInt(0);
	} else
	{
		filterTypeVar->SetInt(1);
	}


	clipCheck(device);

	//RENDER HERE
	frameworkRender(device);
	pointerInstancedClipMeshArrayUpdateMatrixData(pointerArrayInstancedClipMesh, pointerArrayInstancedClipMeshCount);
	pointerInstancedLightMeshArrayUpdateMatrixData(pointerArrayInstancedLightClipMesh, pointerArrayInstancedLightClipMeshCount);

	renderPointerInstancedClipMeshArray(pointerArrayInstancedClipMesh, pointerArrayInstancedClipMeshCount);
	renderPointerInstancedLightMeshArray(pointerArrayInstancedLightClipMesh, pointerArrayInstancedLightClipMeshCount);

	//if (fwd > 0)
	//	fwd = speed();
	//if (fwd < 0)
	//	fwd = -speed();


	return true;
}
Пример #3
0
void ButtonOverlayProcessor::renderOverlayImage() {

    regenerateOverlay_ = false;

    tgt::Texture* pickingTex = pickingPort_.getColorTexture();
    if(pickingTex->getPixelData())
        pickingTex->destroy();

    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);

    overlayPort_.activateTarget();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();

    glClearDepth(1.0);
    glDisable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    pickingPort_.activateTarget();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearDepth(1.0);
    glDisable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    TextureUnit overlayUnit;
    tgt::ivec2 groupCoords = inport_.getSize() - tgt::ivec2(horzBorder_.get(), vertBorder_.get());

    int count = 0;

    for(size_t i = 0; i < buttonProps_.size(); i++) {

        if(!isVisibleProps_.at(i)->get())
            continue;

        overlayPort_.activateTarget();
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

        // add support for transparent buttons in combination with user controlled transparency, otherwise
        // the texture transparency always has priority
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        overlayUnit.activate();
        if(buttonProps_.at(i)->get()) {
            //buttonTexturesPressed_.at(i)->bind();
            //buttonTexturesPressed_.at(i)->enable();
            buttonTexturePressed_->bind();
            buttonTexturePressed_->enable();
        } else {
            //buttonTexturesNonPressed_.at(i)->bind();
            //buttonTexturesNonPressed_.at(i)->enable();
            buttonTextureReleased_->bind();
            buttonTextureReleased_->enable();
        }
        LGL_ERROR;

        tgt::ivec2 radius = tgt::ivec2(buttonRadiusX_.get(), buttonRadiusY_.get());
        tgt::ivec2 centerCoords = groupCoords - tgt::ivec2(0, count*(groupBorder_.get() + 2*radius.y)) - radius;

        //radius.x = (float(buttonTexturePressed_->getWidth()) / float(buttonTexturePressed_->getHeight())) * radius.y;

        glColor4f(1.0f, 1.0f, 1.0f, opacity_.get());
        glBegin(GL_QUADS);

        tgt::vec2 ll = tgt::vec2(float(centerCoords.x - radius.x) / inport_.getSize().x, float(centerCoords.y - radius.y) / inport_.getSize().y);
        tgt::vec2 ur = tgt::vec2(float(centerCoords.x + radius.x) / inport_.getSize().x, float(centerCoords.y + radius.y) / inport_.getSize().y);
        ll = 2.0f * ll - 1.0f;
        ur = 2.0f * ur - 1.0f;

        glTexCoord2f(0.0f, 0.0f);
        glVertex2f(ll.x, ll.y);
        glTexCoord2f(1.0f, 0.0f);
        glVertex2f(ur.x, ll.y);
        glTexCoord2f(1.0f, 1.0f);
        glVertex2f(ur.x, ur.y);
        glTexCoord2f(0.0f, 1.0f);
        glVertex2f(ll.x, ur.y);

        glEnd();

        if(buttonProps_.at(i)->get())
            buttonTexturePressed_->disable();
        else
            buttonTextureReleased_->disable();

        renderFont(static_cast<int>(i), centerCoords);

        overlayPort_.deactivateTarget();
        glBlendFunc(GL_ONE, GL_ZERO);
        glDisable(GL_BLEND);

        pickingPort_.activateTarget();
        float col = float(i+1) / 255.f;
        glColor4f(col, col, col, 1.f);

        glRectf(ll.x, ll.y, ur.x, ur.y);
        pickingPort_.deactivateTarget();

        count++;
    }

    // download the picking texture to a buffer so we can perform picking on the cpu
    pickingPort_.getColorTexture()->downloadTexture();
    TextureUnit::setZeroUnit();
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
}
Пример #4
0
void ClientWidget::paintGL()
{
    frames+=1;
    qDebug()<<ENCAPS(tr("gl paint start"));
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,(float)width()/(float)height(),0.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
//**************************************************************************************************SCENE
    float l[]={-2,0,1,1};
    glLightfv(GL_LIGHT0,GL_POSITION,l);
    l[0]=-l[0];
    glLightfv(GL_LIGHT1,GL_POSITION,l);
    lightingprogram.bind();
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glColor4f(0.8,0.8,0.8,1);
    glLoadIdentity();
    gluLookAt(me.position.x(), me.position.y(),      me.position.z(),
              me.position.x(), me.position.y(),      me.position.z()+1.0f,
              0, 1, 0);
    glTranslatef(-0.1,0.2,0.5);
    glRotated(180,0,1,0);
    glRotated(30,1,0,0);
    glRotated(5,0,0,1);
    GLfloat whiteSpecularMaterial[] = {1.0, 1.0, 1.0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,128);
    teapot.render();
    glLoadIdentity();
    gluLookAt(me.position.x(), me.position.y(),      me.position.z(),
              me.position.x(), me.position.y(),      me.position.z()+1.0f,
              0, 1, 0);
    glTranslatef(0.1,-0.2,1);
    glColor4f(0.8,0.8,0.8,1);
    glScaled(0.05,0.05,0.05);
    glRotated(90,1,0,0);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,128);
    bunny.render();
    lightingprogram.release();
//**************************************************************************************************HUD
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,width(),0, height(), -1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();					// Reset The Current Modelview Matrix
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
    glColor4f(1,1,1,1);
    if(hudtex){
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, hudtex );
        glBegin(GL_QUADS);
        glTexCoord2d(0.0,0.0); glVertex3d(-1.0,-1.0,-1);
        glTexCoord2d(1.0,0.0); glVertex3d( 1.0,-1.0,-1);
        glTexCoord2d(1.0,1.0); glVertex3d( 1.0, 1.0,-1);
        glTexCoord2d(0.0,1.0); glVertex3d(-1.0, 1.0,-1);
        glEnd();
        glDisable( GL_TEXTURE_2D );
    }
    renderFont(font,fps,10,10,CWRF_LEFT,CWRF_TOP);
    renderFont(font,clock,10,10,CWRF_RIGHT,CWRF_BOTTOM);
    qDebug()<<ENCAPS(tr("gl paint end"));
}