I am trying to draw a triangle using GL_POLYGON but for some reason it is taking the whole window..
...
typedef struct myTriangle {
float tx;
float ty;
} myTriangle;
std::vector<myTriangle> container;
void display() {
glClear(GL_COLOR_BUFFER_BIT);
for(int i = 0; i < (int)container.size(); ++i) {
glBegin(GL_POLYGON);
glColor3f(0.35, 0.0, 1.0);
glVertex2f(container.at(i).tx, container.at(i).ty + 20);
glVertex2f(container.at(i).tx - 20, container.at(i).ty - 20);
glVertex2f(container.at(i).tx + 20, container.at(i).ty - 20);
glEnd();
}
glutSwapBuffers();
}
...
int main(int argc, char** argv) {
myTriangle t1;
container.push_back(t1);
container.back().tx = (float)0.;
container.back().ty = (float)0.;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
// initializations
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow( "Transformer" );
glClearColor(1.0, 1.0, 1.0, 1.0);
// global variable initialization
GW = GH = 200;
// callback functions
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(mouseMove);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
It should be drawing an equilateral 40x40 triangle at the origin (0,0) in a 400x400 window. Is there something I did wrong?