///Displays
void display(){
    ///--- Clears the color buffer so that we don't display garbage
    glViewport(0,0,windowDimension,windowDimension);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        ///--- Upload viewing matrices externally
        GLuint pid = quad.getProgramID();
        glUseProgram(pid);
            mat4 MODEL = mat4::Identity();
            glUniformMatrix4fv(glGetUniformLocation(pid, "MODEL"), 1, GL_FALSE, MODEL.data());

            float theta_rad = M_PI/180.0*theta;
            //vec3 camera_pos( camX, camY, 2*sin(theta_rad));
            camX = camX + rateX;
            camY = camY + rateY;
            camZ = camZ + rateZ;
            vec3 camera_pos(camX,camY,camZ);
            mat4 VIEW = Eigen::lookAt( camera_pos, vec3(lookX,lookY,lookZ), vec3(0,0,1) ); //< "z" up on screen
            glUniformMatrix4fv(glGetUniformLocation(pid, "VIEW"), 1, GL_FALSE, VIEW.data());

            mat4 PROJ = Eigen::perspective(75.0f, windowDimension/(float)windowDimension, 0.1f, 10.0f);
            glUniformMatrix4fv(glGetUniformLocation(pid, "PROJ"), 1, GL_FALSE, PROJ.data());
        glUseProgram(pid);
    ///--- calls the quad.draw() method which displays the terrain quad (?takes in the ModelViewProjection matrices?)
    quad.draw();
}
示例#2
0
	void drawOverlay()
	{
		if (overlayTex == TEX::ID(0))
			return;

		SimpleShader &shader = shState->shaders().simple;
		shader.bind();
		shader.applyViewportProj();
		shader.setTexSize(overlayTexSize);
		shader.setTranslation(Vec2i());

		glState.blend.pushSet(true);

		TEX::bind(overlayTex);
		screenQuad.draw();

		glState.blend.pop();
	}
示例#3
0
文件: bitmap.cpp 项目: Lobomon/mkxp
	void blitQuad(Quad &quad)
	{
		glState.blendMode.pushSet(BlendNone);
		quad.draw();
		glState.blendMode.pop();
	}
示例#4
0
int main()
{
	sf::ContextSettings settings;
	settings.majorVersion = 4;
	settings.minorVersion = 3;
	settings.depthBits = 24;
	settings.stencilBits = 8;
	settings.antialiasingLevel = 0;

	sf::Window window(sf::VideoMode(800, 600), "SMOG Test", sf::Style::Close, settings);

	sf::ContextSettings actualSettings = window.getSettings();
	std::cout << "Window created:\n" <<
		 "\tMajor Version: " << actualSettings.majorVersion << "\n" <<
		 "\tMinor Version: " << actualSettings.minorVersion << "\n" <<
		 "\tDepth Bits   : " << actualSettings.depthBits << "\n" <<
		 "\tStencil Bits : " << actualSettings.stencilBits << "\n" <<
		 "\tAntialiasing : " << actualSettings.antialiasingLevel << std::endl;

	window.setVerticalSyncEnabled(true);

	initialiseGlew();

	sf::Vector2u windowSize = window.getSize();
	Viewport viewport(windowSize.x, windowSize.y);

	TextureCache::RegisterLoader<SFML_TextureLoader>();

	Scene scene;

//	FrameBuffer frameBuffer(800, 600);
//	frameBuffer.addTarget("diffuse", 4, Texture::UNSIGNED_BYTE_8);

	GBuffer gbuffer;

	// Scene setup
	for (int i = 0; i < 4; ++i)
	{
		SceneObject& sceneObject = scene.createSceneObject();
		RenderableComponent& rendComp = sceneObject.createComponent<RenderableComponent>();
		rendComp.renderable.reset(new Triangle);
#if 1
		rendComp.material = Material::Load("install/share/materials/textured.mtl");
#else
		std::stringstream ss;
		ss << "install/share/materials/color" << i << ".mtl";
#if 1
		rendComp.material = Material::Load(ss.str());
#else
		rendComp.material = Material::Load("install/share/materials/color.mtl");
		rendComp.material.set("color", RGB(
			(i == 0 || i == 1) ? 1.0f : 0.0f,
			(i == 0 || i == 2) ? 1.0f : 0.0f,
			(i == 0 || i == 3) ? 1.0f : 0.0f));
		rendComp.material.save(ss.str());
#endif
#endif
		sceneObject.transform().position = Vector3(
			(i % 2) ? 0.5f : -0.5f,
			(i > 1) ? 0.5f : -0.5f,
			0.0f);
		sceneObject.transform().scale = Vector3(0.5f, 0.5f, 1.0f);
	}

	Material material = Material::Load("install/share/materials/debug_gbuffer.mtl");
	Quad quad;

	

	// Main loop
	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
			{
				window.close();
				break;
			}
            else if (event.type == sf::Event::Resized)
            {
            	viewport.resize(event.size.width, event.size.height);
            }
		}

		// Update
		scene.update(0.0f);

		// Bind the frame buffer
		//frameBuffer.bind();
		gbuffer.writeTo();
		glEnable(GL_DEPTH_TEST);
		glDepthMask(true);
		glDisable(GL_BLEND);
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Draw
		for(SceneObjects::iterator sit = scene.begin(); sit != scene.end(); ++sit)
		{
			Components::iterator_range range = sit->components<RenderableComponent>();
			for(Components::iterator cit = range.begin; cit != range.end; ++cit)
			{
				cit->as<RenderableComponent>().draw();
			}
		}
		glUseProgram(0);

		//frameBuffer.unbind();
		//frameBuffer.bindForRead();

		gbuffer.readFrom();
		
		glDisable(GL_DEPTH_TEST);
		glDepthMask(false);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		material.program().use();
		//frameBuffer.bindTargets(material.program());
		material.program().set("diffuse", Texture(gbuffer.target(GBuffer::kDiffuse)));
		quad.draw();
		glUseProgram(0);

		gbuffer.finish();

		//frameBuffer.unbind();

		window.display();

