//glDepthFunc(GL_LESS);
//glEnable(GL_DEPTH_TEST);///关掉深度测试,否则没效果,原因是后画的物体通不过测试,当然也就不能混合了
glDepthRange(0.0, 1.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
AUX_RGBImageRec *textureImage[1];
textureImage[0] = auxDIBImageLoadA(TEXT("D:/aa.bmp"));//辅助函数,用来读入纹理图
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);//打开混合测试函数
glColor4f(1.0, 0.0, 0.0, 0.7);
glEnable(GL_BLEND);
GLuint texture[1];
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, textureImage[0]->sizeX, textureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, textureImage[0]->data);////注意把nehe里面的生成纹理的函数换成glubuild2DMipmaps()
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRotatef(num * 30, 10.0, 10.0, 10.0);//旋转纹理
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-100.0f, -100.0f, 100.0f);//0 4 // 纹理和四边形的左下
glTexCoord2f(1.0f, 0.0f); glVertex3f( 100.0f, -100.0f, 100.0f);//1 5 // 纹理和四边形的右下
glTexCoord2f(1.0f, 1.0f); glVertex3f( 100.0f, 100.0f, 100.0f);//2 6 // 纹理和四边形的右上
glTexCoord2f(0.0f, 1.0f); glVertex3f(-100.0f, 100.0f, 100.0f);//3 7 // 纹理和四边形的左上
glTexCoord2f(0.0, 0.0); glVertex3f(-10.0, -10.0, 30.0);//4
glTexCoord2f(1.0, 0.0); glVertex3f(10.0, -10.0, 30.0);//5
glTexCoord2f(1.0, 1.0); glVertex3f(10.0, 10.0, 30.0);//6
glTexCoord2f(0.0, 1.0); glVertex3f(-10.0, 10.0, 30.0);//7
glTexCoord2f(0.0, 0.0); glVertex3f(-10.0f, -10.0f, 10.0f);
glTexCoord2f(1.0, 0.0); glVertex3f( 10.0f, -10.0f, 10.0f);
glTexCoord2f(1.0, 1.0); glVertex3f(-10.0, -10.0, 30.0);
glTexCoord2f(0.0, 1.0); glVertex3f(10.0, -10.0, 30.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
//----------------------------
测试了一下nehe教程里面的混合这一节,有两个地方需要注意,首先要关掉深度测试,如果不关掉深度测试,可能后画的物体直接通不过,就不能画到屏幕上,当然也就不能产生混合效果了
第二个就是,要用gluBuild2DMipmaps()这个函数,原教程的产生纹理的函数好像已经被丢弃了,不能使用