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


C++ Program::bind方法代码示例

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


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

示例1: onFrame

  void onFrame() {

    if (camera.isTransformed) {
      camera.transform();
    }

    glViewport(0, 0, width, height);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cmt.bind(GL_TEXTURE0); {

      skyboxProgram.bind(); {
        glUniformMatrix4fv(skyboxProgram.uniform("view"), 1, 0, ptr(camera.view));
        glUniformMatrix4fv(skyboxProgram.uniform("proj"), 1, 0, ptr(camera.projection));
        glUniform1i(skyboxProgram.uniform("cube_texture"), 0);

        skyboxMeshBuffer.draw();
      } skyboxProgram.unbind();

      vec3 totals = rotateBehavior.tick(now()).totals();
      cubeModel = glm::mat4();
      cubeModel = glm::translate(cubeModel, vec3(12.0,0.0,40.0));
      cubeModel = glm::rotate(cubeModel, totals.x, vec3(1.0f,0.0f,0.0f));
      cubeModel = glm::rotate(cubeModel, totals.y, vec3(0.0f,1.0f,0.0f));

      dragonModel = glm::mat4();
      dragonModel = glm::translate(dragonModel, vec3(-12.0,-15.0,40.0));
      dragonModel = glm::rotate(dragonModel, totals.y, vec3(0.0f,1.0f,0.0f));


      environmentMappingProgram.bind(); {
        glUniformMatrix4fv(environmentMappingProgram.uniform("view"), 1, 0, ptr(camera.view));
        glUniformMatrix4fv(environmentMappingProgram.uniform("proj"), 1, 0, ptr(camera.projection));
        glUniform1i(environmentMappingProgram.uniform("cube_texture"), 0);

        //set dragon specific variables and draw dragon
        glUniformMatrix4fv(environmentMappingProgram.uniform("model"), 1, 0, ptr(dragonModel));
        glUniform4f(environmentMappingProgram.uniform("baseColor"), 0.0, 0.0, 0.1, 1.0);
        dragonMeshBuffer.draw();

        //set cube specific variables and draw cube
        glUniformMatrix4fv(environmentMappingProgram.uniform("model"), 1, 0, ptr(cubeModel));
        glUniform4f(environmentMappingProgram.uniform("baseColor"), 0.1, 0.0, 0.0, 1.0);
        cubeMeshBuffer.draw();
      } environmentMappingProgram.unbind();

    } cmt.unbind(GL_TEXTURE0);

  }
开发者ID:CreativeCodingLab,项目名称:aluminum,代码行数:49,代码来源:SkyBox.cpp

示例2: sizeof

	virtual	void	redisplay ()
	{
		static	GLuint	buf [] = { 0, 0, 0, 0 };
		static	GLuint	counters [4];
		
		counterBuf.setData ( sizeof ( buf ), buf, GL_DYNAMIC_DRAW );
		
		glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

		mat4	mv = mat4 :: rotateZ ( toRadians ( rot.z ) ) * mat4 :: rotateY ( toRadians ( rot.y ) ) * mat4 :: rotateX ( toRadians ( rot.x ) );
		mat3	nm = normalMatrix ( mv );
		
		program.bind ();
		program.setUniformMatrix ( "mv",  mv );
		program.setUniformMatrix ( "nm",  nm );

		mesh -> render ();

		program.unbind ();
		
		glFinish ();
		
		counterBuf.getSubData ( 0, sizeof ( buf ), counters );
		
		printf ( "%4d %4d %d %d\n", counters [0], counters [1], counters [2], counters [3] );
	}
开发者ID:galek,项目名称:steps-framework,代码行数:26,代码来源:atomic-counters.cpp

