2012-02-21 3 views
2

OpenGL과 함께 새로 만들었습니다. GLOST를 사용하여 iOS 5에 GLKit을 사용하여 행을 성공적으로 표시했지만 GL_POINTS로 점을 표시하면 문제가 발생합니다. 특히 하나의 픽셀 만 표시 할 수는 없습니다. 나는 성공을 거두지 못한 채 웹을 샅샅이 뒤졌고, 그래서 나는 누군가가 내가 빠진 것을 지적 할 수 있기를 바라고있다. 시간에 대한GLKit (iOS 5)에서 GL_POINTS 사용

여기 내 테스트 코드는 ...

//positions and colors, vertices and indices... 
typedef struct { 
    float Position[2]; 
    float Color[4]; 
} Vertex; 

const Vertex Vertices[] = { 
    {{50, 50}, {0, 0, 1, 1}}, 
    {{200, 50}, {0, 0, 1, 1}}, 
    {{200, 200}, {0, 0, 1, 1}}, 
    {{50, 200}, {0, 0, 1, 1}} 
}; 

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


@interface AppViewController() { 
    GLuint _vertexBuffer; 
    GLuint _indexBuffer; 
} 

... 
//some unrelated properties, the @implementation and other methods 
... 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 
    if (!self.context) NSLog(@"Failed to create ES context"); 

    GLKView *view = (GLKView *)self.view; 
    view.context = self.context; 
    [EAGLContext setCurrentContext:self.context]; 

    self.effect = [[GLKBaseEffect alloc] init]; 

    GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(0, self.view.bounds.size.width, 0, self.view.bounds.size.height, -1024, 1024); 
    self.effect.transform.projectionMatrix = projectionMatrix; 

    glGenBuffers(1, &_vertexBuffer); 
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); 
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); 

    glGenBuffers(1, &_indexBuffer); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer); 
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW); 
} 

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {  
    glClearColor(1, 1, 1, 1); 
    glClear(GL_COLOR_BUFFER_BIT); 

    [self.effect prepareToDraw]; 

    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer); 

    glEnableVertexAttribArray(GLKVertexAttribPosition);   
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position)); 
    glEnableVertexAttribArray(GLKVertexAttribColor); 
    glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color)); 

    //this worked for drawing my lines... 
    //glLineWidth(10); 
    //glDrawElements(GL_LINE_LOOP, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0); 

    //this does NOT work for drawing 10-pixel points. single pixel only. 
    glEnable(GL_POINT_SMOOTH); 
    glPointSize(10); 
    glDrawElements(GL_POINTS, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0); 
} 

감사합니다!

답변

7

glPointSize()은 OpenGL ES 2.0의 일부라고 생각하지 않습니다. 정점 셰이더

시도 설정 ...

gl_PointSize = 10.0; //has to be a floating point value 

....

+0

값이 부동 소수점 값이어야하거나 "유형 불일치"가 발생하면 'int'에서 'float'로 변환 할 수 없습니다. "오류가 발생합니다. GLSL은 java가 아니며 값을 변환하지 않습니다. –

관련 문제