废话闲叙述,直接上代码:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(-5, 5, -5, 5);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
double width, height;
g_pGLDC->GetWindow(width, height);
m_centerY = height -70;
m_centerX = width*0.5;
double scalX = 10 / width;
double scalY = 10 / height;
double originerX = (m_centerX - width*0.5)*scalX;
glEnable(GL_TEXTURE_2D);
UINT32 textureWALL = tMap.find(textId)->second.textureValue;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, textureWALL);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2d(originerX - m_Width*0.5*scalX, 5 - (m_centerY + m_Height*0.5)*scalY);
glTexCoord2f(1.0f, 0.0f);
glVertex2d(originerX + m_Width*0.5*scalX, 5 - (m_centerY + m_Height*0.5)*scalY);
glTexCoord2f(1.0f, 1.0f);
glVertex2d(originerX + m_Width*0.5*scalX, 5 - ((m_centerY - m_Height*0.5))*scalY);
glTexCoord2f(0.0f, 1.0f);
glVertex2d(originerX - m_Width*0.5*scalX, 5 - (m_centerY - m_Height*0.5)*scalY);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();