I’m trying to port a simple OpenGL ES 2.0 renderer I made for iOS to OS X desktop and I’m running into into a ‘nothing rendering’ problem, and I don’t get any errors reported so I’m at a loss what to do. So far I’ve narrowed the problem down to a call I make to glVertexAttrib4f, which is only working in OS X. Can anyone take a look at the following code and see why the call to glVertexAttrib4f doesn’t work on desktop?:
void Renderer::drawTest()
{
gl::clear( mBackgroundColor );
static Vec2f vertices[3] = { Vec2f( 0, 0 ), Vec2f( 0.5, 1 ), Vec2f( 1, 0 ) };
static int indices[3] = { 0, 1, 2 };
mShader.bind();
glEnableVertexAttribArray( mAttributes.position );
glVertexAttribPointer( mAttributes.position, 2, GL_FLOAT, GL_FALSE, 0, &vertices[0] );
#ifdef USING_GENERIC_ARRAY_POINTER
// works in iOS /w ES2 and OSX:
static Color colors[3] = { Color( 0, 0, 1 ), Color( 0, 0, 1 ), Color( 0, 0, 1 ) };
glEnableVertexAttribArray( mAttributes.color );
glVertexAttribPointer( mAttributes.color, 3, GL_FLOAT, GL_FALSE, 0, &colors[0] );
#else // using generic attribute
// works in iOS, but doesn't work in OSX ?:
glVertexAttrib4f( mAttributes.color, 0, 1, 1, 1 );
#endif
glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, &indices[0] );
errorCheck(); // calls glGetError, which always returns GL_NO_ERROR
}
note: this is example code that I stripped out of something much more complex, please forgive me for not making it more complete.
versions:
desktop OS X is 2.1 ATI-7.18.18
iPhone simulator is OpenGL ES 2.0 APPLE
The reason why drawing wasn’t happening while calling
glVertexAttrib4fwas thatmAttributes.colorwas automatically bound to location 0; I did not callglBindAttribLocation, but instead relied on the originally bounded values during linking. Apparently in GL compatibility context (2.1 in OS X), glDrawElements may not draw anything if whatever attribute is bounds at location 0 is not ‘enabled’, i.e. you callglEnableVertexAttribArrayon it.So, when I explicitly bind position to 0 and color to 1, I can call glVertexAttrib*() on the color attribute and it will draw just fine in both OS X (legacy) and ES 2.