#if 1
		checkGLErrors();
#endif
	}
	
	uchar pixels[800*600*4];

//	const Texture& target = frameBuffer.target("diffuse");
//	target.bind();
	uint target = gbuffer.target(GBuffer::kDiffuse);
	glBindTexture(GL_TEXTURE_2D, target);
	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels);
	glBindTexture(GL_TEXTURE_2D, 0);
//	target.unbind();

	sf::Image image;
	image.create(800, 600, pixels);
	image.saveToFile("screenshot.png");

	TextureCache::CleanUp();

#if 1
	checkGLErrors();
#endif

	return 0;
}
示例#5
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	// set some variables for the shader
	int foo[1];
	foo[0] = 0;
	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//setting the color flip variable in the shader
	mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int));

	//draw the lines
	mWVP = xLine.getWorldMatrix()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	xLine.setMTech(mTech);
	xLine.draw();
	
	mWVP = yLine.getWorldMatrix() *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	yLine.setMTech(mTech);
	yLine.draw();

	mWVP = zLine.getWorldMatrix() *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	zLine.setMTech(mTech);
	zLine.draw();

	//draw the quad using the "old" method
	//compare how messy this is compared to the objectified geometry classes
	mWVP = quad1.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad1.draw();
    }

	mWVP = quad2.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad2.draw();
    }

	mWVP = quad3.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad3.draw();
    }

	mWVP = quad4.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad4.draw();
    }

	mWVP = quad5.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad5.draw();
    }

	for(int i = 0; i < WALL_SIZE; ++i) {
		mWVP = wall[i].getWorld()*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mTech->GetDesc( &techDesc );
		for(UINT p = 0; p < techDesc.Passes; ++p)
		{
			mTech->GetPassByIndex( p )->Apply(0);
		   wall[i].draw();
		}
	}

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);
	mSwapChain->Present(0, 0);
}
示例#6
0
	void draw()
	{
		if (base.tex.tex == TEX::ID(0))
			return;

		bool windowskinValid = !nullOrDisposed(windowskin);
		bool contentsValid = !nullOrDisposed(contents);

		Vec2i trans = geo.pos() + sceneOffset;

		SimpleAlphaShader &shader = shState->shaders().simpleAlpha;
		shader.bind();
		shader.applyViewportProj();

		if (windowskinValid)
		{
			shader.setTranslation(trans);
			shader.setTexSize(Vec2i(base.tex.width, base.tex.height));

			TEX::bind(base.tex.tex);
			base.quad.draw();

			if (openness < 255)
				return;

			windowskin->bindTex(shader);

			TEX::setSmooth(true);
			ctrlVert.draw(0, ctrlQuads);
			TEX::setSmooth(false);
		}

		if (openness < 255)
			return;

		bool drawCursor = cursorVert.count() > 0 && windowskinValid;

		if (drawCursor || contentsValid)
		{
			/* Translate cliprect from local into screen space */
			IntRect clip = clipRect;
			clip.setPos(clip.pos() + trans);

			glState.scissorBox.push();
			glState.scissorTest.pushSet(true);

			if (rgssVer >= 3)
				glState.scissorBox.setIntersect(clip);
			else
				glState.scissorBox.setIntersect(IntRect(trans, geo.size()));

			IntRect pad = padRect;
			pad.setPos(pad.pos() + trans);

			if (drawCursor)
			{
				Vec2i contTrans = pad.pos();
				contTrans.x += cursorRect->x;
				contTrans.y += cursorRect->y;

				if (rgssVer >= 3)
					contTrans -= contentsOff;

				shader.setTranslation(contTrans);

				TEX::setSmooth(true);
				cursorVert.draw();
				TEX::setSmooth(false);
			}

			if (contentsValid)
			{
				if (rgssVer <= 2)
					glState.scissorBox.setIntersect(clip);

				Vec2i contTrans = pad.pos();
				contTrans -= contentsOff;
				shader.setTranslation(contTrans);

				TEX::setSmooth(false); // XXX
				contents->bindTex(shader);
				contentsQuad.draw();
			}

			glState.scissorBox.pop();
			glState.scissorTest.pop();
		}

		TEX::setSmooth(false); // XXX FIND out a way to eliminate
	}
