Draw 4 stars in screen with OpenGL
Screenshot:
Code:
#include <windows.h> #include <GL\glut.h> void myInit (void) { glClearColor(0.0,0.0,0.0,0.0); // sets background color to white // sets a point to be 4x4 pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 400.0); // the display area in world coordinates. } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clears the screen ;// setsthe drawing colour glPointSize(4.0); //Axis glColor3f(1.0f,0.0f,1.0f) ; glBegin(GL_LINES); glVertex2i(255,0); glVertex2i(255,500); glVertex2i(0,200); glVertex2i(500,200); glEnd(); glColor3f(1.0f,0.0f,0.0f); // glColor3f(1.0f,1.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (40,50); glVertex2i (60,50); //left glVertex2i (40,50); glVertex2i (40,80); //top glVertex2i (40,80); glVertex2i (60,80); //right glVertex2i (60,50); glVertex2i (60,80); glEnd(); //BOTTOM TRIANGLE glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (40,50); glVertex2i (60,50); //left glVertex2i (40,50); glVertex2i (50,30); //RIGHT glVertex2i (60,50); glVertex2i (50,30); glEnd(); //RIGHT TRIANGLE glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); //bottom glVertex2i (60,50); glVertex2i (60,80); glVertex2i (60,50); glVertex2i (70,60); glVertex2i (60,80); glVertex2i (70,60); glEnd(); //left triangle glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); glVertex2i (40,50); glVertex2i (40,80); glVertex2i (40,50); glVertex2i (30,64); glVertex2i (40,80); glVertex2i (30,62); glEnd(); //Top triangle glColor3f(1.0f,0.0f,0.0f) ; glBegin(GL_POLYGON); glVertex2i (40,80); glVertex2i (60,80); glVertex2i (40,80); glVertex2i (50,90); glVertex2i (60,80); glVertex2i (50,90); glEnd(); glColor3f(1.0f, 0.0f, 0.0f); glRectf(120,120, 100, 100); glColor3f(1.0f,1.0f,0.0f) ; glBegin(GL_POLYGON); //RIGHT glVertex2i (120,120); glVertex2i (120,100); glVertex2i (120,120); glVertex2i (150,110); glVertex2i (120,100); glVertex2i (150,110); glEnd(); glBegin(GL_LINES); //RIGHT glVertex2i (120,120); glVertex2i (120,100); glVertex2i (120,120); glVertex2i (150,110); glVertex2i (120,100); glVertex2i (150,110); glEnd(); //left glBegin(GL_POLYGON); glVertex2i (100,120); glVertex2i (62,107); glVertex2i (100,100); glVertex2i (62,107); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (100,120); glVertex2i (110,130); glVertex2i(110,130); glVertex2i (120,120); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (100,98); glVertex2i(110,70); glVertex2i (120,98); glVertex2i(110,70); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (350,315); glVertex2i (350,290); glVertex2i(370,290); glVertex2i (370,290); glVertex2i (370,315); glVertex2i (350,315); glVertex2i (370,315); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,315); glVertex2i (362,325); glVertex2i (370,315); glVertex2i (362,325); glEnd(); // glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (370,290); glVertex2i (385,305); glVertex2i (370,315); glVertex2i (385,305); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (320,305); glVertex2i (350,315); glVertex2i (320,305); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (350,290); glVertex2i (362,270); glVertex2i (370,290); glVertex2i (362,270); glEnd(); glColor3f(0.0f,0.0f,1.0f) ; glBegin(GL_POLYGON); glVertex2i (70,275); glVertex2i (70,290); glVertex2i(70,290); glVertex2i(85,290); glVertex2i(85,290); glVertex2i(85,275); glVertex2i(85,275); glVertex2i(70,275); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,275); glVertex2i(76,220); glVertex2i(85,275); glVertex2i(76,220); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(85,275); glVertex2i(120,280); glVertex2i(85,290); glVertex2i(120,280); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,275); glVertex2i(38,280); glVertex2i(70,290); glVertex2i(38,280); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex2i(70,290); glVertex2i(76,335); glVertex2i(85,290); glVertex2i(76,335); glEnd(); glFlush(); // sends all output to display; } int main (int argc, char **argv) { glutInit (&argc, argv); // to initialize the toolkit; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // sets the display mode glutInitWindowSize (640, 480); // sets the window size glutInitWindowPosition (10, 10); // sets the starting position for the window glutCreateWindow ("My first OpenGL program!"); // creates the window and sets the title glutDisplayFunc (myDisplay); myInit(); // additional initializations as necessary glutMainLoop(); // go into a loop until event occurs return 0; }