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


C++ ShaderProgram::addShader方法代码示例

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


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

示例1: GenerateShaders

void GenerateShaders( ) {
    //  Shaders
    try {
        vertex_shader.SourceFile("../shaders/diffuse_shading.vert");
        fragment_shader.SourceFile("../shaders/diffuse_shading.frag");
        vertex_shader.Compile();
        fragment_shader.Compile();
        diffuse_shading.addShader(vertex_shader.GetHandle());
        diffuse_shading.addShader(fragment_shader.GetHandle());
        diffuse_shading.link();
        diffuse_shading.unuse();
    }
    catch (ShaderProgramException excp) {
        cerr << excp.what () << endl;
        exit (EXIT_FAILURE);
    }

    try {
        ads_vertex_shader.SourceFile("../shaders/ads_shading.vert");
        ads_fragment_shader.SourceFile("../shaders/ads_shading.frag");
        ads_vertex_shader.Compile();
        ads_fragment_shader.Compile();
        ads_shading.addShader(ads_vertex_shader.GetHandle());
        ads_shading.addShader(ads_fragment_shader.GetHandle());
        ads_shading.link();
        ads_shading.unuse();
        ads_shading.printActiveUniforms();
    }
    catch (ShaderProgramException excp) {
        cerr << excp.what() << endl;
        exit (EXIT_FAILURE);
    }

//    global_shader = &diffuse_shading;
    global_shader = &ads_shading;
}
开发者ID:juantresde,项目名称:opengl,代码行数:36,代码来源:exj_5.cpp

示例2: main

