使用两个纹理

用两个纹理


//载入位图

AUX_RGBImageRec* TextureImage[1];
TextureImage[0]=auxDIBImageLoad(L"ground.bmp");
//绑定纹理
glGenTextures(1,&texground);
glBindTexture(GL_TEXTURE_2D,texground);
//纹理参数指定包装形式
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);
glTexImage2D(GL_TEXTURE_2D,0,3,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glPushMatrix();
glScalef(4,1,4);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-2., -1., 2.);
glTexCoord2f(1.0f, 0.0f); glVertex3f(2.0f, -1., 2.);
glTexCoord2f(1.0f, 1.0f); glVertex3f(2.0f,  -1., -2.);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.,-1., -2);
glEnd();
glPopMatrix();


//绑定纹理
glGenTextures(1,&texsky);
glBindTexture(GL_TEXTURE_2D,texsky);
//纹理参数指定包装形式
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
TextureImage[0]=auxDIBImageLoad(L"sky.bmp");
glTexImage2D(GL_TEXTURE_2D,0,3,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glPushMatrix();
glTranslatef(0,0,-8);
glScalef(2,2,1);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-3.,-3.,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(3.,-3, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(3.,3.,0);
glTexCoord2f(0.f, 1.0f); glVertex3f(-3.,3.,0);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);

你可能感兴趣的:(opengl)