Another representation method of osgfbo (seven) texture coordinates

Here, first modify the representation method of texture coordinates in osgfbo (5), not to say that the method in osgfbo (5) is wrong, but I prefer to explicitly assign the texture coordinate array to (0, 1). That is
1, set texture coordinates
osg::ref_ptrosg::Vec2Array texCoord = new osg::Vec2Array;
texCoord->push_back(osg::Vec2(0.0, 0.0));
texCoord->push_back(osg::Vec2(1.0, 0.0 ));
texCoord->push_back(osg::Vec2(1.0, 1.0));
texCoord->push_back(osg::Vec2(0.0, 1.0));
2. Pass the texture coordinates to shader (note that the serial number cannot be 0, here it is set to 1)

geom->setVertexAttribArray(1, texCoord, osg::Array::BIND_PER_VERTEX);
//geom->setTexCoordArray(0, texCoord);

3. Pass the texture coordinate variable before the shader (also set to 1 here)

		program1->addBindAttribLocation("texCoord", 1);

4. In the shader, the vertex shader is changed to

static const char * vertexShader =
{
“in vec2 texCoord;\n”
“varying vec2 outTexCoord;”
“void main(void)\n”
“{\n”
“outTexCoord = texCoord;\n”
" gl_Position = ftransform();\n"
“}\n”
};

5,传递给片元着色器

static const char *psShader =
{
“varying vec2 outTexCoord;”
“uniform sampler2D tex0;”
“void main(void)\n”
“{\n”
“gl_FragColor = texture2D(tex0,outTexCoord);”

"}"

"}\n"

};

Guess you like

Origin blog.csdn.net/directx3d_beginner/article/details/129892474