glGenBuffers() generiert keine buffer oder zeichnet nix :(

Dylans Ghost

Dylans Ghost

Aktives Mitglied
Thread Starter
Dabei seit
25.09.2012
Beiträge
110
Reaktionspunkte
2
Hallo, ihr Prinzen von Maine,
der VBO code, mit 7.3 generiert, funktioniert.
Beim ersten Versuch mit 8.3 hatte ich den code in eine category ausgelagert, da blieb das buffer array leer.
Zurück nach OpenGLView geschoben - hat es geklappt, aber das Fenster blieb schwarz.
Hoffentlich könnt ihr mir helfen, danke im voraus.
Uwe

Code:
- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    if(backgroundColor == 1) glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    else  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0, 0, -10);
    if(readyForDisplay)
    {
      //  glCallList(indicatorList); // Test o.k.
        [self drawIndicatorBuffers];
    }
    [self glError];
    [self.openGLContext flushBuffer];
}
-(void)setupIndicator
{
    readyForDisplay = false;
    indicatorBuf = 3;
    glDeleteBuffers(GL_MAX_BUFFERS, indicatorBuffers);
    glGenBuffers(indicatorBuf , indicatorBuffers);
    [self calculateSphere];
    [self prepareIndicatorBuffers];
    readyForDisplay = true;
    [self setNeedsDisplay:true];
}
- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    if(backgroundColor == 1) glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    else  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0, 0, -10);
    if(readyForDisplay) [self drawIndicatorBuffers];
    [self glError];
    [self.openGLContext flushBuffer];
}
-(void)prepareIndicatorBuffers
{
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[0]);
    glBufferData(GL_ARRAY_BUFFER,self.indicatorBufferSize, indicatorVertex, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[1]);
    glBufferData(GL_ARRAY_BUFFER, self.indicatorBufferSize, indicatorNormal, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[2]);
    glBufferData(GL_ARRAY_BUFFER, self.indicatorBufferSize , indicatorColor, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
-(void)drawIndicatorBuffers
{
    unsigned idx = 0;
    GLfloat sc = 0.1;
    GLfloat xx,yy;
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[0]);
    glVertexPointer(3, GL_FLOAT, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[1]);
    glNormalPointer(GL_FLOAT, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, indicatorBuffers[2]);
    glColorPointer(3, GL_FLOAT, 0, 0);
    
    xx = sin(loopIndex/(float)interval * 2.0 * PI);
    yy = cos(loopIndex/(float)interval * 2.0 * PI );
    glPushMatrix();
    glTranslatef(xx, yy, 0.0);
    glScalef(sc,sc,sc);
    glDrawArrays(GL_TRIANGLES, 0, 3840);
    glPopMatrix();
    [self disableIndicatorBuffers];
    [self setNeedsDisplay:YES];
}

-(void)disableIndicatorBuffers
{
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
}
 
Zurück
Oben Unten