Exemple #1
0
void Renderer::ChangeShaders()
{
	CleanShaders();
	
	QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
	QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
	//QOpenGLShader *gshader = new QOpenGLShader(QOpenGLShader::Geometry, this);

	bool compiled = ReadShader(vshader, "shaders\\vertexShader.ogl");
	//compiled &= ReadShader(gshader, "shaders\\geometryShader.ogl");
	compiled &= ReadShader(fshader, "shaders\\fragmentShader.ogl");

	if (!compiled)
		return;

	makeCurrent();
	CreateModels();

	_shaderProgram = new QOpenGLShaderProgram;
	_shaderProgram->addShader(vshader);
	//_shaderProgram->addShader(gshader);
	_shaderProgram->addShader(fshader);

	_shaderProgram->bindAttributeLocation("vertexPosition_modelspace", VERTEX_LOCATION);
	_shaderProgram->bindAttributeLocation("vertexNormal_modelspace", NORMAL_LOCATION);
	_shaderProgram->bindAttributeLocation("barycentric", BARYCENTRIC_LOCATION);

	// vertdata + normals
	bool vbocreated = _vertexBuffer.create();
	int vbSize = 0;
	DoAssert(vbocreated);
	bool vbobound = _vertexBuffer.bind();
	DoAssert(vbobound);
	_indicesBuffer.create();
	std::vector<GLfloat> vertexNormal;
	std::vector<int> indices;
	for (int i = 0; i < _renderData.size(); i++)
	{
		_renderData[i]._mesh.GetVertexNormal(vertexNormal);
		_renderData[i]._mesh.GetIndices(indices);
	}
	_vertexBuffer.allocate(vertexNormal.data(), vertexNormal.size() * sizeof(GLfloat));
	_indicesBuffer.bind();
	_indicesBuffer.allocate(indices.data(), indices.size() * sizeof(GLint));
	_indices = indices.size();

	if (!_shaderProgram->link())
	{
		QString eeror = _shaderProgram->log();
		emit reportSignal(MError, eeror);
		delete _shaderProgram;
		_shaderProgram = NULL;
		return;
	}
	_shaderProgram->bind();
	update();
}
Exemple #2
0
//----------------------------------------------------------------------------
void Lighting::CreateScene()
{
    m_spScene = SE_NEW SENode;
    m_spWireframe = SE_NEW SEWireframeState;
    m_spScene->AttachGlobalState(m_spWireframe);

    CreateLights();
    CreateModels();

    m_spModelRoot->AttachLight(m_spLight0);
    m_spModelRoot->AttachLight(m_spLight1);
    m_spScene->AttachChild(m_spLight0Node);
    m_spScene->AttachChild(m_spLight1Node);
    m_spScene->AttachChild(m_spModelRoot);

    m_spScene->UpdateGS();
    m_spScene->UpdateRS();
}
Exemple #3
0
//----------------------------------------------------------------------------
void Lighting2::CreateScene()
{
    m_spScene = SE_NEW SENode;
    m_spWireframe = SE_NEW SEWireframeState;
    m_spScene->AttachGlobalState(m_spWireframe);

    SEMatrix3f mat3fR;
    mat3fR.FromAxisAngle(SEVector3f::UNIT_Z, -SEMathf::HALF_PI);
    m_spScene->Local.SetRotate(mat3fR);
    m_spScene->Local.SetTranslate(SEVector3f(-5.0f, 0.0f, 0.0f));

    CreateLights();
    CreateModels();

    m_spModelRoot->AttachLight(m_spLight0);
    m_spModelRoot->AttachLight(m_spLight1);
    m_spScene->AttachChild(m_spLight0Node);
    m_spScene->AttachChild(m_spLight1Node);
    m_spScene->AttachChild(m_spModelRoot);

    m_spScene->UpdateGS();
    m_spScene->UpdateRS();
}