示例3: SDLLoop

	MyCaveGeneratorTestLoop(Window *w) : SDLLoop(w) 
	{
		cout << "Initializing glew\n";
		glewInit();

		cout << "Binding program\n";
		program.addShader(Shader(GL_VERTEX_SHADER, "functional/phong/shader.vp"));
		program.addShader(Shader(GL_FRAGMENT_SHADER, "functional/phong/shader.fp"));
		program.link();
		program.bind();
		
		cout << "Getting locations of shader parameters\n";
		vertexLocation = program.getAttributeLocation("vPosition");
		texCoordLocation = program.getAttributeLocation("uv");
		vertexColorLocation = program.getAttributeLocation("vColor");
		samplerLocation = program.getUniformLocation("image");
		modelLocation = program.getUniformLocation("model");
		perspectiveLocation= program.getUniformLocation("perspective");
		normalLocation = program.getAttributeLocation("Normal");
		ambientProductLocation = program.getUniformLocation("ambientProduct");
		diffuseProductLocation = program.getUniformLocation("diffuseProduct");
		specularProductLocation = program.getUniformLocation("specularProduct");
		lightPositionLocation = program.getUniformLocation("LightPosition");
		shininessLocation = program.getUniformLocation("shininess");
		
		program.enableAttributeArray(vertexLocation);
		program.enableAttributeArray(texCoordLocation);
		program.enableAttributeArray(vertexColorLocation);
		program.enableAttributeArray(normalLocation);
		
		signal = new PerlinSignal;
		signal->addFrequency(2, 0.2);
		signal->addFrequency(16, 0.01);
	}
开发者ID:fantastic001,项目名称:Height3D,代码行数:34,代码来源:cave_generator.cpp

示例4: onFrame

	//onFrame syncs with the refresh rate of the display (e.g., 60fps). Here we can send information to the GPU to define exactly how the pixels on the window should look.
	virtual void onFrame(){

		glViewport(0, 0, width, height); //defines the active viewport to match the size of our window
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clears color and depth info from the viewport
		glEnable(GL_DEPTH_TEST);
		glDisable(GL_BLEND);

		//have the pyramid to rotate in place
		m = glm::rotate(m, rx, vec3(1.0f, 0.0f, 0.0f));
		m = glm::rotate(m, ry, vec3(0.0f, 1.0f, 0.0f));

		//update the view matrix based on the camera's rotation
		v = mat4(1.0); //reset to identity
		v = glm::rotate(v, cx, vec3(1.0f, 0.0f, 0.0f)); //rotate sum amount around the x-axis
		v = glm::rotate(v, cy, vec3(0.0f, 1.0f, 0.0f)); //rotate sum amount around the y-axis
		v = glm::translate(v, vec3(0, 0, pz)); //translate the "cursor" forward five units ( = move the camera five units backwards)


		// the program.bind() activates our shader program so that we can 1. pass data to it and 2. let it draw to the active viewport in our window
		program.bind(); {

			glUniformMatrix4fv(program.uniform("m"), 1, 0, ptr(m)); //pass in the model matrix
			glUniformMatrix4fv(program.uniform("v"), 1, 0, ptr(v)); //pass in the view matrix
			glUniformMatrix4fv(program.uniform("p"), 1, 0, ptr(p)); //pass in the projection matrix

			glBindVertexArray(vao); //binds our vertex array object, containing all our data and information about how it's organized and indexed
			glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); //passes the entire data buffer to the GPU as a set of triangles; that is, read the index array three items at a time.

			glBindVertexArray(0);
		} program.unbind();

	}
开发者ID:CreativeCodingLab,项目名称:aluminum,代码行数:33,代码来源:Transformation.cpp

