D.V.D
Make a wish
- Reaction score
- 73
So Im starting to use OpenGl for the first time and I'm following this tutorial : http://xoax.net/cpp/crs/opengl/lessons/Lesson3/
In that specific lesson, the video is showing how to draw stripes for the american flag. I wanted to just draw the stripes on my screen and looking at my code for DrawStripes and his, I cannot find any major difference to not allow my code to work. His generates stripes across the screen, each with a different color. Mine does not change the screen at all D: Im not sure if I'm doing somethnig wrong with setting color or anything but here's my code. The screen remains the same black color.
His code for draw stripes:
In that specific lesson, the video is showing how to draw stripes for the american flag. I wanted to just draw the stripes on my screen and looking at my code for DrawStripes and his, I cannot find any major difference to not allow my code to work. His generates stripes across the screen, each with a different color. Mine does not change the screen at all D: Im not sure if I'm doing somethnig wrong with setting color or anything but here's my code. The screen remains the same black color.
Code:
// A Simple OpenGL Project
// Author: Michael Hall
//
// This C++ code and project are provided "as is"
// without warranty of any kind. For personal use only,
// not for distribution. Copyright 2010 XoaX.
#include "stdafx.h"
#include <glut.h>
#include <cmath>
//Identifiers
void DrawCircle ();
void DrawStripes ();
void DrawStripes () {
for ( int i=0; i < 13; i++ ) {
if ( i % 2 == 0 ) {
glColor3f(0.5,1.0,1.0);
}
else {
glColor3f(1.0,.5,1.0);
}
float s_start_x = 0.0;
float s_end_x = 1.0;
float s_start_y = i*(1/13);
float s_end_y = (i+1)*(1/13);
glBegin(GL_QUADS);
glVertex3f(s_start_x, s_start_y, 0.0); // 0,0 | 0,.1 | 0,.2
glVertex3f(s_end_x, s_start_y, 0.0); // 1,0 | 1,.1 | 1,.2
glVertex3f(s_end_x, s_end_y, 0.0); // 1,.1 | 1,.2 | 1,.4
glVertex3f(s_start_x, s_end_y, 0.0); // 0,0 | 0,.2 | 0,.4
glEnd();
}
}
void DrawCircle () {
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.25,0.25,0);
glVertex3f(0.5,0.5,0);
glVertex3f(0.5,0.75,0);
glEnd();
}
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
DrawStripes();
/*glBegin(GL_QUADS);
glVertex3f(0.1,0.1,0.0);
glVertex3f(0.9,0.1,0.0);
glVertex3f(0.1,.9,0.0);
glVertex3f(.9,.9,0.0);
glEnd();*/
glFlush();
}
void Initialize() {
glClearColor(0.0, 0.0, 0.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(1280, 720);
glutInitWindowPosition(200, 200);
glutCreateWindow("Research Engine OpenGL");
Initialize();
glutDisplayFunc(Draw);
glutMainLoop();
return 0;
}
His code for draw stripes:
Code:
void DrawStripes() {
for (int iStripeIndex = 0; iStripeIndex < 13; ++iStripeIndex) {
// Alternate stripe colors
if (iStripeIndex % 2 == 0) {
glColor3f(204.0/255.0, 0.0, 0.0);
} else {
glColor3f(1.0, 1.0, 1.0);
}
float fStartX = 0.0;
float fEndX = 1.0;
float fStartY = iStripeIndex*(1.0/13.0);
float fEndY = (iStripeIndex + 1)*(1.0/13.0);
// The last seven stripes are shorter
if (iStripeIndex > 5) {
fStartX = 0.76/1.9;
}
glBegin(GL_QUADS);
glVertex3f(fStartX, fStartY, 0.0);
glVertex3f(fEndX, fStartY, 0.0);
glVertex3f(fEndX, fEndY, 0.0);
glVertex3f(fStartX, fEndY, 0.0);
glEnd();
}
}