Im trying to draw custom openGL objects using cocos2dx. Currently i have subclassed a “Node” and am trying to override its “draw(Renderer* renderer, const Mat4 &transform, uint32_t flags)” function to do my custom drawing.
This is what im trying to draw (a simple triangle) and heres how im trying to setup my vertices, shaders and draw functions…
const GLfloat vertices[9] = {
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f
};
void MyNode::loadOurShaders(){
GLProgram* myShader = new GLProgram();
myShader->initWithFilenames("shader.vert", "shader.frag");
myShader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
myShader->link();
myShader->updateUniforms();
}
void MyNode::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags){
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE,0, vertices);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
While the draw function is being called, i dont see anything on the screen. Ive setup my ‘director’ and set its ‘EAGLView’ also. I dont know what I’m missing here and what i should do to see my triangle on the screen!