C++ OpenGL 1.x显示带有纹理的GL#U四边形,纯色不';T

C++ OpenGL 1.x显示带有纹理的GL#U四边形,纯色不';T,c++,opengl,sdl,C++,Opengl,Sdl,首先,我的OpenGL信息(我在运行时获取): OpenGL版本=4.0.10243兼容配置文件上下文,供应商=ATI 技术公司,渲染器=AMD Radeon HD 6650M 所以我正在为几个项目开发gui/hud渲染系统,我遇到了一个有趣的问题。我可以使用以下代码毫无问题地显示纹理GL_四边形: this->m_buffer->openglBindTexture(); SDL::Rect tc( this->m_buffer->getOpenGLTextureCoo

首先,我的OpenGL信息(我在运行时获取):

OpenGL版本=4.0.10243兼容配置文件上下文,供应商=ATI 技术公司,渲染器=AMD Radeon HD 6650M

所以我正在为几个项目开发gui/hud渲染系统,我遇到了一个有趣的问题。我可以使用以下代码毫无问题地显示纹理GL_四边形:

this->m_buffer->openglBindTexture();

SDL::Rect tc( this->m_buffer->getOpenGLTextureCoords() );           

glBegin( GL_QUADS );

    glColor4fv( (SDL::Color("white")).toGLColor4vf( 1.0 ) );
    glTexCoord2f( tc.topleft().x, tc.topleft().y );
    glVertex3f( this->boundary().bottomleft().x, this->boundary().bottomleft().y, this->m_z );

    glTexCoord2f( tc.topright().x, tc.topright().y );
    glVertex3f( this->boundary().bottomright().x, this->boundary().bottomright().y, this->m_z );

    glTexCoord2f( tc.bottomright().x, tc.bottomright().y );
    glVertex3f( this->boundary().topright().x, this->boundary().topright().y, this->m_z );

    glTexCoord2f( tc.bottomleft().x, tc.bottomleft().y );
    glVertex3f( this->boundary().topleft().x, this->boundary().topleft().y, this->m_z );

glEnd();
其中一些使用了我自己的SDL+OpenGL包装代码。这是我的绑定代码,以防有人发现它的怪癖:

void Surface::openglBindTexture( void )
{
    int glerror = 0;
    if( !this->m_hastexture ) {
        int bpp;
        Uint32 Rmask, Gmask, Bmask, Amask;
        SDL_PixelFormatEnumToMasks(
            SDL_PIXELFORMAT_ABGR8888, &bpp,
            &Rmask, &Gmask, &Bmask, &Amask
        );

        int glw = this->w_pow2();
        int glh = this->h_pow2();

        /* Create surface that will hold pixels passed into OpenGL. */
        SDL_Surface *img_rgba8888 = SDL_CreateRGBSurface(0,
            glw, glh, bpp,
            Rmask, Gmask, Bmask, Amask
        );

        SDL_SetSurfaceAlphaMod( this->m_surface, 0xFF );
        SDL_SetSurfaceBlendMode( this->m_surface, SDL_BLENDMODE_NONE );

        SDL_BlitSurface( this->m_surface, NULL, img_rgba8888, NULL );

        glGenTextures( 1, &this->m_texture );
        glBindTexture( GL_TEXTURE_2D, this->m_texture );
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, glw, glh, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_rgba8888->pixels );
        glerror = GLException::glError(); if( glerror != 0 ) throw new GLException( "Surface::openglBindTexture::glTexImage2D", glerror, __FILE__, __LINE__ );

SDL_FreeSurface(img_rgba8888);
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
        glerror = GLException::glError();
        if( glerror != 0 ) throw new GLException( "Surface::openglBindTexture::Importing raw texture", glerror, __FILE__, __LINE__ );
        this->m_hastexture = true;
    }
    glBindTexture( GL_TEXTURE_2D, this->m_texture );
}
下面是我试图在opengl中显示简单彩色四边形的代码:

glBegin( GL_QUADS );
    glColor3f( 1.0f, 1.0f, 1.0f );
    glVertex3f( this->boundary().topleft().x, this->boundary().topleft().y, this->m_z );
    glColor3f( 1.0f, 1.0f, 1.0f );
    glVertex3f( this->boundary().topright().x, this->boundary().topright().y, this->m_z );
    glColor3f( 1.0f, 1.0f, 1.0f );
    glVertex3f( this->boundary().bottomright().x, this->boundary().bottomright().y, this->m_z );
    glColor3f( 1.0f, 1.0f, 1.0f );
    glVertex3f( this->boundary().bottomleft().x, this->boundary().bottomleft().y, this->m_z );
glEnd();
这画不出任何东西。我完全被难住了,因为我可以看到我所有的纹理四边形都没有问题

编辑:我应该注意,我做了一些完整性检查,边界坐标都正确可见


编辑2:看起来当我不做任何纹理四边形时,它就可以工作了。有人在绑定函数中看到任何可能破坏它的部分吗?

因此,我只需要添加一些逻辑,以便在每次需要时启用和禁用GL_TEXTURE_2D,而不仅仅是在opengl状态业务中保持它的绑定。

在哪里设置纹理环境(glTexEnv)之类的东西?你在哪里激活和停用纹理?我建议就这样。