ShaderColorInstanced::ShaderColorInstanced(CL_GraphicContext &gc)
{
	CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex);
	if(!vertex_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment);
	if(!fragment_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	program_object = CL_ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	program_object.bind_attribute_location(1, "InNormal");
	if (!program_object.link())
	{
		throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log()));
	}

	material_updated = false;
	light_updated = false;

	material_shininess = 64.0f;
	material_emission = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f);

	light_vector = CL_Vec4f(0.0f, 0.0f, 1.0f, 0.0f);
	light_specular = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f);
	light_diffuse = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f);
}
Example #2
0
ShaderDepth::ShaderDepth(CL_GraphicContext &gc)
{
	CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex);
	if(!vertex_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment);
	if(!fragment_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	program_object = CL_ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	if (!program_object.link())
	{
		throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log()));
	}

	material_updated = false;

	material_ambient =  CL_Vec4f(0.9f, 0.2f, 0.2f, 1.0f);

}
Example #3
0
void ShaderImpl::initialize(CL_GraphicContext &p_gc)
{
	G_ASSERT(!m_initialized);

	CL_ResourceManager *resMgr = Gfx::Stage::getResourceManager();

	m_program = CL_ProgramObject(p_gc);

	// load vertex shader
	const CL_String &vertShaderName = m_parent->getVertexShaderResourceName();
	m_vertShader = CL_ShaderObject::load(p_gc, vertShaderName, resMgr);
	m_program.attach(m_vertShader);

	// load fragment shader
	const CL_String &fragShaderName = m_parent->getFragmentShaderResourceName();
	m_fragShader = CL_ShaderObject::load(p_gc, fragShaderName, resMgr);
	m_program.attach(m_fragShader);

	// bind common attributes
	m_program.bind_attribute_location(CL_PRIARR_VERTS, "Position");
	m_program.bind_attribute_location(CL_PRIARR_COLORS, "Color0");
	m_program.bind_attribute_location(CL_PRIARR_TEXCOORDS, "TexCoord0");

	// link the program
	if (!m_program.link()) {
		m_program.detach(m_vertShader);
		m_program.detach(m_fragShader);

		throw CL_Exception(
				cl_format(
						"error linking shader %1, %2: %3",
						vertShaderName, fragShaderName,
						m_program.get_info_log()
				)
		);
	}

	// build frame buffer
	m_frameBuffer = CL_FrameBuffer(p_gc);

	// build quad
	m_quad = CL_PrimitivesArray(p_gc);
	m_quad.set_attributes(CL_PRIARR_VERTS, m_quadVerts);
	m_quad.set_attributes(CL_PRIARR_COLORS, QUAD_COLORS);
	m_quad.set_attributes(CL_PRIARR_TEXCOORDS, QUAD_TEX_COORDS);

	m_initialized = true;
}
Example #4
0
void ShaderImpl::destroy()
{
	G_ASSERT(m_initialized);

	m_quad = CL_PrimitivesArray();
	m_frameBuffer = CL_FrameBuffer();

	m_program.detach(m_vertShader);
	m_program.detach(m_fragShader);

	m_vertShader = CL_ShaderObject();
	m_fragShader = CL_ShaderObject();

	m_program = CL_ProgramObject();

	m_initialized = false;
}
ShaderColorGeometry::ShaderColorGeometry(CL_GraphicContext &gc)
{
	CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex);
	if(!vertex_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	CL_ShaderObject geometry_shader(gc, cl_shadertype_geometry, geometry);
	if(!geometry_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile geometry shader object: %1", geometry_shader.get_info_log()));
	}

	if (!glProgramParameteri)
		throw CL_Exception("Geomtry shader is not available");

	CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment);
	if(!fragment_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	program_object = CL_ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(geometry_shader);
	program_object.attach(fragment_shader);
	program_object.bind_attribute_location(0, "InPosition");
	program_object.bind_attribute_location(1, "InColor");
	program_object.bind_frag_data_location(0, "cl_FragColor");

	if (!program_object.link())
	{
		throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log()));
	}
	
	program_object.set_uniform1i("Texture0", 0);

}
Example #6
0
Shader::Shader(CL_GraphicContext &gc)
{
	CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex);
	if(!vertex_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log()));
	}

	CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment);
	if(!fragment_shader.compile())
	{
		throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log()));
	}

	program_object = CL_ProgramObject(gc);
	program_object.attach(vertex_shader);
	program_object.attach(fragment_shader);

	program_object.bind_attribute_location(cl_attrib_position, "InPosition");
	program_object.bind_attribute_location(cl_attrib_normal, "InNormal");
	program_object.bind_attribute_location(cl_attrib_color, "InMaterialAmbient");
	program_object.bind_attribute_location(cl_attrib_texture_position, "InTextureCoords");
	if (!program_object.link())
	{
		throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log()));
	}

	material_shininess = 64.0f;
	material_emission = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
	material_specular = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f);

	light_position = CL_Vec3f(0.0f, 0.0f, 1.0f);
	light_specular = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f);
	light_diffuse = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f);


}