# Newbie Triangle creation help

• 03-10-2009
ernestnapoleon
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.
• 03-10-2009
tabstop
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.
• 03-11-2009
ernestnapoleon
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;

}
• 03-11-2009
tabstop
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.