Newbie Triangle creation help

This is a discussion on Newbie Triangle creation help within the Game Programming forums, part of the General Programming Boards category; hi guys im trying to create 5 random triangles of the same size at different points of canvas. I'm using ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Smile Newbie Triangle creation help

    hi guys im trying to create 5 random triangles of the same size at different points of canvas. I'm using glVertexPointer function with no luck. I either have them line up one on top of each other or cause them to be different sizes at different points using glTranslatef function.
    I have started learning Open GL recently so I'm very new. Any help would be greatly appreciated.
    Thanks guys.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You're familiar with perspective, right? Things that are farther away look smaller? If you don't want perspective, you should make sure all your triangles have the same z value.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    here are my two triangles ... is Vertices a correct choice ?
    and how do i have them at a different point of the canvas, as you can see my Z value is 0.0f for both.
    I dont want to use translateF since im using it for bouncing the triangles along the screen at random.
    Right now those two are on top of each other (obviously).
    const GLfloat triVertices[] =
    {
    0.0f, 0.25f, 0.0f,
    -0.25f, -0.25f, 0.0f,
    0.25f, -0.25f, 0.0f
    };


    const GLfloat triVertices2[] =
    {
    0.0f, 0.25f, 0.0f,
    -0.25f, -0.25f, 0.0f,
    0.25f, -0.25f, 0.0f
    };

    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity(); //Reset the Current Modelview Matrix


    glTranslatef(moveX, moveY, -6.0f); //move up 2 Units and into the screen 6.0


    glVertexPointer(3, GL_FLOAT, 0, triVertices);



    glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, 0, triColors);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);


    glTranslatef((moveX, moveY, -6.0f); //move up 2 Units and into the screen 6.0
    glVertexPointer(3, GL_FLOAT, 0, triVertices2);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, triColors);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);




    moveX += xstep;
    moveY += ystep;
    if(moveX > 2.0 || moveX < -2.0)
    {
    xstep = -xstep;
    }

    if(moveY > 3.2 || moveY < -3.2)
    {
    ystep = -ystep;

    }
    Last edited by ernestnapoleon; 03-11-2009 at 10:27 AM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So why not make it say
    Code:
    const GLfloat triVertices2[] =
    {
    2.0f, 2.25f, 0.0f,
    1.75f, 1.75f, 0.0f,
    2.25f, 1.75f, 0.0f
    };
    (where I obviously just added 2 to the x and y coordinates -- it might be too much but you get the idea). If you wanted them to not move together, then you're going to have to do more work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive Triangle Function
    By w2look in forum C Programming
    Replies: 14
    Last Post: 11-13-2010, 02:31 PM
  2. Right Triangle Program
    By BSmith4740 in forum C# Programming
    Replies: 9
    Last Post: 02-27-2008, 12:24 AM
  3. Resizing a triangle. Why is my code not working?
    By gozu in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2007, 06:40 PM
  4. Stupid Logic Problem Need Outside Viewpoint
    By RP319 in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2005, 10:59 PM
  5. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 01:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21