سؤال

I'm currently using OpenGL ES 2.0 under GLKView on the new iPad. It seems, whenever I make the call to glColor4f, nothing happens (ie. it doesn't color the polygons I want it to) other than causing a GL_INVALID_OPERATION error. Then, as soon as I try to load a texture, I get this error message: Error loading file: The operation couldn't be completed. (GLKTextureLoaderErrorDomain error 8.)

But before the glColor4f is called, everything works fine. Here's my code below for drawInRect:

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

    // Render the object with GLKit
    self.effect.texture2d0.enabled        = NO;
    self.effect.transform.modelviewMatrix = _defaultModelMatrix;

    [self.effect prepareToDraw];

    // Render the grid
    glBindBuffer(GL_ARRAY_BUFFER, _gridVertexBuffer);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, 0);

    glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
    glDrawArrays(GL_TRIANGLES, 0, TRIANGLES * 6);

    glDisableVertexAttribArray(GLKVertexAttribPosition);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

If anyone can help, I'd really appreciate it. Some things to point out though. The object I'm trying to color is stored in a VBO and is rendered fine, in a white color (even though I'm trying to color it red).

Thanks

هل كانت مفيدة؟

المحلول

glColor4f is not an OpenGLES2.0 command (it's from GLES1.1)

What you want to do is declare a uniform in your shader called 'color' (or something similar), set that uniform as you typically would with any shader uniform, and multiply your fragment color with that uniform before writing the pixel.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top