2013-02-12 3 views
0

많은 검색 및 읽기에도 불구하고 해결책을 찾지 못한 이상한 문제가 있습니다.cocos2d 2.0 사용자 지정 드로잉으로 인해 불완전한 장면 렌더링이 발생합니다.

동적으로 생성 된 배경을 사용하는 장면이 있습니다. 배경에 대한 코드는이 tutorial과 Haqus Tiny-Wings github와 관련된 것으로 발견 된 다른 코드를 기반으로합니다.

어쨌든 내 코드는 힐 생성을 단순화했으며 모두 StripedTerrain이라는 CCNode 클래스에 포함되어 있습니다. 그것은 모두 잘 작동하지만 (현재!) 동일한 배경 스프라이트로 동일한 레이아웃을 사용하는 다른 장면으로 갈 때 완전히 렌더링되지 않습니다. screenshot을 참조하십시오. 이미지 A는 내 코드를 그대로 사용하는 첫 번째 실행입니다. 이미지 B는 동일한 장면 클래스의 새 장면에 대한 replaceScene 호출 이후입니다. 그럼, 난 그냥 매트릭스 터지는 전에 내 드로우 코드이 작은 변화를 만들어 :

ccDrawColor4B(255, 255, 255, 255); 
ccDrawLine(ccp(0.0,0.0),ccp(0.0,0.0)); 

을하고 그것을 잘 (이미지 C 및 D)

이것은 이상한 일이 내가 무엇을 알아낼 수 없습니다 작동 잘못되어가는.

나는 그리기 호출 코드를 게시 할 수 있습니다,하지만 당신은 세부 사항의 나머지 여분 :

/** 
* Previus to the draw method we have already done the following: 
* Randomly selected, or have been given two colors to paint the stripes onto our texture 
* Generated a texture to overlay on to our hill vertice geometry 
* Generated the top of the hill peaks and valleys 
* Generated the hill verticies that will fill in the surface of the hills 
* with the texture applied 
*/ 
- (void) draw { 

CC_NODE_DRAW_SETUP(); 
// this statement fixed the screwed up jagged line rendering 
// since we are only using position and texcoord vertexes, we have to use this shader 
kmGLPushMatrix(); 
CHECK_GL_ERROR_DEBUG(); 
ccGLBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); //TB 25-08-12: Allows change of blend function 
ccGLBindTexture2D(self.stripes.texture.name); 

//TB 25-08-12: Assign the vertices array to the 'position' attribute 
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, _hillVertices); 

//TB 25-08-12: Assign the texCoords array to the 'TexCoords' attribute 
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, _hillTexCoords); 
glEnableVertexAttribArray(kCCVertexAttrib_Position); 
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords); 
//TB 25-08-12: Draw the above arrays 
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nHillVertices); 
CHECK_GL_ERROR_DEBUG(); 

//Debug Drawing (remove comments to enable) 
if(0) { 
    for(int i = MAX(_fromKeyPointI, 1); i <= _toKeyPointI; ++i) { 
    ccDrawColor4B(255, 0, 0, 255); 
    ccDrawLine(_hillKeyPoints[i-1], _hillKeyPoints[i]); 
    } 
    for(int i =0;i<_nHillVertices;i+=3) { 
     ccDrawColor4B(255, 0, 0, 255); 
     ccDrawLine(_hillVertices[i+1], _hillVertices[i+2]); 
    } 
} 
// have to do this to force it to work the next scene load 
ccDrawColor4B(255, 255, 255, 255); 
ccDrawLine(ccp(0.0,0.0),ccp(0.0,0.0)); 
kmGLPopMatrix(); 
CC_INCREMENT_GL_DRAWS(1); 


} 

명백한 실수 위?

다른 방법으로 쉐이더를 설정했습니다.

답변

0

이전 장면과 해당 하위 항목이 dealloc 메소드를 실행하는지 확인하십시오. 그렇지 않으면 가장 이상한 일이 누출 될 수 있습니다.

슈퍼 정리를 호출하지 않고 정리를 재정의하는 경우에도 마찬가지입니다.

+0

아니요, 나는 그런 모든 명백한 일을했습니다. – Mark

+0

나는 ccDrawLine을 모두 인라인으로 처리하고 다시 중단되기 전에 얼마나 주석을 달 수 있는지 알아 봅니다. 아마도 ccGLEnableVertexAttribs와 관련이 있을까요? 플래그가 설정되면 kCCVertexAttrib_Color가 활성화됩니다. – Pat