Monday, 20 April 2015

OpenGL program to render a 2D triangle









#include<GL/glut.h>
void display()   {

glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);

    glColor3f(1,0,0);
    glVertex2f(-200,-150);

    glColor3f(0,1,0);
    glVertex2f(0,150);

    glColor3f(0,0,1);
    glVertex2f(200,-150);
glEnd();
glFlush();

}
void myinit()    {

glClearColor(1,1,1,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-500,500,-500,500);

}
void main(int argc,char** argv)   {

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(500,500);
glutInitWindowPosition(50,50);
glutCreateWindow("2D triangle");
glutDisplayFunc(display);
myinit();
glutMainLoop();

}

No comments:

Post a Comment

Total Pageviews