//Loads and compiles vertice and fragment shaders from strings into one GLSLProgram*
GLSLProgram* ShaderManager::LoadFromStrings(std::string vertName, std::string fragName, std::string vertString, std::string fragString)
{
	GLSLProgram* prog = new GLSLProgram();

	///Compile the vertex portion of the shader
	if(!prog->compileShaderFromString(vertString, GLSLShader::VERTEX))
	{
		printf("Vertex shader failed to compile from string!\n%s", prog->log().c_str());
		assert(false && "Vertex shader failed to compile from string");
		return NULL;
	}

	///Compile the fragment portion of the shader
	if(!prog->compileShaderFromString(fragString, GLSLShader::FRAGMENT))
	{
		printf("Fragment shader failed to compile from string!\n%s", prog->log().c_str());
		assert(false && "Fragment shader failed to compile from string");
		return NULL;
	}

	///Links the shader to OpenGL using the handle obtained during the compile
	if ( !prog->link() )
	{
		printf("Shader program failed to link!\n%s", prog->log().c_str());
		assert(false && "Shader program failed to link.");
		return NULL;
	}

	assert(prog != NULL);
	return prog;
}
Example #2
0
GLSLProgram* ShaderManager::LoadFromStrings(const char* vertName, const char*fragName, std::string vertString, std::string fragString)
{
	GLSLProgram* prog = new GLSLProgram();

	if(!prog->compileShaderFromString(vertString, GLSLShader::VERTEX))
	{
		printf("Vertex shader failed to compile from string!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Vertex shader <" << vertName << "> failed to compile from string." << prog->log();
		assert(false && "Vertex shader failed to compile from string");
		return NULL;
	}

	if(!prog->compileShaderFromString(fragString, GLSLShader::FRAGMENT))
	{
		printf("Fragment shader failed to compile from string!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Fragment shader <" << fragName << "> failed to compile from string." << prog->log();
		assert(false && "Fragment shader failed to compile from string");
		return NULL;
	}

	if(!prog->link())
	{
		printf("Shader program failed to link!\n%s", prog->log().c_str());
		sLog(Level::Severe) << "Shader program failed to link." << prog->log();
		assert(false && "Shader program failed to link.");
		return NULL;
	}

	assert(prog != NULL);
	return prog;
}
Example #3
0
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
    // Black background
    glClearColor(0.0f , 0.0f , 0.0f , 1.0f );
    
    prog.compileShaderFromString (szIdentityShaderVP, GLSLShader:: VERTEX);
    prog.compileShaderFromString (szIdentityShaderFP, GLSLShader:: FRAGMENT);
    prog.link ();
    prog.use ();
    
    /////////////////// Create the VBO ////////////////////
    GLfloat positionData [] = {
        -0.8f, -0.8f , 0.0f ,
        0.8f, -0.8f, 0.0f,
        0.0f,  0.8f, 0.0f };
    
    GLfloat colorData[] = {
        1.0f, 0.0f, 0.0f,
        0.0f, 1.0f, 0.0f,
        0.0f, 0.0f, 1.0f };
    
    // Create and populate the buffer objects
    GLuint vboHandles[2];
    glGenBuffers(2, vboHandles);
    GLuint positionBufferHandle = vboHandles[0];
    GLuint colorBufferHandle = vboHandles[1];
    
    glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
    glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), positionData, GL_STATIC_DRAW);
    
    glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
    glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), colorData, GL_STATIC_DRAW);
    
    // Create and set-up the vertex array object
    glGenVertexArrays( 1, &vaoHandle );
    glBindVertexArray(vaoHandle);
    
    glEnableVertexAttribArray(0);  // Vertex position
    glEnableVertexAttribArray(1);  // Vertex color
    
    glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
    
    glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
    glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
}