Results 1 to 3 of 3

Thread: problem with glDrawArrays

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    1

    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();
    }

  2. #2
    Junior Member
    Join Date
    Dec 2010
    Posts
    4

    Re: problem with glDrawArrays

    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>

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    4

    Re: problem with glDrawArrays

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

Similar Threads

  1. glDrawArrays problem
    By Min in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 02-17-2005, 04:51 PM
  2. glVertexPointer, glDrawArrays?
    By shellee in forum OpenGL ES general technical discussions
    Replies: 2
    Last Post: 11-03-2004, 03:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •