2014-03-02 2 views
1

OpenGL ES 2.0에는 2 개의 VBO와 2 개의 IBO가 있습니다. 첫 번째 VBO 렌더링에는 문제가 없지만 두 번째 VBO 렌더링은 렌더링되지 않습니다. 나도 오류가 발생하지 않습니다.OpenGL ES 2.0 : 두 번째 VBO를 렌더링 할 수 없습니까?

첫 번째 VBO에는 9 개의 꼭지점이있는 GL_STATIC_DRAW 개체가 포함되어 있습니다. 두 번째 VBO에는 사용자 인터페이스를 렌더링 할 수 있도록 4 개의 꼭지점이 포함되어 간단한 2D 평면을 만듭니다.

여기에 C 코드의 관련 부분이 있습니다. renderBG()은 첫 번째 VBO를 렌더링하고 renderUI()은 두 번째 VBO를 렌더링합니다. 나는 이것을 올바른 방법으로하고 있는가?

void renderBG(OGL_STATE_T *state) { 

    matIdentity(modelViewMatrix); 
    matTranslate(modelViewMatrix, 0, 0, -1.0); 

    _currentRotation = _currentRotation + 0.5; 
    _currentRotation = fmod(_currentRotation, 360); 
    matRotate(modelViewMatrix, 0, 0, 45); 
    matRotate(modelViewMatrix, 0, _currentRotation, 0); 

    const GLfloat *mvMat = modelViewMatrix; 
    const GLfloat *pMat = projectionMatrix; 

    glClearColor(0, 0.05, 0, 1.0); 
    glClearDepthf(10.0f); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glViewport(0,0,state->screen_width, state->screen_height); 

    glBindBuffer(GL_ARRAY_BUFFER, state->nsVB); 

    glUniformMatrix4fv(_projectionUniform, 1, 0, pMat); 
    glUniformMatrix4fv(_modelViewUniform, 1, 0, mvMat); 

    glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); 
    glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
      (GLvoid *) (sizeof(float) * 3)); 

    glEnableVertexAttribArray(_positionSlot); 
    glEnableVertexAttribArray(_colorSlot); 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state->nsIB); 
    glDrawElements(GL_TRIANGLES, sizeof(nsIndices)/sizeof(nsIndices[0]), 
      GL_UNSIGNED_BYTE, 0); 

} 

void renderUI(OGL_STATE_T *state) { 

    matIdentity(modelViewMatrix); 
    matTranslate(modelViewMatrix, 0, 0, -1.0); 

    const GLfloat *mvMat2 = modelViewMatrix; 
    const GLfloat *pMat2 = projectionMatrix; 

    glViewport(0,0,state->screen_width, state->screen_height); 

    glBindBuffer(GL_ARRAY_BUFFER, state->uiVB); 

    glUniformMatrix4fv(_projectionUniform, 1, 0, pMat2); 
    glUniformMatrix4fv(_modelViewUniform, 1, 0, mvMat2); 

    glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); 
    glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
      (GLvoid *) (sizeof(float) * 3)); 

    glEnableVertexAttribArray(_positionSlot); 
    glEnableVertexAttribArray(_colorSlot); 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state->uiIB); 
    glDrawElements(GL_TRIANGLES, uiIndicesArraySize/uiIndicesElementSize, 
      GL_UNSIGNED_BYTE, 0); 

    GLenum err; 

    if ((err = glGetError()) != GL_NO_ERROR) 
     printf("There was an error"); 
} 

void render(OGL_STATE_T *state) { 

    renderBG(state); 
    renderUI(state); 

    eglSwapBuffers(state->display, state->surface); 
    check(); 
} 

편집 :

여기에 몇 가지 추가 정보입니다. 이것은 버텍스 및 인덱스 배열은 제 2 VBO에 채워집니다 방법입니다

GLfloat _width = uiWidth; 
GLfloat _height = uiHeight; 

Vertex uiVertices[] = { 
    {{-_width,_height,0}, {1,1,1,1}},  // Top left 
    {{_width,_height,0}, {1,1,1,1}},  // Top right 
    {{-_width,-_height,0}, {1,1,1,1}},  // Bottom left 
    {{_width,-_height,0}, {1,1,1,1}}  // Bottom right 
}; 

GLubyte uiIndices[] = { 
    0,1,2, 
    2,1,3 
}; 

uiVerticesArraySize = sizeof(uiVertices); 
uiVerticesElementSize = sizeof(uiVertices[0]); 
uiIndicesArraySize = sizeof(uiIndices); 
uiIndicesElementSize = sizeof(uiIndices[0]); 

printf("%f %f\n", uiVertices[0].Position[0], uiVertices[0].Position[1]); 

glGenBuffers(1, &state->uiVB); 
glBindBuffer(GL_ARRAY_BUFFER, state->uiVB); 
glBufferData(GL_ARRAY_BUFFER, sizeof(uiVertices), uiVertices, GL_STATIC_DRAW); 

glGenBuffers(1, &state->uiIB); 
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state->uiIB); 
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uiIndices), uiIndices, GL_STATIC_DRAW); 
+0

'glGetError'가 뭐라고 말합니까? –

+0

@ ViníciusGobboA.deOliveira 오류가 없습니다. – ReX357

답변

0

그래서 내 인덱스가 시계 방향으로 순서와 GL_CULL_FACE 활성화 (카메라를 향해 정상을 직면 할 생각)에 선언했다 밝혀졌습니다. 지표를 바꿨고 모든 것이 세계와 잘 맞습니다.