2012-01-19 3 views
0

나는 this tutorial을 따라 갔고 현재 큐브를 그리는 클래스를 만들려고합니다. 클래스는 setup이라는 함수에서 버퍼를 채우고 draw라는 함수로 버퍼를 그립니다.iphone 큐브 클래스 만들기

아무런 오류가 없지만 화면에 아무 것도 표시되지 않습니다.

내 질문은 기본적으로 큐브를 렌더링 할 수있는 클래스를 만드는 방법입니다.

Xcode 4.2, Opengl 및 Objective-C 사용. 내 뷰포트 및 시각 설정의 배열에 문제가 언급 한 바와 같이

[편집]

-(void)SetShader:(GLuint)InShader 
{ 
glUseProgram(InShader); 

_positionSlot = glGetAttribLocation(InShader, "Position"); 
_colorSlot = glGetAttribLocation(InShader, "SourceColor"); 
glEnableVertexAttribArray(_positionSlot); 
glEnableVertexAttribArray(_colorSlot); 

_projectionUniform = glGetUniformLocation(InShader, "Projection"); 
_modelViewUniform = glGetUniformLocation(InShader, "Modelview"); 

_texCoordSlot = glGetAttribLocation(InShader, "TexCoordIn"); 
glEnableVertexAttribArray(_texCoordSlot); 
_textureUniform = glGetUniformLocation(InShader, "Texture"); 
} 

-(void)SetupVBO 
{ 
    GLuint vertexBuffer; 
    glGenBuffers(1, &vertexBuffer); 
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); 
    glBufferData(GL_ARRAY_BUFFER, sizeof(CubeVertices), CubeVertices, GL_STATIC_DRAW); 

    GLuint indexBuffer; 
    glGenBuffers(1, &indexBuffer); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); 
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(CubeIndices), CubeIndices, GL_STATIC_DRAW); 
} 

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

glVertexAttribPointer(_texCoordSlot, 2, GL_FLOAT, GL_FALSE, 
         sizeof(Vertex), (GLvoid*) (sizeof(float) * 7));  

glDrawElements(GL_TRIANGLES, sizeof(CubeIndices)/sizeof(CubeIndices[0]), GL_UNSIGNED_BYTE, 0); 
} 

-(void)render:(CADisplayLink*)displayLink 
{ 
glClearColor(0, 0, 0.2, 1.0); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glEnable(GL_DEPTH_TEST); 

CC3GLMatrix *projection = [CC3GLMatrix matrix]; 
float h = 4.0f * self.frame.size.height/self.frame.size.width; 
[projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:10]; 
glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix); 

CC3GLMatrix *modelView = [CC3GLMatrix matrix]; 
[modelView populateFromTranslation:CC3VectorMake(0, 0, -7)]; 
[modelView translateBy:CC3VectorMake(0,5,0)]; 
glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix); 

glViewport(0, 0, self.frame.size.width, self.frame.size.height); 

[m_cube draw]; 

[_context presentRenderbuffer:GL_RENDERBUFFER]; 
} 
+0

코드를 게시하십시오. –

+1

질문이 막연합니다. 변경없이 튜토리얼을 따라 가면 되나요? 그렇다면 어떤 변화가 일어나지 않았습니까? 일반적으로, OpenGL 상태 머신이 이상하게 설정되어 있기 때문에 OpenGL은 아무 것도 그리지 않습니다. 'glViewport()','glOrtho()','gluPerspective()'및/또는'glFrustum()'에 대한 호출을 설정하는 방법을 보여주는 코드를 게시하면 도움이 될 것입니다. – user1118321

+0

필자의 관련 코드 – Dave

답변

0

그것은이었다.