2009-07-06 3 views
0

OpenGL을 처음 사용하기 때문에 이것은 실수가 아니지만 모든 게시물을 읽고 샘플 코드를 검토 한 결과입니다. glFrustum이 왜 내가 원하는대로 표시되지 않는지 설명하는 차이점을 찾을 수 없습니다.glFrustumf는 투명 색상 만 표시합니다. 예상대로 표시됩니다. (OpenGL ES)

내가 좋아하는 OpenGL을 초기화 :

- (void) initOpenGL{ 
    glEnable(GL_DEPTH_TEST); 
    glMatrixMode(GL_PROJECTION); 
    //glLoadIdentity(); 
    //glOrthof(0.0f, self.bounds.size.width, self.bounds.size.height, 0.0f, -10.0f, 10.0f); 

    const GLfloat zNear = -0.1, zFar = 1000.0, fieldOfView = 60.0; 
    GLfloat size; 
    size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView)/2.0); 

    // This give us the size of the iPhone display 
    CGRect rect = self.bounds; 
    glFrustumf(-size, size, -size/(rect.size.width/rect.size.height), size/(rect.size.width/rect.size.height), zNear, zFar); 
    glViewport(0, 0, rect.size.width, rect.size.height); 

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

#if 0 
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
#endif 

    glEnable(GL_TEXTURE_2D); 
    glEnable(GL_BLEND); 

#if TARGET_IPHONE_SIMULATOR 
    glColor4f(0.0, 0.0, 0.0, 0.0f); 
#else 
    glColor4f(0.0, 0.0, 0.0, 0.0f); 
#endif 

    [[Texture2D alloc] initWithImage:[UIImage imageNamed:@"GreenLineTex.png"] filter:GL_LINEAR]; 

    glInitialised = YES; 

을 그리고 내 도면이 같이 이루어집니다 :

for 루프의 블록이 어떤 삼각형 스트립을 구성하는 정점의 집합입니다
- (void)drawView { 
    if(!glInitialised) { 
     [self initOpenGL]; 
    } 

    [EAGLContext setCurrentContext:context]; 

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); 

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    glEnableClientState(GL_COLOR_ARRAY);   
    glEnable(GL_TEXTURE_2D); 
    static const GLfloat texCoords[] = { 
     0.0, 0.0, 
     1.0, 0.0, 
     0.0, 1.0, 
     1.0, 1.0 
    }; 

    // draw the edges 
    glEnableClientState(GL_VERTEX_ARRAY); 
     glDisableClientState(GL_COLOR_ARRAY); 

    glTexCoordPointer(2, GL_FLOAT, 0, texCoords); 
    glBindTexture(GL_TEXTURE_2D, 1); 
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 

    glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 

    for (int i = 0; i < connectionNumber; i++){ 

     Vertex2DSet(&vertices[0], connectionLines[i].lineVertexBeginPoint.x, connectionLines[i].lineVertexBeginPoint.y); 
     Vertex2DSet(&vertices[1], connectionLines[i].lineVertexBeginPoint.x+connectionLines[i].normalVector.x, connectionLines[i].lineVertexBeginPoint.y+connectionLines[i].normalVector.y); 
     Vertex2DSet(&vertices[2], connectionLines[i].lineVertexEndPoint.x, connectionLines[i].lineVertexEndPoint.y); 
     Vertex2DSet(&vertices[3], connectionLines[i].lineVertexEndPoint.x+connectionLines[i].normalVector.x, connectionLines[i].lineVertexEndPoint.y+connectionLines[i].normalVector.y); 

     glVertexPointer(2, GL_FLOAT, 0, vertices); 
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 
    } 

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); 
    [context presentRenderbuffer:GL_RENDERBUFFER_OES]; 
} 

.

glOrthof() 행의 주석을 지우면 내 디스플레이를 볼 수 있지만 정사각형이지만 전체 장면의 크기를 변경하려면 카메라를 안팎으로 이동하고 싶습니다.

내가 무엇을 잘못했기 때문에 glFrustumf()가 선명한 색만 표시합니까?

+0

나는 glTranslatef()를 사용하여 secene 안팎으로 카메라를 이동한다는 것을 잊어 버렸다. –

답변

2

짧은 대답 : 잘못된 방향으로보고 있습니다.

긴 답변 : 정자 기둥이없는 동안 절두체가 대칭입니다. 따라서 모델이 glOtho 경우에 표시되도록 설정되어 있으면 glFrustum에서 표시되지 않을 수 있습니다. 또한 glOrtho와 glFrustum을 함께 사용하면 안됩니다. 왜냐하면 행렬이 곱 해져서 반드시 재미있는 투영 행렬을 산출하기 때문입니다.

http://www.xmission.com/~nate/tutors.html에서 Nate Robins의 GL 튜터를 사용하여 glFrustum 및 glOrtho ("프로젝션"응용 프로그램에서)를 실험 할 수 있습니다.