Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/gl.h>
- #include <GL/glut.h>
- #include <math.h>
- void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius)
- {
- int i;
- int triangleAmount = 50;
- GLfloat twicePi = 2.0f * 3.1416;
- glBegin(GL_TRIANGLE_FAN);
- glVertex2f(x, y);
- for(i = 0; i <= triangleAmount; i++) {
- glVertex2f(x + (radius * cos(i * twicePi / triangleAmount)), y + (radius * sin(i * twicePi/ triangleAmount)));
- }
- glEnd();
- }
- void display(void)
- {
- /* clear all pixels */
- glClear (GL_COLOR_BUFFER_BIT);
- /* draw white polygon (rectangle) with corners at
- * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
- */
- glColor3f(0.0f, 0.5f, 1.0f);//baby Blue Sky
- glBegin(GL_POLYGON);
- glVertex3f (00, 50, 0.0);
- glVertex3f (100, 50, 0.0);
- glVertex3f (100, 100, 0.0);
- glVertex3f (00, 100, 0.0);
- glEnd();
- glColor3f(0.1f, 0.8f, 0.3f);//Ground
- glBegin(GL_POLYGON);
- glVertex3f (00, 00, 0.0);
- glVertex3f (100, 00, 0.0);
- glVertex3f (100, 50, 0.0);
- glVertex3f (00, 50, 0.0);
- glEnd();
- glColor3f(0.1f, 0.1f, 0.1f);//Dark grey//Road
- glBegin(GL_POLYGON);
- glVertex3f (0, 25, 0.0);
- glVertex3f (100, 25, 0.0);
- glVertex3f (100, 38, 0.0);
- glVertex3f (0, 38, 0.0);
- glEnd();
- glColor3f(0.3f, 0.3f, 0.4f);//Violet(House1)
- glBegin(GL_POLYGON);
- glVertex3f (22, 40, 0.0);
- glVertex3f (32, 40, 0.0);
- glVertex3f (32, 67, 0.0);
- glVertex3f (22, 67, 0.0);
- glEnd();
- glColor3f(0.3f, 0.3f, 0.5f);
- glBegin(GL_POLYGON);
- glVertex3f (32, 40, 0.0);
- glVertex3f (33, 40, 0.0);
- glVertex3f (33, 65, 0.0);
- glVertex3f (32, 67, 0.0);
- glEnd();
- glColor3f(0.0f, 0.1f, 0.2f);//Windows
- glBegin(GL_POLYGON);
- glVertex3f (23, 48, 0.0);
- glVertex3f (24.5, 48, 0.0);
- glVertex3f (24.5, 50, 0.0);
- glVertex3f (23, 50, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (26, 48, 0.0);
- glVertex3f (27.5, 48, 0.0);
- glVertex3f (27.5, 50, 0.0);
- glVertex3f (26, 50, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (29, 48, 0.0);
- glVertex3f (30.5, 48, 0.0);
- glVertex3f (30.5, 50, 0.0);
- glVertex3f (29, 50, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (23, 54, 0.0);
- glVertex3f (24.5, 54, 0.0);
- glVertex3f (24.5, 56, 0.0);
- glVertex3f (23, 56, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (26, 54, 0.0);
- glVertex3f (27.5, 54, 0.0);
- glVertex3f (27.5, 56, 0.0);
- glVertex3f (26, 56, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (29, 54, 0.0);
- glVertex3f (30.5, 54, 0.0);
- glVertex3f (30.5, 56, 0.0);
- glVertex3f (29, 56, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (29, 60, 0.0);
- glVertex3f (30.5, 60, 0.0);
- glVertex3f (30.5, 62, 0.0);
- glVertex3f (29, 62, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (26, 60, 0.0);
- glVertex3f (27.5, 60, 0.0);
- glVertex3f (27.5, 62, 0.0);
- glVertex3f (26, 62, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (23, 60, 0.0);
- glVertex3f (24.5, 60, 0.0);
- glVertex3f (24.5, 62, 0.0);
- glVertex3f (23, 62, 0.0);
- glEnd();
- glColor3f(0.2f, 0.2f, 0.1f);//Violet(House2)
- glBegin(GL_POLYGON);
- glVertex3f (52, 40, 0.0);
- glVertex3f (62, 40, 0.0);
- glVertex3f (62, 62, 0.0);
- glVertex3f (52, 62, 0.0);
- glEnd();
- glColor3f(0.3f, 0.2f, 0.1f);
- glBegin(GL_POLYGON);
- glVertex3f (62, 40, 0.0);
- glVertex3f (63, 40, 0.0);
- glVertex3f (63, 61, 0.0);
- glVertex3f (62, 62, 0.0);
- glEnd();
- glColor3f(0.0f, 0.0f, 0.0f);//Windows
- glBegin(GL_POLYGON);
- glVertex3f (53.5, 48, 0.0);
- glVertex3f (56, 48, 0.0);
- glVertex3f (56, 51, 0.0);
- glVertex3f (53.5, 51, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (58, 48, 0.0);
- glVertex3f (60.5, 48, 0.0);
- glVertex3f (60.5, 51, 0.0);
- glVertex3f (58, 51, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (53.5, 54, 0.0);
- glVertex3f (56, 54, 0.0);
- glVertex3f (56, 57, 0.0);
- glVertex3f (53.5, 57, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (58, 54, 0.0);
- glVertex3f (60.5, 54, 0.0);
- glVertex3f (60.5, 57, 0.0);
- glVertex3f (58, 57, 0.0);
- glEnd();
- glColor4f(1.0f, 0.0f, 0.0f, 0.0f);//red//for car
- glBegin(GL_POLYGON);
- glVertex3f (38, 29.5, 0.0);
- glVertex3f (50, 29.5, 0.0);
- glVertex3f (50, 33, 0.0);
- glVertex3f (38, 33, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (39.5, 33, 0.0);
- glVertex3f (50, 33, 0.0);
- glVertex3f (48, 36, 0.0);
- glVertex3f (42, 36, 0.0);
- glEnd();
- glColor3f (0.0,0.0,0.0);
- glBegin(GL_POLYGON);
- glVertex3f (39.5, 33.1, 0.0);
- glVertex3f (50, 33.1, 0.0);
- glVertex3f (50, 33, 0.0);
- glVertex3f (39.5, 33, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (45, 29.5, 0.0);
- glVertex3f (45.1, 29.5, 0.0);
- glVertex3f (45.1, 36, 0.0);
- glVertex3f (45, 36, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (48, 33, 0.0);
- glVertex3f (48.1, 33, 0.0);
- glVertex3f (48.1, 36, 0.0);
- glVertex3f (48, 36, 0.0);
- glEnd();
- glBegin(GL_POLYGON);
- glVertex3f (42, 33, 0.0);
- glVertex3f (42.1, 33, 0.0);
- glVertex3f (42.1, 36, 0.0);
- glVertex3f (42, 36, 0.0);
- glEnd();
- /* don't wait!
- * start processing buffered OpenGL routines
- */
- glFlush ();
- //For Sun
- glColor3f (.87,0.88,.1);
- drawFilledCircle(80,80,3);
- //For car1 wheel
- glColor3f (0.0,0.0,0.0);
- drawFilledCircle(41,29.5,1.1);
- glColor3f(0.1f, 0.1f, 0.0f);//Bronze
- drawFilledCircle(41,29.5,0.5);
- //For car1 wheel2
- glColor3f (0.0,0.0,0.0);
- drawFilledCircle(47,29.5,1.1);
- glColor3f(0.1f, 0.1f, 0.0f);//Bronze
- drawFilledCircle(47,29.5,0.5);
- glFlush();
- }
- void init (void)
- {
- /* select clearing (background) color */
- glClearColor (0.0, 0.0, 0.0, 0.0);
- /* initialize viewing values */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 100, 0.0, 100, -1.0, 1.0);
- }
- /*
- * Declare initial window size, position, and display mode
- * (single buffer and RGBA). Open window with "hello"
- * in its title bar. Call initialization routines.
- * Register callback function to display graphics.
- * Enter main loop and process events.
- */
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize (1300, 1000);
- glutInitWindowPosition (75,75);
- glutCreateWindow ("Fist Lab Task");
- init ();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0; /* ISO C requires main to return int. */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement