Пример #1
0
GLuint createAndLoadFragmentShaderAll()
{
	const GLuint shader_handle = createFragmentShader();
	if (shader_handle == 0){ return 0; }
	{
		const char* shader_source_file_path_list[] = {
			SHADER_SOURCE_BASE_PATH "circle.frag"
		};
		const int shader_source_file_num = countof(shader_source_file_path_list);
		const GLchar** shader_source_file_list = loadShaderSource(shader_source_file_num, shader_source_file_path_list);
		if (shader_source_file_list)
		{
			glShaderSource(shader_handle, shader_source_file_num, shader_source_file_list, NULL);
			freeShaderSource(shader_source_file_num, shader_source_file_list);
			shader_source_file_list = NULL;
		}
	}
	{
		glCompileShader(shader_handle);
		{
			const GLint shader_compile_result = getShaderResult(shader_handle, GL_COMPILE_STATUS);
			if (shader_compile_result == GL_FALSE){ return 0; }
		}
	}
	return shader_handle;
}
Пример #2
0
ShaderObject::ShaderObject(char *vertexfile, char *fragmentfile)
{
	printf("%s %s\n", vertexfile, fragmentfile);
	program = glCreateProgram();
	vertexShader = glCreateShader(GL_VERTEX_SHADER);
	fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	char** vertexShaderSource = loadShaderSource(vertexfile);
	char** fragmentShaderSource = loadShaderSource(fragmentfile);
	glShaderSource(vertexShader, 1, vertexShaderSource, NULL);
	glShaderSource(fragmentShader, 1, fragmentShaderSource, NULL);
	freeShaderSource(vertexShaderSource);
	freeShaderSource(fragmentShaderSource);
	glCompileShader(vertexShader);
	glCompileShader(fragmentShader);
	shaderLog(vertexShader);
	shaderLog(fragmentShader);
	glAttachShader(program, vertexShader);
	glAttachShader(program, fragmentShader);
	glLinkProgram(program);
}