使用OpenGL三维场景下,在屏幕固定位置画图

废话闲叙述,直接上代码:
            //设置为2D投影场景
            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;
           //start: 绘制图片
             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();
             //end:结束绘制
            // m_centerY = height - 70;
             // glRotated(-GeoStateCurrent::GetInstance()->m_carDirection + 90, 0, 0, 1);
             glDisable(GL_BLEND);
             glDisable(GL_TEXTURE_2D);
           //还原场景
             glMatrixMode(GL_MODELVIEW);
             glPopMatrix();
             glMatrixMode(GL_PROJECTION);
         glPopMatrix();

你可能感兴趣的:(使用OpenGL三维场景下,在屏幕固定位置画图)