This simple program was designed to draw 13 even, red and white stripes placed alternately, as in the US flag.
// A Simple OpenGL Project
// Author: Michael Hall
//
// This C++ code and project are provided "as is" without warranty of any kind.
//
// Copyright 2010 XoaX - For personal use only, not for distribution
//
// Elaborated by me :)
#include <glut.h>
void DrawStripes(const int quantity)
{
glBegin(GL_QUADS);
for(int i=1; i <= quantity ; i++)
{
if(i%2)
glColor3f(1.0,0.0,0.0);
else
glColor3f(1.0,1.0,1.0);
glVertex2f(0,static_cast<float>(i-1)/static_cast<float>(quantity));
glVertex2f(1.0,static_cast<float>(i-1)/static_cast<float>(quantity));
glVertex2f(0,static_cast<float>(i)/static_cast<float>(quantity));
glVertex2f(1.0,2*static_cast<float>(i)/static_cast<float>(quantity));
}
}
void Draw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
DrawStripes(13);
glEnd();
glFlush();
}
void Initialize()
{
glClearColor(0.0, 0.0, 102.0/255.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(int iArgc, char** cppArgv)
{
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(950,500);
glutInitWindowPosition(200, 200);
glutCreateWindow("Rough draft");
Initialize();
glutDisplayFunc(Draw);
glutMainLoop();
return 0;
}
This is how it looks in practice:

Why there are blue triangles on the foreground? I’ve specified only “QUADS” inside Draw/DrawStripes functions.
I think you’re drawing the quad vertices in the wrong order. They should be counterclockwise, but you’re drawing a ‘twisted’ quad.
Try swapping the 3rd and 4th vertex in your for loop.