当前位置: 首页>>代码示例>>C++>>正文


C++ Shader::Init方法代码示例

本文整理汇总了C++中Shader::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::Init方法的具体用法?C++ Shader::Init怎么用?C++ Shader::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shader的用法示例。


在下文中一共展示了Shader::Init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Init

bool Res::Init() {
	Shader* shader = nullptr;
	Texture* texture = nullptr;

	// block shader
	shader = new Shader();
	if (!shader->Init("res/block.vert", "res/block.frag")) return false;
	AddShader("block", shader);

	// simpler color shader
	shader = new Shader();
	if (!shader->Init("res/color.vert", "res/color.frag")) return false;
	AddShader("color", shader);


	std::vector<byte> buffer, image;
	LodePNG::loadFile(buffer, "res/blocks.png");
	LodePNG::Decoder decoder;
	decoder.decode(image, buffer);

	int dim = decoder.getWidth();

	texture = Texture::Create3DTexture(dim, dim, decoder.getHeight() / dim, image.data());
	AddTexture("blocks", texture);

	return true;
}
开发者ID:xunatai,项目名称:cubiverse,代码行数:27,代码来源:Res.cpp

示例2: CreateProgram

ShaderManager::Shader* ShaderManager::CreateProgram( int flags )
{
	static const int LEN = 200;
	char buf[LEN];
	int outLen = 0;

	for( int i=0; i<shaderArr.Size(); ++i ) {
		if ( shaderArr[i].prog && shaderArr[i].flags == flags ) {
			return &shaderArr[i];
		}
		if ( shaderArr[i].prog == 0 ) {
			break;
		}
	}

	Shader* shader = shaderArr.Push();
	shader->Init();
	shader->flags = flags;

	shader->vertexProg = glCreateShader( GL_VERTEX_SHADER );
	shader->fragmentProg = glCreateShader( GL_FRAGMENT_SHADER );

	header = "";
	AppendFlag( &header, "TEXTURE0",			flags & TEXTURE0 );
	AppendFlag( &header, "TEXTURE0_ALPHA_ONLY",	flags & TEXTURE0_ALPHA_ONLY );
	AppendFlag( &header, "TEXTURE0_TRANSFORM",	flags & TEXTURE0_TRANSFORM );
	AppendFlag( &header, "TEXTURE0_3COMP",		flags & TEXTURE0_3COMP );
	
	AppendFlag( &header, "TEXTURE1",			flags & TEXTURE1 );
	AppendFlag( &header, "TEXTURE1_ALPHA_ONLY",	flags & TEXTURE1_ALPHA_ONLY );
	AppendFlag( &header, "TEXTURE1_TRANSFORM",	flags & TEXTURE1_TRANSFORM );
	AppendFlag( &header, "TEXTURE1_3COMP",		flags & TEXTURE1_3COMP );
	
	AppendFlag( &header, "COLORS",				flags & COLORS );
	AppendFlag( &header, "COLOR_MULTIPLIER",	flags & COLOR_MULTIPLIER );
	AppendFlag( &header, "LIGHTING_DIFFUSE",	flags & LIGHTING_DIFFUSE );	

	const char* vertexSrc[2] = { header.c_str(), fixedpipe_vert };
	glShaderSource( shader->vertexProg, 2, vertexSrc, 0 );
	glCompileShader( shader->vertexProg );
	glGetShaderInfoLog( shader->vertexProg, LEN, &outLen, buf );
	if ( outLen > 0 ) {
		GLOUTPUT(( "Vertex %d:\n%s\n", flags, buf ));
	}
	CHECK_GL_ERROR;

	const char* fragmentSrc[2] = { header.c_str(), fixedpipe_frag };
	glShaderSource( shader->fragmentProg, 2, fragmentSrc, 0 );
	glCompileShader( shader->fragmentProg );
	glGetShaderInfoLog( shader->fragmentProg, LEN, &outLen, buf );
	if ( outLen > 0 ) {
		GLOUTPUT(( "Fragment %d:\n%s\n", flags, buf ));
	}
	CHECK_GL_ERROR;

	shader->prog = glCreateProgram();
	glAttachShader( shader->prog, shader->vertexProg );
	glAttachShader( shader->prog, shader->fragmentProg );
	glLinkProgram( shader->prog );
	glGetProgramInfoLog( shader->prog, LEN, &outLen, buf );
	if ( outLen > 0 ) {
		GLOUTPUT(( "Link %d:\n%s\n", flags, buf ));
	}
	CHECK_GL_ERROR;

	// glUseProgram
	return shader;
}
开发者ID:chrisBGithub,项目名称:unflobtactical,代码行数:68,代码来源:shadermanager.cpp

示例3: main

int main(int argc, char **argv) {
	atexit(cleanup);
    // parse arguments
    char *model_path = NULL;
    char *vertexshader_path = NULL;
    char *fragmentshader_path = NULL;
    char *texture_path = NULL;
    bool use_smoothed_normals;
    if (argc >= 6) {
        texture_path = argv[5];
        useTexture = 1;
    }
	if (argc >= 5) {
        model_path = argv[1];
        vertexshader_path = argv[2];
        fragmentshader_path = argv[3];
        use_smoothed_normals = *argv[4] != '0';
	} else {
        std::cerr << "Usage:" << std::endl;
        std::cerr << argv[0]
             << " <model::path> "
             << " <vertex-shader::path> "
             << " <fragment-shader::path> "
             << " <smooth-normals::{0,1}>"
             << " (<texture::path>)"
             << std::endl;
		exit(1);
	}
	// initialise OpenGL
	glutInit(&argc, argv);
	glutInitWindowSize(windowX, windowY);
	glutCreateWindow("CG-CW1");
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glEnable(GL_DEPTH_TEST);
    // set display and keyboard callbacks
	glutDisplayFunc(display_handler);
    glutKeyboardFunc(keyboard_handler);
	// initialise the OpenGL Extension Wrangler library for VBOs
	GLenum err = glewInit();
	if (err != GLEW_OK){
        std::cerr << "Error!" << std::endl;
		exit(1);
	}
	if (!GLEW_VERSION_2_1) {
        std::cerr << "Error 2.1!" << std::endl;
		exit(1);
	}
	// create shader, prepare data for OpenGL
    trig.LoadFile(model_path);
	shader.Init(vertexshader_path, fragmentshader_path);
    setup_texture(texture_path, &textureID);
	setup_vertex_position_buffer_object();
	setup_vertex_uv_buffer_object();
    setup_vertex_normal_buffer_object(use_smoothed_normals);
	// set up camera and object transformation matrices
	projectionMatrix = get_default_projectionMatrix();
	viewMatrix = get_default_viewMatrix();
	modelMatrix = get_default_modelMatrix();
    normalMatrix = get_default_normalMatrix();
	glutMainLoop();
}
开发者ID:c-w,项目名称:ug4_Shaders,代码行数:61,代码来源:main.cpp


注:本文中的Shader::Init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。