Hi, I am also attempting to draw with custom OpenGL, but it draws nothing on the screen.
void CustomSprite::draw(float x, float y, float rot)
{
if (NULL == m_tex)
{
return;
}
CC_NODE_DRAW_SETUP();
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
GL::bindTexture2D( m_tex->getName() );
const float w = m_tex->getPixelsWide();
const float h = m_tex->getPixelsHigh();
kmGLPushMatrix();
kmGLTranslatef(x, y, 0.0f);
kmGLRotatef(rot, 0.0f, 0.0f, 1.0f);
kmGLScalef(w, h, 1.0f);
static const float box[] =
{
-0.5f, -0.5f,
0.5f , -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f
};
const float u1 = 0;
const float u2 = w;
const float v1 = 0;
const float v2 = h;
const float tex[] = {
u1, v1,
u2, v1,
u1, v2,
u2, v2
};
const GLubyte colors[] = {255, 255, 255, 255};
glVertexAttribPointer( GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0 , &box);
glVertexAttribPointer( GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, 0, &tex);
glVertexAttribPointer( GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, &colors);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
kmGLPopMatrix();
CC_INCREMENT_GL_DRAWS(1);
}
I call this function from the overriden Scene::draw() function.
I wonder what is the problem with above function? Any help would be greatly appreciated.