osg学习(六十五)图片到纹理

Posted hankern

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osg学习(六十五)图片到纹理相关的知识,希望对你有一定的参考价值。

glBindTexture(GL_TEXTURE_2D, 0);
GLuint disp_tex_id;
glGenTextures(1, &disp_tex_id);



glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, disp_tex_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


osg::ref_ptr<osg::Image> img = new osg::Image;
img=osgDB::readImageFile("D:\\\\OSG_OAGEARTH_x86\\\\data\\\\road.png");
osg::ref_ptr<osg::Texture2D> tex1 = new osg::Texture2D(img);
unsigned char* dataPtr = (unsigned char*)img->data();
glTexImage2D( GL_TEXTURE_2D, 0, img->getInternalTextureFormat(),
img->s(), img->t(), tex1->getBorderWidth(),
(GLenum)img->getPixelFormat(),
    (GLenum)img->getDataType(),
    dataPtr);


GLfloat vVertices[] =

0.0f, 0.0, 10.0f,
0.0f,0.0, 0.0f,
10.0f, 0.0f, 0.0f,

;
GLfloat vTex[] = 
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
;
GLfloat vColor[] =

0.8,0.0,0.0,1.0
;


glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0,vVertices);




glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0,vTex);

glDrawArrays(GL_TRIANGLES, 0, 3);

以上是关于osg学习(六十五)图片到纹理的主要内容,如果未能解决你的问题,请参考以下文章

osg学习(六十三)osg直接调用opengl例子

osg学习(六十六)Unsupported wrapper class osg::Object

osg学习(六十)setTextureMode setTextureAttributeAndModes

osg学习(六十八)序列化插件加载过程

osg学习(六十九)平移旋转缩放实现过程

osg学习(六十七)InputIterator::checkStream() : _in->rdstate() 3, 2