示例5: onFrame

 void onFrame(){
   
   model = glm::mat4(1.0);
   
   vec3 totals = rotateBehavior.tick(now()).totals();
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   
   //draw cube 1 into an offscreen texture
   fbo.bind(); {
     glViewport(0, 0, fbo.width, fbo.height);
     glClearColor(0.1,0.1,0.1,1.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     draw(model, cubeMeshBuffer1, texture, textureProgram);
     
   } fbo.unbind();
   
   
   //draw cube 2 with the offscreen texture using phong shading
   glViewport(0, 0, width, height);
   glClearColor(0.0,0.0,0.0,1.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   model = glm::mat4(1.0);
   
   model = glm::translate(model, vec3(1.0,0.0,0.0));
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   draw(model, cubeMeshBuffer2, fbo.texture, phongProgram);
   
   
   
   //draw cube 3 - a colored cube
   
   model = mat4(1.0);
   model = glm::translate(model, vec3(-1.0,0.0,0.0));
   
   model = glm::rotate(model, -totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, -totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, -totals.z, vec3(0.0f,0.0f,1.0f));
   
   programColor.bind(); {
     glUniformMatrix4fv(programColor.uniform("model"), 1, 0, ptr(model));
     glUniformMatrix4fv(programColor.uniform("view"), 1, 0, ptr(view));
     glUniformMatrix4fv(programColor.uniform("proj"), 1, 0, ptr(proj));
     
     cubeMeshBuffer3.draw();
     
   } programColor.unbind();
   
 }
开发者ID:CreativeCodingLab,项目名称:aluminum,代码行数:56,代码来源:FBOExample.cpp

示例6: uploadFullscreenQuad

 void uploadFullscreenQuad(const Program & sp) {
     sp.bind();
     float quad[] = {
         -1.0f,  1.0f, 0.0f, 1.0f,	// top left corner
         -1.0f, -1.0f, 0.0f, 0.0f,	// bottom left corner
          1.0f,  1.0f, 1.0f, 1.0f,// top right corner
          1.0f, -1.0f, 1.0f, 0.0f	// bottom right corner
     };
     sp.uploadData(quad, sizeof(quad));
 }
开发者ID:phaikawl,项目名称:nxvg,代码行数:10,代码来源:context.cpp

示例7: paint

void PrimitiveShape::paint()
{
    VertexBuffer* vb = m_vertexbuffer;
    // IndexBuffer* ib = m_indexbuffer;
    Program* pr = m_program;
    if( !vb || !pr )
    {
        return;
    }
    size_t vertexcount;
    VertexDeclaration* vdecl;
    if( !vb->bind( &vertexcount, &vdecl ) )
    {
        return;
    }
    // int indexcount;
    // if( ib )
    // {
    // if( !ib->bind( &indexcount ) )
    // {
    // return;
    // }
    // }
    if( !pr->bind() )
    {
        return;
    }
    int ptype = m_type.load( std::memory_order_acquire );
    checkerror( Context::Device->SetRenderState(
                    D3DRS_BLENDOP, m_blendop ) );
    checkerror( Context::Device->SetRenderState(
                    D3DRS_SRCBLEND, m_blendsf ) );
    checkerror( Context::Device->SetRenderState(
                    D3DRS_DESTBLEND, m_blenddf ) );
    {
        lock_t lock( m_mutex );
        checkerror( Context::Device->SetVertexShaderConstantF(
                        0, m_matrix.m[ 0 ], 4 ) );
    }
    // checkerror( Context::Device->DrawIndexedPrimitive(
    // D3DPRIMITIVETYPE( m_type ),
    // 0,
    // 0,
    // vertexcount,
    // 0,
    // indexcount / 3 ) );
    checkerror( Context::Device->DrawPrimitive(
                    D3DPRIMITIVETYPE( typetable[ ptype ] ),
                    0,
                    UINT( ( vertexcount - poffsettable[ ptype ] )
                          / pfactortable[ ptype ] ) ) );
}
开发者ID:delfigamer,项目名称:mist,代码行数:52,代码来源:primitiveshape.cpp

示例8: perspective

	virtual	void	reshape ( int w, int h )
	{
		GlutWindow::reshape ( w, h );
		
		glViewport ( 0, 0, (GLsizei)w, (GLsizei)h );
	   
		mat4 proj = perspective ( 60.0f, (float)w / (float)h, 0.5f, 20.0f ) * lookAt ( eye, vec3 :: zero, vec3 ( 0, 0, 1 ) );

		program.bind ();
		program.setUniformMatrix ( "proj",  proj );
		program.setUniformVector ( "eye",   eye );
		program.setUniformVector ( "light", light );
		program.unbind ();  
	}
开发者ID:galek,项目名称:steps-framework,代码行数:14,代码来源:atomic-counters.cpp

示例9: bind_prog_and_attributes

void bind_prog_and_attributes(const VertexFormat& vf, const Program& program)
{
	program.bind();

	for (auto&& vc : vf) {
		const auto attrib_loc = program.get_attribute_loc(vc.name);

		CHECK_FOR_GL_ERROR;
		glEnableVertexAttribArray(attrib_loc);
		CHECK_FOR_GL_ERROR;
		glVertexAttribPointer(attrib_loc, vc.num_comps, vc.type, vc.normalize, (GLsizei)vf.stride(), (const void*)vc.offset);
		CHECK_FOR_GL_ERROR;
	}
}
开发者ID:csulmone,项目名称:emilib,代码行数:14,代码来源:gl_lib.cpp

示例10: getTime

	virtual	void	idle () 
	{
		angle  = 4 * getTime ();

		light.x = 8*cos ( angle );
		light.y = 8*sin ( 1.4 * angle );
		light.z = 8 + 0.5 * sin ( angle / 3 );

		program.bind ();
		program.setUniformVector ( "eye",   eye   );
		program.setUniformVector ( "light", light );
		program.unbind ();

		GlutWindow::idle ();		// for glutPostRedisplay ();
	}
开发者ID:galek,项目名称:steps-framework,代码行数:15,代码来源:atomic-counters.cpp

示例11: draw

 void draw(mat4& model, MeshBuffer& mb, Texture& t, Program& p) {
   
   p.bind(); {
     glUniformMatrix4fv(p.uniform("model"), 1, 0, ptr(model));
     glUniformMatrix4fv(p.uniform("view"), 1, 0, ptr(view));
     glUniformMatrix4fv(p.uniform("proj"), 1, 0, ptr(proj));
     
     t.bind(GL_TEXTURE0); {
       
       glUniform1i(p.uniform("tex0"), 0);
       mb.draw();
       
     } t.unbind(GL_TEXTURE0);
     
   } p.unbind();
 }
开发者ID:CreativeCodingLab,项目名称:aluminum,代码行数:16,代码来源:FBOExample.cpp

示例12: SDLLoop

	MyArray3DLayeredHeightfieldTestLoop(Window *w) : SDLLoop(w) 
	{
		cout << "Initializing glew\n";
		glewInit();

		cout << "Binding program\n";
		program.addShader(Shader(GL_VERTEX_SHADER, "functional/phong/shader.vp"));
		program.addShader(Shader(GL_FRAGMENT_SHADER, "functional/phong/shader.fp"));
		program.link();
		program.bind();
		
		cout << "Getting locations of shader parameters\n";
		vertexLocation = program.getAttributeLocation("vPosition");
		texCoordLocation = program.getAttributeLocation("uv");
		vertexColorLocation = program.getAttributeLocation("vColor");
		samplerLocation = program.getUniformLocation("image");
		modelLocation = program.getUniformLocation("model");
		perspectiveLocation= program.getUniformLocation("perspective");
		normalLocation = program.getAttributeLocation("Normal");
		ambientProductLocation = program.getUniformLocation("ambientProduct");
		diffuseProductLocation = program.getUniformLocation("diffuseProduct");
		specularProductLocation = program.getUniformLocation("specularProduct");
		lightPositionLocation = program.getUniformLocation("LightPosition");
		shininessLocation = program.getUniformLocation("shininess");
		
		program.enableAttributeArray(vertexLocation);
		program.enableAttributeArray(texCoordLocation);
		program.enableAttributeArray(vertexColorLocation);
		program.enableAttributeArray(normalLocation);
		
		signal = new PerlinSignal;
		signal->addFrequency(2, 0.5);
		signal->addFrequency(16, 0.01);
		generator = new MyLayeredVoxeledHeightfield(signal);

		voxels = new Array3D<bool>(128, 128, 128);
		generator->populateArray(voxels, 128);
		
		for (int j = 0; j<5; j++) make_hole(*voxels);
		for (int i =0; i<10; i++) (*voxels).copy(erode(*voxels));
		
		adapter = new Array3DLayeredHeightfieldAdapter(*voxels);
		adapter->generate();
		h = adapter->getField();
		cout << "Number of levels " << h->levelCount() << endl;

	}
开发者ID:fantastic001,项目名称:Height3D,代码行数:47,代码来源:array_to_layered_heightfield.cpp

示例13: SDLLoop

	MyVoxeledTerrainTestLoop(Window *w) : SDLLoop(w) 
	{
		cout << "Initializing glew\n";
		glewInit();

		cout << "Binding program\n";
		program.addShader(Shader(GL_VERTEX_SHADER, "functional/scene/shader.vp"));
		program.addShader(Shader(GL_FRAGMENT_SHADER, "functional/scene/shader.fp"));
		program.link();
		program.bind();
		
		cout << "Getting locations of shader parameters\n";
		vertexLocation = program.getAttributeLocation("vPosition");
		texCoordLocation = program.getAttributeLocation("uv");
		vertexColorLocation = program.getAttributeLocation("vColor");
		samplerLocation = program.getUniformLocation("image");
		modelLocation = program.getUniformLocation("model");
		perspectiveLocation= program.getUniformLocation("perspective");
		normalLocation = program.getAttributeLocation("Normal");
		ambientProductLocation = program.getUniformLocation("ambientProduct");
		diffuseProductLocation = program.getUniformLocation("diffuseProduct");
		specularProductLocation = program.getUniformLocation("specularProduct");
		lightPositionLocation = program.getUniformLocation("LightPosition");
		shininessLocation = program.getUniformLocation("shininess");
		
		cout <<  program.getAttributeLocation("vPosition")<< endl;
		cout <<  program.getAttributeLocation("uv")<< endl;
		cout <<  program.getAttributeLocation("vColor")<< endl;
		cout <<  program.getUniformLocation("image")<< endl;
		cout <<  program.getUniformLocation("model")<< endl;
		cout <<  program.getUniformLocation("perspective")<< endl;
		cout <<  program.getAttributeLocation("Normal")<< endl;
		cout <<  program.getUniformLocation("ambientProduct")<< endl;
		cout <<  program.getUniformLocation("diffuseProduct")<< endl;
		cout <<  program.getUniformLocation("specularProduct")<< endl;
		cout <<  program.getUniformLocation("LightPosition")<< endl;
		cout <<  program.getUniformLocation("shininess")<< endl;
		
		cout << "Normal location: " << normalLocation << endl;

		program.enableAttributeArray(vertexLocation);
		program.enableAttributeArray(texCoordLocation);
		program.enableAttributeArray(vertexColorLocation);
		program.enableAttributeArray(normalLocation);
	}
开发者ID:fantastic001,项目名称:Height3D,代码行数:45,代码来源:voxeled_terrain.cpp

示例14: onFrame

    void onFrame(){

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      program.bind(); {

	glUniformMatrix4fv(program.uniform("model"), 1, 0, ptr(model));
	glUniformMatrix4fv(program.uniform("view"), 1, 0, ptr(view));
	glUniformMatrix4fv(program.uniform("proj"), 1, 0, ptr(proj));

	glUniform1f(program.uniform("bloom"), bloomAmt);
	glUniform1i(program.uniform("tex0"), 0);

	texture.bind(GL_TEXTURE0); {
	  mb1.draw();	
	} texture.unbind(GL_TEXTURE0);

      } program.unbind();
    }
开发者ID:brianherman,项目名称:al2,代码行数:19,代码来源:TextureExample.cpp

示例15: onFrame

  void onFrame() {

    float ratio = float(height) / float(width);
    float c = cosf(angle);
    float s = sinf(angle);

    vec4 rot = scale * vec4(c, -s * ratio, s, c * ratio);

    planetProgram.bind(); {
      glUniform4fv(planetProgram.uniform("rot"), 1, ptr(rot));
      glUniform1f(planetProgram.uniform("zoom"), zoom);
      glUniform1f(planetProgram.uniform("power"), power);
      glUniform1i(planetProgram.uniform("cube_texture"), 0);

      cubemap[which].bind(GL_TEXTURE0); {
        mb.draw();
      } cubemap[which].unbind(GL_TEXTURE0);

    } planetProgram.unbind();
  }
开发者ID:CreativeCodingLab,项目名称:aluminum,代码行数:20,代码来源:MiniPlanet.cpp


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