Reputation: 165
I'm following the xoax.net tutorials for OpenGL in C++, and I am stuck on drawing the stripes in the U.S. flag using a for loop. I just get a blue screen (since I set the background colour to blue). Here is the code for the 'DrawStripes' function:
void DrawStripes() {
for (int x = 0; x < 13; ++x) {
if (x % 2 == 0) {
glColor3f(204/255, 0, 0);
} else {
glColor3f(1, 1, 1);
}
float fStartX = 0;
float fEndX = 1;
float fStartY = x * (1/13);
float fEndY = (x + 1) * (1/13);
if (x > 5) {
fStartX = .76/1.9;
}
glBegin(GL_QUADS);
glVertex3f(fStartX, fStartY, 0);
glVertex3f(fEndX, fStartY, 0);
glVertex3f(fEndX, fEndY, 0);
glVertex3f(fStartX, fEndY, 0);
glEnd();
}
}
(I have put this function in the 'draw' function so it isn't just I'm not telling it to use the function) Any ideas?
--- EDIT --- Here are the 'Draw' and 'Initialize' functions:
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
DrawStripes();
glFlush();
}
void Initialize() {
glClearColor(0.0, 0.0, 0.5, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
Upvotes: 1
Views: 1528
Reputation: 5520
1/13 is 0 in C++. Been there, done that. For float constants you want to use 1.0f/13.0f.
Upvotes: 5