int main( void )
{
	for (int i=0; i<NUM_CIRCLE_VERTICES; i++) {
		float f = i * 2*M_PI / NUM_CIRCLE_VERTICES;
		g_vertex_buffer_data[3*i] = cos(f)+2.0f;
		g_vertex_buffer_data[3*i+1] = sin(f);
		g_vertex_buffer_data[3*i+2] = 0.0f;
	}

	// Initialise GLFW
	if( !glfwInit() )
	{
		fprintf( stderr, "Failed to initialize GLFW\n" );
		return -1;
	}

	glfwWindowHint(GLFW_SAMPLES, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	// Open a window and create its OpenGL context
	window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
	if( window == NULL ){
		GLenum error = glGetError();
		if (error != GL_NO_ERROR)
		{
			fprintf(stderr, "-1 OpenGL Error: %d\n", error);
		}
		fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);

	GLenum error = glGetError();
	if (error != GL_NO_ERROR)
	{
	    fprintf(stderr, "-1 OpenGL Error: %d\n", error);
	}

	glewExperimental = GL_TRUE;
	// Initialize GLEW
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		return -1;
	}


	error = glGetError();
	if (error != GL_NO_ERROR)
	{
	    fprintf(stderr, "0 OpenGL Error: %d\n", error);
	}

	// Ensure we can capture the escape key being pressed below
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

	// Dark blue background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
	
	
	GLuint VertexArrayID;
	glGenVertexArrays(1, &VertexArrayID);
	glBindVertexArray(VertexArrayID);
	
	//glEnable (GL_BLEND);
	//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// This will identify our vertex buffer
	GLuint vertexbuffer;
	 
	// Generate 1 buffer, put the resulting identifier in vertexbuffer
	glGenBuffers(1, &vertexbuffer);
	 
	// The following commands will talk about our 'vertexbuffer' buffer
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	 
	// Give our vertices to OpenGL.
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

	// load shaders
	ShaderProgram shaderProgram;
	shaderProgram.addShader(GL_VERTEX_SHADER, "vertex");
	shaderProgram.addShader(GL_FRAGMENT_SHADER, "fragment");
	shaderProgram.addShader(GL_GEOMETRY_SHADER, "geometry");
	GLuint shader = shaderProgram.finalize();
	
	// matrices
	glm::mat4 projection = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
	glm::mat4 view       = glm::lookAt(
		glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space
		glm::vec3(0,0,0), // and looks at the origin
		glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
	);
	glm::mat4 MVP0 = projection * view;
	
	glm::vec4 x_vec = MVP0 * glm::vec4(1.0f,0.0f,0.0f,1.0f);
	glm::vec4 z_vec = MVP0 * glm::vec4(0.0f,0.0f,1.0f,1.0f);

//.........这里部分代码省略.........
开发者ID:theleftmostguy,项目名称:opengl_lecture,代码行数:101,代码来源:playground.cpp

示例3: main

int main(int argc, char* argv[]) {
    System::init();
    
    /*
     * Byte buffer
     *
     */
    ByteBuffer buffer(5);
    char abc[4] = "abc";
    buffer.write(abc,3);
    buffer.reset();
    buffer.resize(3,true);
    printf("%c\n",buffer.readByte());
    printf("%c\n",buffer.readByte());
    printf("%c\n",buffer.readByte());
    buffer.reset();

    /*
     * Canvas
     */
    Canvas canvas(640,480);
    if (!canvas.getSurface()) {
        return -1;
    }

    Thread thread("test thread", &testFunc, (void*)NULL);

    /*
     * Json Reader.
     */
    JsonReader reader;
    reader.read("res/config.json");
    Json::Value value = reader.getRoot();
    std::cout << reader.getRoot().get("verson", "1.2") << std::endl;

    JsonWriter writer;
    writer.write("res/1.json", reader.getRoot(), true);
    writer.write("res/2.json", reader.getRoot(), false);

    Shader vertex("res/shaders/vertex.glsl",Shader::ShaderType::VERTEX_SHADER);
    Shader fragment("res/shaders/fragment.glsl",Shader::ShaderType::FRAGMENT_SHADER);
    ShaderProgram shaderProgram;
    shaderProgram.addShader(&vertex);
    shaderProgram.addShader(&fragment);
    shaderProgram.link();

    Shader vertexRadialBlur("res/shaders/radialblur_vertex.glsl",Shader::ShaderType::VERTEX_SHADER);
    Shader fragmentRadialBlur("res/shaders/radialblur_fragment.glsl",Shader::ShaderType::FRAGMENT_SHADER);
    ShaderProgram radialBlur;
    radialBlur.addShader(&vertexRadialBlur);
    radialBlur.addShader(&fragmentRadialBlur);
    radialBlur.link();

    ResourcesManager resourcesManager;
    resourcesManager.loadTexture("lama1","res/lama1.png");
    resourcesManager.loadTexture("spritesheet","res/ch.png");
    resourcesManager.loadTexture("courrier","res/courrier_0.png");
    
    Sprite sprite2(resourcesManager.getTexture("lama1"));

    Rect<float> texCoords[] = { Rect<float>(32,0,32,32), Rect<float>(0,0,32,32), Rect<float>(32,0,32,32), Rect<float>(64,0,32,32)};
    unsigned int durations[] = { 100, 100, 100, 100 };
    Sprite sprite(resourcesManager.getTexture("spritesheet"));
    sprite.addAnimation("down", 4, durations, texCoords);
    sprite.setSize(128,128);
    sprite.setAnimation("down");

    SimpleScene2D scene2D(640,480);

    shared_ptr<SceneNode> node = shared_ptr<SceneNode>(new SceneNode(&vertex,&fragment));
    scene2D.addNode(node);

    for (int i = 0; i < 1; i++)
    {
        shared_ptr<SpriteActor> s = shared_ptr<SpriteActor>(new SpriteActor(sprite2));
        if (s)
        {
            node->addActor(s);
        }
    }
    node->addActor(shared_ptr<SpriteActor>(new SpriteActor(sprite)));

    BMFontReader fontReader("res/courrier.fnt");
    FontActorCreator fontActorCreator(resourcesManager,fontReader.read());
    shared_ptr<FontActor> fontActor = fontActorCreator.createFontActor("courrier", "This IS A TEXT TEST ! Hehehe", 1, 2, 2.0f, Vector4d<float>(0.2f,0.5f,1.0f,0.2f));
    node->addActor(fontActor);

    /*
    for (int i = 0; i < 5000; i++)
    {
        shared_ptr<SpriteActor> s = shared_ptr<SpriteActor>(new SpriteActor(sprite));
        if (s)
        {
            node->addActor(s);
        }
    }
    */

    InputDevicesManager& idm = canvas.getInputDevicesManager();

//.........这里部分代码省略.........
开发者ID:remeh,项目名称:mehteor,代码行数:101,代码来源:main.cpp


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