openGL清除颜色缓冲位

时间:2013-06-16 04:32:05

标签: c++ opengl rendering sdl

我已经做了一些环顾四周,并且正在找到我的问题。可以找到相关的主题:

SDL OpenGL Rendering Issue

问题是渲染纹理在其顶部有一个基元。我试图在我的原语中添加一些颜色动画,似乎这样做并渲染纹理有一些问题 动画开始时很简单,可以测试我能做什么,它只是改变了基元顶点的颜色。结果效果会使我的纹理在两个不同的阴影之间交替。我似乎无法弄清楚如何阻止这种情况,我尝试了很多东西,但我认为它与我所链接的相同类型的问题有关。

void CApp::OnRender() {


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    MainScreen.RenderQuad(0,0,winWidth,winHeight);  

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    MainMenu.OnRender();

    SDL_GL_SwapBuffers();
}

MainScreen是一个CTexture类,渲染函数是:

void CTexture::RenderQuad(int X, int Y, int Width, int Height) {
    glPushMatrix();
    Bind(); //just calls glBindTexture(GL_TEXTURE_2D, TextureID);


    glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f(X, Y, 0);
        glTexCoord2f(1, 0); glVertex3f(X + Width, Y, 0);
        glTexCoord2f(1, 1); glVertex3f(X + Width, Y + Height, 0);
        glTexCoord2f(0, 1); glVertex3f(X, Y + Height, 0);
    glEnd();
    glPopMatrix();
    glFlush();
}

MainMenu是一个CMenu类对象和渲染函数。 MainMenu是一个案例1,因此忽略交换机中的其他情况。

void CMenu::OnRender() {

    if( Visible ) {
        //glPushMatrix();
        if(MenuTexture == NULL) {   

            switch(Style) {
            case 0: {
            glBegin(GL_QUADS);
                glColor4f(R,G,B,A); glVertex2d(X, Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y+Height);
                glColor4f(R,G,B,A); glVertex2d(X,Y+Height);
            glEnd();
            break;
                    }
            case 1: {
            glBegin(GL_POLYGON);
                glColor4f(sR,sG,sB,sA); glVertex2d(X, Y+Rounding);
                glColor4f(R,G,B,A); glVertex2d(X+Rounding,Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y+Height-Rounding);
                glColor4f(sR,sG,sB,sA); glVertex2d(X+Width-Rounding,Y+Height); 
                glColor4f(sR,sG,sB,sA); glVertex2d(X,Y+Height);
            glEnd();
            break;
                }
            case 2: {
            glBegin(GL_POLYGON);
                glColor4f(R,G,B,A); glVertex2d(X, Y+Rounding);
                glColor4f(R,G,B,A); glVertex2d(X+Rounding,Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width-Rounding,Y);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y+Rounding);
                glColor4f(R,G,B,A); glVertex2d(X+Width,Y+Height-Rounding);
                glColor4f(R,G,B,A); glVertex2d(X+Width-Rounding,Y+Height);

                glColor4f(R,G,B,A); glVertex2d(X+Rounding,Y+Height);
                glColor4f(R,G,B,A); glVertex2d(X,Y+Height-Rounding);
            glEnd();
            break;
                    }
            default:{
                    }
            }

        }else{
            MenuTexture->RenderQuad(X,Y,Width,Height);
        }
        //glPopMatrix();
        //glFlush();
    }
}

在我的动画中,我有一个定时器,每秒都会改变原始阴影,所以我可以捕获结果。我并排放置了两个不同框架的图像。在每个人之后,我只是调用一个函数,它反转r,g,b,a与sr,sg,sb,sa。

my shoddy rendering http://img90.imageshack.us/img90/6016/syqx.png

0 个答案:

没有答案