2012-04-21 2 views
0

OpenGL ES "2.0"에서 2D와 3D를 결합하려고합니다. OpenGL es 1.0과 2.0에서 많은 질문이 있지만이 문제를 파악하는 데 문제가 있습니다. . 2D 용이므로이 튜토리얼을 진행할 것입니다 : http://www.raywenderlich.com/9743/how-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-1 그리고 3D 용 기존 큐브 회전 xcode 템플릿을 사용 중입니다 ...ios opengl es 2.0 2D + 3D 조합

두 번째 glDrawArray에서 EXC_BAD_ACCESS를 얻고 있습니다 (어떻게 든 원래 버퍼가 여전히 적용된다고 생각합니다.) ? 어쨌든 2D 텍스처를 그리기 전에 이것을 바인딩 해제 하시겠습니까?) 다음 렌더링 함수로 오류가 발생했습니다. 줄을 사용하지 않으면 작동합니다. glEnableVertexAttribArray (GLKVertexAttribPosition); glVertexAttribPointer (GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET (0)); glEnableVertexAttribArray (GLKVertexAttribNormal); glVertexAttribPointer (GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET (12));

무슨 일 이니? 미리 감사드립니다.

[코드]

glEnable(GL_DEPTH_TEST); 

// glGenVertexArraysOES(1, &_vertexArrayNum); 
// glBindVertexArrayOES(_vertexArrayNum); 

glGenBuffers(1, &_vertexBufferNum); 
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferNum); 
glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); 

glEnableVertexAttribArray(GLKVertexAttribPosition); 
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); 
glEnableVertexAttribArray(GLKVertexAttribNormal); 
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); 

glBindVertexArrayOES(0); 

float aspect = fabsf(self.view.bounds.size.width/self.view.bounds.size.height); 
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f); 

self.effect.transform.projectionMatrix = projectionMatrix; 

GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f); 
// baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f); 

// Compute the model view matrix for the object rendered with GLKit 
// GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 1.5f); 
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeRotation(_rotation, 0, 1, 0); 
//modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); 
modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); 

self.effect.transform.modelviewMatrix = modelViewMatrix; 

glClearColor(0.65f, 0.65f, 0.65f, 1.0f); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

glBindVertexArrayOES(_vertexArrayNum); 

// Render the object with GLKit 
// [self.effect prepareToDraw]; 

// glDrawArrays(GL_TRIANGLES, 0, 36); 

modelViewMatrix = GLKMatrix4MakeScale(2.0f, 2.0f, 2.0f); 
projectionMatrix = GLKMatrix4MakeOrtho(0, 480, 0, 320, -1024, 1048); 
self.effect.transform.projectionMatrix = projectionMatrix; 
self.effect.transform.modelviewMatrix = modelViewMatrix; 

[self.effect prepareToDraw]; 


glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
glEnable(GL_BLEND); 

[self.player render]; 

[/ 코드]

UPDATE : glEnableClientState 라이트 (GL_VERTEX_ARRAY); ... 나쁜 액세스 오류를 제거있어 큐브 그리기 부분 ... 감싸하지만 (나오긴의 내가 모두 코드 부분을 언급하지 않는) 큐브 나 스프라이트도 그려되고

UPDATE2 : 그래서 problen은 glDrawArray를 호출하여 (잘 작동하는) 큐브를 그리는 것이 분명합니다 ... 나는 glDrawArray를 다시 다음과 같이 호출합니다. 하지만 어쨌든 여전히 이전 배열을 렌더링하려고? // 1 self.effect.texture2d0.name = self.textureInfo.name; self.effect.texture2d0.enabled = 예;

// 2  
[self.effect prepareToDraw]; 

// 3 
glEnableVertexAttribArray(GLKVertexAttribPosition); 
glEnableVertexAttribArray(GLKVertexAttribTexCoord0); 

// 4 
long offset = (long)&_quad;   
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, geometryVertex))); 
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, textureVertex))); 

// 5  
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

답변

0

어리석은 me. 최대한 빨리 작동 :

glBindBuffer(GL_ARRAY_BUFFER, 0); 

버퍼를 지우려면. 나는 계속 glUnbind 뭔가를 찾고 있었다. ... OpenGL이 메모리 참조에서 작동하지 않는다는 것을 잊어 버렸다. 2D texutre가 이제 큐브에 적용되지만, 나는 쉬운 수정이라고 확신한다. : o

텍스처 문제 고정 :