0

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

OpenGL 版本=4.0.10243 兼容性配置文件上下文,供应商=ATI Technologies Inc.,渲染器=AMD Radeon HD 6650M

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

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:看起来当我不做任何带纹理的四边形时,它可以工作。有没有人看到绑定功能中可能会破坏它的任何部分?

4

1 回答 1

1

所以,事实证明我只需要添加一些逻辑来启用和禁用 GL_TEXTURE_2D 每次我需要它,而不是仅仅将其绑定在 opengl 状态业务中。

于 2012-06-03T05:51:33.803 回答