示例#7
0
文件: bitmap.cpp 项目: Ancurio/mkxp
	void blitQuad(Quad &quad)
	{
		glState.blend.pushSet(false);
		quad.draw();
		glState.blend.pop();
	}
示例#8
0
void ColoredCubeApp::drawScene()
{
    int foo[1] = {0};
    switch (gsm->getGameState()) {
    case GameStateManager::START_GAME:
    {
        foo[0] = 1;
        break;
    }
    case GameStateManager::IN_GAME:
    {
        foo[0] = 0;
        break;
    }
    case GameStateManager::END_GAME:
    {
        foo[0] = 1;
        break;
    }
    default:
        foo[0] = 0;
        break;
    }

    mfxBlack_WhiteVar->SetRawValue(&foo[0], 0, sizeof(int));

    D3DApp::drawScene();

    // Restore default states, input layout and primitive topology
    // because mFont->DrawText changes them.  Note that we can
    // restore the default states by passing null.
    md3dDevice->OMSetDepthStencilState(0, 0);
    float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
    md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    //Get Camera viewMatrix
    mView = camera.getViewMatrix();
    mProj = camera.getProjectionMatrix();

    // set constants
    mWVP = mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);

        //mBox.draw();
        //mAxes.draw();
        //mLine.draw();
        //mTriangle.draw();
        mQuad.draw();
        //particleBox.draw();
    }

    mWVP = gameObject1.getWorldMatrix()  *mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);
    gameObject1.setMTech(mTech);
    gameObject1.draw();

    for (int i = 0; i < MAX_NUM_ENEMIES; i++)
    {
        mWVP = enemyObjects[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        enemyObjects[i].setMTech(mTech);
        enemyObjects[i].draw();
    }


    for (int i = 0; i < MAX_NUM_BULLETS; i++)
    {
        mWVP = playerBullets[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        playerBullets[i].setMTech(mTech);
        playerBullets[i].draw();
    }

    for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++)
    {
        mWVP = particles[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        particles[i].setMTech(mTech);
        particles[i].draw();
    }

    for (int i = 0; i < MAX_NUM_STARS; i++)
    {
        mWVP = stars[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        stars[i].setMTech(mTech);
        stars[i].draw();
    }

    if(gsm->getGameState() == GameStateManager::END_GAME && score > 0) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "YOU WIN!\n";
        gameOverString << "Score: " << score;
        gameOverString << "\nSpacebar to\nplay again.";
        finalScore = gameOverString.str();
        RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0};
        endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    else if(gsm->getGameState() == GameStateManager::END_GAME) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "YOU DIED!\n";
        gameOverString << "Score: " << score;
        gameOverString << "\nSpacebar to\nplay again.";
        finalScore = gameOverString.str();
        RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0};
        endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    if(gsm->getGameState() == GameStateManager::START_GAME) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "Controls:\n";
        gameOverString << "Move: A and D.\n";
        gameOverString << "Shoot: Enter \n";
        gameOverString << "Hit the spacebar to begin.";
        finalScore = gameOverString.str();
        RECT R2 = {50, GAME_HEIGHT/2 - 100, 0, 0};
        scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    else {
        if (gsm->getGameState() == GameStateManager::IN_GAME) {
            std::wostringstream scoreString;
            scoreString.precision(6);
            scoreString << score;
            finalScore = scoreString.str();
            RECT R2 = {GAME_WIDTH/2 + 50, GAME_HEIGHT + 65, 0, 0};
            scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
        }
    }


    std::wostringstream ts;
    ts.precision(6);
    ts << secondsRemaining;
    timeString = ts.str();
    RECT R3 = {GAME_WIDTH/2 + 50, 20, 0, 0};
    scoreFont->DrawText(0, timeString.c_str(), -1, &R3, DT_NOCLIP, GREEN);

    // We specify DT_NOCLIP, so we do not care about width/height of the rect.
    RECT R = {5, 5, 0, 0};
    //mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);




    mSwapChain->Present(0, 0);
}
void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    //triangle.draw();
    quad.draw();
}