problem with glDrawArrays

Hi,
I have written following openglES code to render the shape.
But it is drawing any thing. blank screen is appearing.
Where am I doing the mistake.
Could you please help me .

Thanks

void CAppView::drawScene2()
{
glClearColor( 0.f, 0.f, 0.f, 1.f );
glViewport( 0, 0, 240, 320 );
glPushMatrix();

const GLfloat pyramidVertices[] = {
       // Our pyramid consists of 4 triangles and a square base.
       // We'll start with the square base
       -1.0, -1.0, 1.0,            
       1.0, -1.0, 1.0,             
       1.0, -1.0, -1.0,            
       -1.0, -1.0, -1.0,           

       // Front face
       -1.0, -1.0, 1.0,            
       1.0, -1.0, 1.0,             
       0.0, 1.0, 0.0,              
                                   

       // Rear face
       1.0, -1.0, -1.0,   
       -1.0, -1.0, -1.0,  
       0.0, 1.0, 0.0,     

       // left face
       -1.0, -1.0, -1.0,           // bottom rear
       -1.0, -1.0, 1.0,            // bottom front
       0.0, 1.0, 0.0,              // top centre

       // right face
       1.0, -1.0, 1.0,             // bottom front
       1.0, -1.0, -1.0,            // bottom rear
       0.0, 1.0, 0.0               // top centre
   };    

glEnableClientState ( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, pyramidVertices );

glColor4f(1.0, 0.0, 0.0, 1.0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);


glPopMatrix();
}

Hi, techkatta
Try to use glTranslatef(0,0,-1.0f); before drawing. If still nothing is on screen try drawing just a simple face.
Here is an example with 5 points.
<code>
GLfloat test_vertices[] = {
-1, -1, 0, // 1
1, -1, 0, // 2
-1, 1, 0, // 3
1, 1, 0, // 4
1, -1, 0 // 5(2)
};

glVertexPointer( 3, GL_FLOAT, 0, test_vertices );
glEnableClientState( GL_VERTEX_ARRAY );

glLoadIdentity();
glTranslatef ( 0, 0, -0 );
glColor4f(1,0,0,1);
glDrawArrays( GL_TRIANGLE_FAN, 0, 5 );

glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
</code>

The correct array for vertices is:
GLfloat vertCoords[] = {
-1, 1, 0,
-1, -1, 0,
1, -1, 0,
1, 1, 0,
-1, 1, 0
};

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.