Results 1 to 5 of 5

Thread: How to draw two shapes at the same time?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    How to draw two shapes at the same time?

    Good morning!

    I was trying to draw two triangle_fan at the same time with OpenGL ES 2.Unfortunately, have been stuck in this problem for a pretty long time,for there's no such example.

    So, can anyone help me out?Really appreciate it!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: How to draw two shapes at the same time?

    What do you mean by "same time"? I think all you need to do is draw the two fans and refresh the display.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    Re: How to draw two shapes at the same time?

    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, eyeVertice);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, 1, 0, eyeColors);
    glEnableVertexAttribArray(ATTRIB_COLOR);

    glUseProgram(program);

    glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY);

    glDrawArrays(GL_TRIANGLE_FAN, 0, num);



    here's a piece of the code , I try to have it executed twice with different "eyeVertice", for showing two eyes.But it showed quite strange result.The eyes totally mix up.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: How to draw two shapes at the same time?

    Can we have a look at the contents of your eyeVertice array.
    Usually for such a thing, you will store the two triangle fans consecutively in the array.
    Code :
    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, eyeVertice);
    This tells me that u r using 2d coordinates are u doing this in screen space? if so also make sure that the ortho graphic projection matrix is setup accordingly so that the geometry may be correctly visible.
    Regards,
    Mobeen

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    Re: How to draw two shapes at the same time?

    - (void)makeEyeWithXGLfloat)x YGLfloat)y verticeGLfloat *)eyeVertices vertexNumberGLint)num{

    GLfloat xStep = -1.0f / (num - 2);


    eyeVertices[0] = x;
    eyeVertices[1] = y;
    eyeVertices[2] = x;
    eyeVertices[3] = y - 0.5f;
    eyeVertices[num * 2 - 2] = x;
    eyeVertices[num * 2 - 1] = y + 0.5f;


    /*
    #### x*x/1 + (y - 0.5)*(y - 0.5) = 0.25
    */
    int direction = -1;
    for (GLint i=4; i<(num - 1) * 2; i+=2) {
    if (eyeVertices[i - 2] + xStep <= -0.5f) {
    xStep = -xStep;
    direction = -direction;
    }
    eyeVertices[i] = eyeVertices[i - 2] + xStep;
    eyeVertices[i + 1] = direction * sqrt(0.25 - eyeVertices[i] * eyeVertices[i]) + 0.5;

    }

    }

    I use this method to make the eyeVertice.Actually it's a semicircle.

    Can you give me some pieces of code that draw two rectangles line up with each other horizontally with the parameter TRIANGLE_FAN?I need an example to imitate.

Similar Threads

  1. Trouble making draw shapes follow mouse
    By throwaway in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-29-2013, 05:18 AM
  2. Draw 2d shapes on window without viewport.
    By the_transltr in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-05-2012, 09:53 AM
  3. Code to draw shapes
    By annette in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-17-2011, 08:31 AM
  4. Draw Shapes With Mouse Drag
    By Usman in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-18-2010, 03:26 PM
  5. tessellated shapes don't draw correctly
    By wwuster in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-09-2009, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean