Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present of uninitialized color attachment issue

Tags:

ios

opengl-es

When I run my OpenGL app, I get the following error:

enter image description here

I googled but can't get any useful information.

Here're a piece of source code:

- (void)render:(CADisplayLink*)displayLink {
    [self.canvas clear];
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    NSInteger mLength = mParticles.count;
    NSInteger drawCount = 0;
    NSInteger drawIndex = 0;
    WQParticle* drawParticle;
    CGFloat drawX,drawY,drawScale,drawAngle;
    GLKMatrix4 changeColorMatrix;
    if (mLength > 0){
        glBindFramebuffer(GL_FRAMEBUFFER, FBO);
        glViewport(0,0,width,height);
        drawCount = 0;
        drawIndex = -1;
        while ( drawCount < mLength){
            drawParticle = mParticles[drawCount];

            if(!(drawParticle.flg && random > 0.5)){

                if (drawIndex != drawParticle.texIndex) {
                    glActiveTexture(GL_TEXTURE0);
                    glBindTexture(GL_TEXTURE_2D, (GLuint)(texture[drawParticle.texIndex]));
                    glUniform1i((GLint)uniLocation[1], 0);
                    drawIndex = drawParticle.texIndex;
                }

                if(drawParticle.flg){
                    drawX = drawParticle.posX + (random * 1 - 0.5) * drawParticle.scale * 0.06;
                    drawY = drawParticle.posY + (random * 1 - 0.5) * drawParticle.scale * 0.06;
                    drawScale = drawParticle.scale * (random * 0.4 + 0.8);
                    changeColorMatrix = [self setChangeColorWithDp:drawParticle n:random];
                    drawX = drawX / drawScale;
                    drawY = drawY / drawScale;
                }else{
                    drawX = drawParticle.posX / drawParticle.scale;
                    drawY = drawParticle.posY / drawParticle.scale;
                    drawScale = drawParticle.scale;
                    changeColorMatrix = [self setChangeColorWithDp:drawParticle n:1];
                }
                glUniformMatrix4fv((GLint)uniLocation[2], 1, 0, changeColorMatrix.m);
                drawAngle = drawParticle.angle;
                CGFloat drawR = sqrt(drawX * drawX + drawY * drawY);
                CGFloat oa = 2 * M_PI - acos(drawX / drawR);
                drawX = cos(oa - drawAngle) * drawR;
                drawY = sin(oa - drawAngle) * drawR;

                mMatrix = GLKMatrix4Identity;
                mMatrix = GLKMatrix4Rotate(mMatrix, drawAngle, 0, 0, 1);
                mMatrix = GLKMatrix4Scale(mMatrix, drawScale, drawScale, drawScale);
                mMatrix = GLKMatrix4Translate(mMatrix, drawX, drawY, 0);
                mvpMatrix = GLKMatrix4Multiply(f_tmpMatrix, mMatrix);

                glUniform1i((GLint)uniLocation[3], YES);
                glUniformMatrix4fv((GLint)uniLocation[0], 1, 0, mvpMatrix.m);
                glDrawElements(GL_TRIANGLES, sizeof(indices), GL_UNSIGNED_BYTE, 0);
            }

            if (drawParticle.life > 0) {
                [mVF getForceFromPosWithPx:drawParticle.posX Py:drawParticle.posY];
                [drawParticle setVFupdateWithOutX:mVF.outX OutY:mVF.outY];
                drawCount++;
                continue;
            }
            [mParticles removeObjectAtIndex:drawCount];
            mLength = mLength - 1;
        }
        glBindFramebuffer(GL_FRAMEBUFFER,0);
    }

    glBindTexture(GL_TEXTURE_2D, FBOTexture);
    mMatrix = GLKMatrix4Identity;
    mvpMatrix = GLKMatrix4Multiply(tmpMatrix, mMatrix);
    glUniformMatrix4fv((GLint)uniLocation[0], 1, 0, mvpMatrix.m);
    glUniform1i((GLint)uniLocation[3], NO);
    glDrawElements(GL_TRIANGLES, sizeof(indices), GL_UNSIGNED_BYTE, 0);
    [self.canvas.glContext presentRenderbuffer:GL_RENDERBUFFER];
}

How can I solve this?

like image 219
Allen Avatar asked Sep 23 '15 18:09

Allen


People also ask

What happens when you try to use an uninitialized variable?

So using an uninitialized variable will result in undefined behavior. Undefined behavior means anything1 can happen including but not limited to the program giving your expected output. But never rely(or make conclusions based) on the output of a program that has undefined behavior.

What does it mean when a variable is uninitialized?

In computing, an uninitialized variable is a variable that is declared but is not set to a definite known value before it is used. It will have some value, but not a predictable one. As such, it is a programming error and a common source of bugs in software.

What does uninitialized mean in C?

Uninitialized means the object has not been given a known value (through any means, including assignment). Therefore, an object that is not initialized but is then assigned a value is no longer uninitialized (because it has been given a known value).

Which function gives memory uninitialized?

The realloc() function changes the size of a dynamically allocated memory object. The initial size bytes of the returned memory object are unchanged, but any newly added space is uninitialized, and its value is indeterminate.


1 Answers

Check that glViewport() is set the size of the renderpass you are rendering to, and that either glScissor() is set to that size too, or that scissor test is disabled via glDisable().

like image 171
solidpixel Avatar answered Oct 01 '22 17:10

solidpixel