Beispiel #1
0
//This function, as its name implies, uses the passed in GL widget
void ShaderProgram::draw(GLWidget277 &f, Drawable &d)
{
    prog.bind();

    //Send the Drawable's color to the shader
    if(unifColor != -1){
        prog.setUniformValue(unifColor, la::to_qvec(d.getColor()));
    }

    // Each of the following blocks checks that:
    //   * This shader has this attribute, and
    //   * This Drawable has a vertex buffer for this attribute.
    // If so, it binds the appropriate buffers to each attribute.

    if (attrPos != -1 && d.bindPos()) {
        prog.enableAttributeArray(attrPos);
        f.glVertexAttribPointer(attrPos, 4, GL_FLOAT, false, 0, NULL);
    }

    if (attrNor != -1 && d.bindNor()) {
        prog.enableAttributeArray(attrNor);
        f.glVertexAttribPointer(attrNor, 4, GL_FLOAT, false, 0, NULL);
    }

    // Bind the index buffer and then draw shapes from it.
    // This invokes the shader program, which accesses the vertex buffers.
    d.bindIdx();
    f.glDrawElements(d.drawMode(), d.elemCount(), GL_UNSIGNED_INT, 0);

    if (attrPos != -1) prog.disableAttributeArray(attrPos);
    if (attrNor != -1) prog.disableAttributeArray(attrNor);

    f.printGLErrorLog();
}
Beispiel #2
0
void Engine::Graphics::Draw2DObject(Drawable & object){
	D3DXMATRIX transMat, scaleMat, rotMat, worldMat;

	D3DXMatrixIdentity(&transMat);
	D3DXMatrixIdentity(&scaleMat);
	D3DXMatrixIdentity(&rotMat);
	D3DXMatrixIdentity(&worldMat);

	D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
	D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
	D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
	D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
	D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

	Engine::DX::instance()->getSprite()->SetTransform(&worldMat);

	Engine::DX::instance()->getSprite()->Draw(
		getTexture(object.getHandle()),
		object.getIsSpriteSheet() ? &object.getRect() : 0,
		object.getIsSpriteSheet() ? &dVec3(object.getWidth() * 0.5f, object.getHeight() * 0.5f, 0.0f) : &dVec3(getInfo(object.getHandle()).Width *0.5f, getInfo(object.getHandle()).Height *0.5f, 0.0f),
		0,
		object.getColor());
}
Beispiel #3
0
void Engine::Text::render(Drawable &word)
{
	font->DrawText(0, word.getPlainText(), -1, &word.getRect(), DT_TOP|DT_LEFT|DT_NOCLIP, word.getColor());
}
Beispiel #4
0
void Engine::Graphics::render(Drawable object, Camera *cam)
{
	D3DXMATRIX transMat, scaleMat, rotMat, worldMat;

	D3DXMatrixIdentity(&transMat);
	D3DXMatrixIdentity(&scaleMat);
	D3DXMatrixIdentity(&rotMat);
	D3DXMatrixIdentity(&worldMat);


	if(!object.get3D())
	{
		D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
		D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
		D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
		D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

		Engine::DX::instance()->getSprite()->SetTransform(&worldMat);

		Engine::DX::instance()->getSprite()->Draw(
			getTexture(object.getHandle()),
			object.getIsSpriteSheet() ? &object.getRect() : 0,
			object.getIsSpriteSheet() ? &dVec3(object.getWidth() * 0.5f, object.getHeight() * 0.5f, 0.0f) : &dVec3(getInfo(object.getHandle()).Width *0.5f, getInfo(object.getHandle()).Height *0.5f, 0.0f),
			0,
			object.getColor());
	}

	if(object.get3D())
	{
		//camera.setLookAt(object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		//camera.setProj(800,600);

		D3DXMATRIX WIT;		

		UINT numPasses = 0;
		m_Effect->Begin(&numPasses, 0);

		Mesh *tempMesh = getMesh(object.getHandle());
		 

		for(UINT i = 0; i < numPasses; i++)
		{
			m_Effect->BeginPass(i);

			D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
			D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
			D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
			D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
			D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

			D3DXMatrixInverse(&WIT, 0, &worldMat);
			D3DXMatrixTranspose(&WIT, &WIT);
			m_Effect->SetMatrix("worldViewProjMat", &(worldMat * cam->getView() * cam->getProjection()));
			m_Effect->SetMatrix("worldInverseTransposeMat", &WIT);
			m_Effect->SetMatrix("worldMat", &worldMat);

			for(DWORD i = 0; i < tempMesh->getNumMaterials(); i++)
			{
				m_Effect->SetValue("ambientMaterial", &tempMesh->getMeshMaterial()[i].Ambient, sizeof(D3DXCOLOR));
				m_Effect->SetValue("diffuseMaterial", &tempMesh->getMeshMaterial()[i].Diffuse, sizeof(D3DXCOLOR));
				m_Effect->SetValue("specularMaterial", &tempMesh->getMeshMaterial()[i].Specular, sizeof(D3DXCOLOR));
				m_Effect->SetFloat("specularPower", tempMesh->getMeshMaterial()[i].Power);
				
				if(object.getHasTexture())
				{
					m_Effect->SetTexture("tex", tempMesh->getMeshTexture()[i]);
					m_Effect->SetBool("isTex", true);
				}else
					m_Effect->SetBool("isTex", false);

				m_Effect->CommitChanges();
				tempMesh->getMesh()->DrawSubset(i);
			}

			m_Effect->EndPass();

			//tempMesh = nullptr;
		}
		m_Effect->End();
	}
}