openGL之API学习(二一二)固定管线的纹理
Posted hankern
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openGL之API学习(二一二)固定管线的纹理相关的知识,希望对你有一定的参考价值。
会将固定管线各个纹理单元(openGL之API学习(二零五)GL_MAX_TEXTURE_UNITS GL_MAX_TEXTURE_IMAGE_UNITS_ARB GL_MAX_COMBINED_TEXTURE_IM纹理单元数_hankern的专栏-CSDN博客int _maxFFPTextureUnits;int _maxGPUTextureUnits;glGetIntegerv( GL_MAX_TEXTURE_UNITS, &_maxFFPTextureUnits ); //4glGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &_maxGPUTextureUnits ); //32https://blog.csdn.net/hankern/article/details/122911153)的纹理融合显示,融合的规则是各个像素分量取最小值。如果不需要融合,则在每个纹理单元使用完后调用glBindTexture(GL_TEXTURE_2D, 0)。
比如
renderInfor.getState()->setActiveTextureUnit(2);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glDisable(GL_LIGHTING);
glColor4f(1.0,1.0,1.0,1.0);
static GLuint disp_tex_id1=0;
if(disp_tex_id1<=0)
glGenTextures(1, &disp_tex_id1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, disp_tex_id1);
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> img1 = new osg::Image;
img1=osgDB::readImageFile("D:\\\\OSG_OAGEARTH_x86\\\\data\\\\school.png");
osg::ref_ptr<osg::Texture2D> tex2 = new osg::Texture2D(img1);
unsigned char* dataPtr1 = (unsigned char*)img1->data();
glTexImage2D( GL_TEXTURE_2D, 0, img1->getInternalTextureFormat(),
img1->s(), img1->t(), tex2->getBorderWidth(),
(GLenum)img1->getPixelFormat(),
(GLenum)img1->getDataType(),
dataPtr1);
renderInfor.getState()->setActiveTextureUnit(1);
static GLuint disp_tex_id=0;
if(disp_tex_id<=0)
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[] =
-5.0f,0.0f,-5.0f,
5.0f,0.0f,-5.0f,
5.0f,0.0f,5.0f,
-5.0f,0.0f,5.0f
;
GLfloat vTex[] =
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.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);
state->setClientActiveTextureUnit(1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0,vTex);
glDrawArrays(GL_QUADS, 0, 4);
融合后效果
两张纹理图片分别为:
以上是关于openGL之API学习(二一二)固定管线的纹理的主要内容,如果未能解决你的问题,请参考以下文章