我正在尝试将纹理映射应用于我绘制的球体。 我可以将我的纹理应用到它上面。但我看不到图像的任何细节。我只看到一个橙色球体,没有细节。
这是我的图片:/image/hdY1H.jpg 我的图像是 17x17 24 位 bmp。
我只看到一个绿色的球体。为什么请?
我的代码:
void glWidget::myTextureMapping()
{
QImage t;
QImage b;
if(!b.load("...sun2.bmp"))
{
qDebug("error with image\n");
}
t = QGLWidget::convertToGLFormat( b );
glGenTextures( 1, &texture[0] );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
gluBuild2DMipmaps( GL_TEXTURE_2D,3 ,17,17, GL_RGB,GL_BITMAP, t.bits());
}
void glWidget::drawSphere()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glPushMatrix();
glScalef(1,1,1);
glLoadIdentity();
GLUquadricObj *quadric=gluNewQuadric();
gluQuadricNormals(quadric, GLU_SMOOTH);
gluSphere(quadric, 0.25, 360,360);
gluDeleteQuadric(quadric);
glPopMatrix();
}
void glWidget::initializeGL()
{
myTextureMapping();
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}
最佳答案
关于c++ - openGL 纹理映射 - 没有细节,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730299/