热气球不可见

时间:2018-12-17 16:16:00

标签: c++ visual-studio opengl glut

#include <stdio.h>  // this library is for standard input and output
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "glut.h"// this library is for glut the OpenGL Utility Toolkit

float squareX = 0.0f;
float squareY = -0.3f;
float squareZ = 0.0f;
static int flag = 1;

#define RAINSIZE 200
int winWidth = 800, winHeight = 600;
int counter = 0;
time_t t;
float rotationAngle = 0;

struct drop {
    float x = 400;
    float y = 400;
    float inc = 0.01;
    float radius = 5;
    float scale = 1.0;
    float rotationAngle = 0;
    float rotationInc = 1;
};

drop rain[RAINSIZE];

void initRain() {
    srand((unsigned)time(&t));
    for (int i = 0; i < RAINSIZE; i++) {
        rain[i].x = rand() % winWidth;
        rain[i].y = rand() % winHeight;
        rain[i].inc = 1.5 + (float)(rand() % 100) / 1000.0;
        rain[i].radius = (float)(rand() % 8);
        rain[i].scale = (float)(rand() % 20000) / 1000.0;
        rain[i].rotationAngle = (float)(rand() % 3000) / 1000.0;
        rain[i].rotationInc = (float)(rand() % 100) / 1000.0;
        if ((rand() % 100) > 50) {
            rain[i].rotationInc = -rain[i].rotationInc;
        }
    }
}

void drawParticleShape(int i) {
    glBegin(GL_POINTS);
    glVertex2d(rain[i].x, rain[i].y);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(rain[i].x, rain[i].y);
    glVertex2d(rain[i].x, rain[i].y + rain[i].radius * 2);
    glEnd();
}

void drawDrop(int i) {
    // color of the rain
    glColor3f(0.1, 0.6, 0.8);
    glLineWidth(2);
    drawParticleShape(i);
    rain[i].y -= rain[i].inc;
    if (rain[i].y < 0) {
        rain[i].y = winHeight;
    }
}

void drawRain() {
    for (int i = 0; i < RAINSIZE; i++) {
        drawDrop(i);
    }
}

// this is the initialisation function, called once only
void init() {
    glClearColor(0.0, 0.0, 0.0, 0.0); // set what colour you want the background to be
    glMatrixMode(GL_PROJECTION); // set the matrix mode, we will look at this later
    // set the projection window size in x an y.
    gluOrtho2D(0.0, winWidth, 0.0, winHeight);
}

float elapsedTime = 0, base_time = 0, fps = 0, frames;

void calcFPS() {
    elapsedTime = glutGet(GLUT_ELAPSED_TIME);
    if ((elapsedTime - base_time) > 1000.0) {
        fps = frames * 1000.0 / (elapsedTime - base_time);
        base_time = elapsedTime;
        frames = 0;
    }
    frames++;
}

// the background
void drawBackground() {
    // draw the green ground
    glBegin(GL_POLYGON);
    glColor3f(0.3, 0.7, 0.0);
    glVertex2f(800, 100);
    glVertex2f(800, 0);
    glVertex2f(0, 0);
    glVertex2f(0, 100);
    glVertex2f(800, 100);
    glEnd();
    // draw the blue sky
    glBegin(GL_POLYGON);
    glColor3f(0.7, 0.7, 0.9);
    glVertex2f(800, 100);
    glVertex2f(800, 800);
    glVertex2f(0, 800);
    glVertex2f(0, 100);
    glVertex2f(800, 100);
    glEnd();
    glFlush();
}

// the hot air balloon
void drawAirBalloon(void) {
    glTranslatef(squareX, squareY, squareZ);
    // draw the balloon
    float theta;
    int cutsegment = 45;
    int start = -90 + cutsegment / 2;
    int end = 270 - cutsegment / 2;
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glColor3f(1.0, 0.0, 0.0);
    for (int i = -45; i <= 225; i++) {
        theta = i * 3.142 / 180;
        glVertex2f(355 + 70 * cos(theta), 225 + 90 * sin(theta));
    }
    glEnd();
    // draw first rope on the left
    glBegin(GL_LINES);
    glColor3f(0.0, 0.0, 0.0);
    glVertex2f(320, 95);
    glVertex2f(295, 177);
    glEnd();
    // draw first rope on the right
    glBegin(GL_LINES);
    glColor3f(0.0, 0.0, 0.0);
    glVertex2f(415, 180);
    glVertex2f(390, 95);
    glEnd();
    // draw propane burner
    glBegin(GL_POLYGON);
    glColor3f(0.1, 0.1, 0.1);
    glVertex2f(335, 140);
    glVertex2f(335, 120);
    glVertex2f(375, 120);
    glVertex2f(375, 140);
    glVertex2f(335, 140);
    glEnd();
    // first vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(330, 95);
    glVertex2f(330, 40);
    glEnd();
    // second vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(340, 95);
    glVertex2f(340, 40);
    glEnd();
    // third vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(350, 95);
    glVertex2f(350, 40);
    glEnd();
    // fourth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(360, 95);
    glVertex2f(360, 40);
    glEnd();
    // fifth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(370, 95);
    glVertex2f(370, 40);
    glEnd();
    // sixth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(380, 95);
    glVertex2f(380, 40);
    glEnd();
    // first horizontal line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(390, 80);
    glVertex2f(320, 80);
    glEnd();
    // second horizontal line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(390, 55);
    glVertex2f(320, 55);
    glEnd();
    // draw basket
    glBegin(GL_POLYGON);
    glColor3f(0.6, 0.45, 0.1);
    glVertex2f(320, 95);
    glVertex2f(320, 40);
    glVertex2f(390, 40);
    glVertex2f(390, 95);
    glVertex2f(320, 95);
    glEnd();
}

// move the hot air balloon up
void update(int value) {
    if (flag) {
        squareY += 1.0f;
        if (squareY > 350.0) {
            flag = 0;
        }
    }
    glutPostRedisplay();
    glutTimerFunc(25, update, 0);
}

// This is the display function it is called when ever you want to draw something
// all drawing should be called form here
void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    // draw hot air balloon
    glPushMatrix();
    drawAirBalloon();
    glPopMatrix();
    // draw background  
    drawBackground();
    // draw rain
    drawRain();
    calcFPS();
    glFlush();
    counter++;
    //glutPostRedisplay();
    glutSwapBuffers();
}

// This is the idle function it is called whenever the program is idle
// This has the effect of repeatedly calling the display function
void idle() {
    display();
}

// As with many programming languages the main() function
// is the entry point for execution of the program
int main(int argc, char** argv) {
    srand(1);
    initRain();
    glutInit(&argc, argv);  //perform the GLUT initialization
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); // more initialisation
    glutInitWindowSize(winWidth, winHeight); // set window position
    glutInitWindowPosition(0, 0); // set window size
    glutCreateWindow("Hot Air Balloon"); // create a display with a given caption for the title bar
    glEnable(GL_BLEND); //Enable blending.
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set blending function.
    init(); // call init function defined above
    glutIdleFunc(idle); //  define what function to call when the program is idle
    glutDisplayFunc(display); // define what function to call to draw
    glutTimerFunc(25, update, 0);
    // the last function in the program puts the program into infinite loop
    glutMainLoop();
    // this line exits the program
    return 0;
}

我已将所有工作都放在一个cpp文件中。我正在尝试创建一个热气球,使其从地面漂浮到天空,这是恶劣的天气,因为它倾盆大雨。问题是我无法显示我的热气球。

这是一项连续的工作,我之前已经在此发布过。如果您不理解我的代码,则可以查看我以前的工作:

OpenGL - Creating rain drops

OpenGL - Stop the background from moving

2 个答案:

答案 0 :(得分:2)

现在您要绘制的是气球,然后是背景。

先绘制背景,然后再绘制气球:

// draw background  
drawBackground();

// draw hot air balloon
glPushMatrix();
drawAirBalloon();
glPopMatrix();

// draw rain
drawRain();

一起:

#include <ctime>
#include <cmath>
#include <GL/glut.h>

float squareX = 0.0f;
float squareY = -0.3f;
float squareZ = 0.0f;
static int flag = 1;

#define RAINSIZE 200
int winWidth = 800, winHeight = 600;
int counter = 0;
time_t t;
float rotationAngle = 0;

struct drop
{
    float x = 400;
    float y = 400;
    float inc = 0.01;
    float radius = 5;
    float scale = 1.0;
    float rotationAngle = 0;
    float rotationInc = 1;
};

drop rain[ RAINSIZE ];

void initRain()
{
    srand( (unsigned)time( &t ) );
    for( int i = 0; i < RAINSIZE; i++ )
    {
        rain[ i ].x = rand() % winWidth;
        rain[ i ].y = rand() % winHeight;
        rain[ i ].inc = 1.5 + (float)( rand() % 100 ) / 1000.0;
        rain[ i ].radius = (float)( rand() % 8 );
        rain[ i ].scale = (float)( rand() % 20000 ) / 1000.0;
        rain[ i ].rotationAngle = (float)( rand() % 3000 ) / 1000.0;
        rain[ i ].rotationInc = (float)( rand() % 100 ) / 1000.0;
        if( ( rand() % 100 ) > 50 )
        {
            rain[ i ].rotationInc = -rain[ i ].rotationInc;
        }
    }
}

void drawParticleShape( int i )
{
    glBegin( GL_POINTS );
    glVertex2d( rain[ i ].x, rain[ i ].y );
    glEnd();
    glBegin( GL_LINES );
    glVertex2d( rain[ i ].x, rain[ i ].y );
    glVertex2d( rain[ i ].x, rain[ i ].y + rain[ i ].radius * 2 );
    glEnd();
}

void drawDrop( int i )
{
    // color of the rain
    glColor3f( 0.1, 0.6, 0.8 );
    glLineWidth( 2 );
    drawParticleShape( i );
    rain[ i ].y -= rain[ i ].inc;
    if( rain[ i ].y < 0 )
    {
        rain[ i ].y = winHeight;
    }
}

void drawRain()
{
    for( int i = 0; i < RAINSIZE; i++ )
    {
        drawDrop( i );
    }
}

float elapsedTime = 0, base_time = 0, fps = 0, frames;

void calcFPS()
{
    elapsedTime = glutGet( GLUT_ELAPSED_TIME );
    if( ( elapsedTime - base_time ) > 1000.0 )
    {
        fps = frames * 1000.0 / ( elapsedTime - base_time );
        base_time = elapsedTime;
        frames = 0;
    }
    frames++;
}

// the background
void drawBackground()
{
    // draw the green ground
    glBegin( GL_POLYGON );
    glColor3f( 0.3, 0.7, 0.0 );
    glVertex2f( 800, 100 );
    glVertex2f( 800, 0 );
    glVertex2f( 0, 0 );
    glVertex2f( 0, 100 );
    glVertex2f( 800, 100 );
    glEnd();
    // draw the blue sky
    glBegin( GL_POLYGON );
    glColor3f( 0.7, 0.7, 0.9 );
    glVertex2f( 800, 100 );
    glVertex2f( 800, 800 );
    glVertex2f( 0, 800 );
    glVertex2f( 0, 100 );
    glVertex2f( 800, 100 );
    glEnd();
    glFlush();
}

// the hot air balloon
void drawAirBalloon( void )
{
    glTranslatef( squareX, squareY, squareZ );
    // draw the balloon
    float theta;
    int cutsegment = 45;
    int start = -90 + cutsegment / 2;
    int end = 270 - cutsegment / 2;
    //glClear( GL_COLOR_BUFFER_BIT );
    glBegin( GL_POLYGON );
    glColor3f( 1.0, 0.0, 0.0 );
    for( int i = -45; i <= 225; i++ )
    {
        theta = i * 3.142 / 180;
        glVertex2f( 355 + 70 * cos( theta ), 225 + 90 * sin( theta ) );
    }
    glEnd();
    // draw first rope on the left
    glBegin( GL_LINES );
    glColor3f( 0.0, 0.0, 0.0 );
    glVertex2f( 320, 95 );
    glVertex2f( 295, 177 );
    glEnd();
    // draw first rope on the right
    glBegin( GL_LINES );
    glColor3f( 0.0, 0.0, 0.0 );
    glVertex2f( 415, 180 );
    glVertex2f( 390, 95 );
    glEnd();
    // draw propane burner
    glBegin( GL_POLYGON );
    glColor3f( 0.1, 0.1, 0.1 );
    glVertex2f( 335, 140 );
    glVertex2f( 335, 120 );
    glVertex2f( 375, 120 );
    glVertex2f( 375, 140 );
    glVertex2f( 335, 140 );
    glEnd();
    // first vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 330, 95 );
    glVertex2f( 330, 40 );
    glEnd();
    // second vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 340, 95 );
    glVertex2f( 340, 40 );
    glEnd();
    // third vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 350, 95 );
    glVertex2f( 350, 40 );
    glEnd();
    // fourth vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 360, 95 );
    glVertex2f( 360, 40 );
    glEnd();
    // fifth vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 370, 95 );
    glVertex2f( 370, 40 );
    glEnd();
    // sixth vertical line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 380, 95 );
    glVertex2f( 380, 40 );
    glEnd();
    // first horizontal line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 390, 80 );
    glVertex2f( 320, 80 );
    glEnd();
    // second horizontal line on basket
    glBegin( GL_LINES );
    glColor3f( 0.6, 0.25, 0.1 );
    glVertex2f( 390, 55 );
    glVertex2f( 320, 55 );
    glEnd();
    // draw basket
    glBegin( GL_POLYGON );
    glColor3f( 0.6, 0.45, 0.1 );
    glVertex2f( 320, 95 );
    glVertex2f( 320, 40 );
    glVertex2f( 390, 40 );
    glVertex2f( 390, 95 );
    glVertex2f( 320, 95 );
    glEnd();
}

// move the hot air balloon up
void update( int value )
{
    if( flag )
    {
        squareY += 1.0f;
        if( squareY > 350.0 )
        {
            flag = 0;
        }
    }
    glutPostRedisplay();
    glutTimerFunc( 25, update, 0 );
}

// This is the display function it is called when ever you want to draw something
// all drawing should be called form here
void display()
{
    glClearColor( 0.0, 0.0, 0.0, 0.0 ); // set what colour you want the background to be
    glClear( GL_COLOR_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION ); // set the matrix mode, we will look at this later
    glLoadIdentity();
    gluOrtho2D( 0.0, winWidth, 0.0, winHeight );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // draw background  
    drawBackground();

    // draw hot air balloon
    glPushMatrix();
    drawAirBalloon();
    glPopMatrix();

    // draw rain
    drawRain();

    calcFPS();

    counter++;
    glutSwapBuffers();
}

int main( int argc, char** argv )
{
    srand( 1 );
    initRain();

    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );
    glutInitWindowSize( winWidth, winHeight );
    glutInitWindowPosition( 0, 0 );
    glutCreateWindow( "Hot Air Balloon" );

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glutDisplayFunc( display );
    glutTimerFunc( 25, update, 0 );
    glutMainLoop();
    return 0;
}

答案 1 :(得分:1)

我将您禁用深度测试的先前问题进行比较。我建议再次启用深度测试,并绘制具有不同深度(z坐标)的对象。

如果您不想启用深度测试,则必须先绘制背景,然后绘制气球,最后绘制雨:

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    // draw background  
    drawBackground();
    // draw hot air balloon
    glPushMatrix();
    drawAirBalloon();
    glPopMatrix();
    // draw rain
    drawRain();
    calcFPS();
    counter++;
    glFlush();
    glutSwapBuffers();
    glutPostRedisplay();
} 

您还必须从glClear中删除drawAirBalloon

void drawAirBalloon(void) {

    // .....

    // glClear(GL_COLOR_BUFFER_BIT);  <---- delete this

还有glFlush from绘制背景

 void drawBackground() {

     // .....

     // glFlush();  <---- delete this, too
 }

请注意,渲染中间的任意glClearglFlush会导致部分渲染和闪烁(特别是在使用单个缓冲时)。

最终代码:

#include <stdio.h>  // this library is for standard input and output
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "glut.h"// this library is for glut the OpenGL Utility Toolkit

float squareX = 0.0f;
float squareY = -0.3f;
float squareZ = 0.0f;
static int flag = 1;

#define RAINSIZE 200
int winWidth = 800, winHeight = 600;
int counter = 0;
time_t t;
float rotationAngle = 0;

struct drop {
    float x = 400;
    float y = 400;
    float inc = 0.01;
    float radius = 5;
    float scale = 1.0;
    float rotationAngle = 0;
    float rotationInc = 1;
};

drop rain[RAINSIZE];

void initRain() {
    srand((unsigned)time(&t));
    for (int i = 0; i < RAINSIZE; i++) {
        rain[i].x = rand() % winWidth;
        rain[i].y = rand() % winHeight;
        rain[i].inc = 1.5 + (float)(rand() % 100) / 1000.0;
        rain[i].radius = (float)(rand() % 8);
        rain[i].scale = (float)(rand() % 20000) / 1000.0;
        rain[i].rotationAngle = (float)(rand() % 3000) / 1000.0;
        rain[i].rotationInc = (float)(rand() % 100) / 1000.0;
        if ((rand() % 100) > 50) {
            rain[i].rotationInc = -rain[i].rotationInc;
        }
    }
}

void drawParticleShape(int i) {
    glBegin(GL_POINTS);
    glVertex2d(rain[i].x, rain[i].y);
    glEnd();
    glBegin(GL_LINES);
    glVertex2d(rain[i].x, rain[i].y);
    glVertex2d(rain[i].x, rain[i].y + rain[i].radius * 2);
    glEnd();
}

void drawDrop(int i) {
    // color of the rain
    glColor3f(0.1, 0.6, 0.8);
    glLineWidth(2);
    drawParticleShape(i);
    rain[i].y -= rain[i].inc;
    if (rain[i].y < 0) {
        rain[i].y = winHeight;
    }
}

void drawRain() {
    for (int i = 0; i < RAINSIZE; i++) {
        drawDrop(i);
    }
}

// this is the initialisation function, called once only
void init() {
    glClearColor(0.0, 0.0, 0.0, 0.0); // set what colour you want the background to be
    glMatrixMode(GL_PROJECTION); // set the matrix mode, we will look at this later
    // set the projection window size in x an y.
    gluOrtho2D(0.0, winWidth, 0.0, winHeight);
}

float elapsedTime = 0, base_time = 0, fps = 0, frames;

void calcFPS() {
    elapsedTime = glutGet(GLUT_ELAPSED_TIME);
    if ((elapsedTime - base_time) > 1000.0) {
        fps = frames * 1000.0 / (elapsedTime - base_time);
        base_time = elapsedTime;
        frames = 0;
    }
    frames++;
}

// the background
void drawBackground() {
    // draw the green ground
    glBegin(GL_POLYGON);
    glColor3f(0.3, 0.7, 0.0);
    glVertex2f(800, 100);
    glVertex2f(800, 0);
    glVertex2f(0, 0);
    glVertex2f(0, 100);
    glVertex2f(800, 100);
    glEnd();
    // draw the blue sky
    glBegin(GL_POLYGON);
    glColor3f(0.7, 0.7, 0.9);
    glVertex2f(800, 100);
    glVertex2f(800, 800);
    glVertex2f(0, 800);
    glVertex2f(0, 100);
    glVertex2f(800, 100);
    glEnd();
    //glFlush();
}

// the hot air balloon
void drawAirBalloon(void) {
    glTranslatef(squareX, squareY, squareZ);
    // draw the balloon
    float theta;
    int cutsegment = 45;
    int start = -90 + cutsegment / 2;
    int end = 270 - cutsegment / 2;
    //glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glColor3f(1.0, 0.0, 0.0);
    for (int i = -45; i <= 225; i++) {
        theta = i * 3.142 / 180;
        glVertex2f(355 + 70 * cos(theta), 225 + 90 * sin(theta));
    }
    glEnd();
    // draw first rope on the left
    glBegin(GL_LINES);
    glColor3f(0.0, 0.0, 0.0);
    glVertex2f(320, 95);
    glVertex2f(295, 177);
    glEnd();
    // draw first rope on the right
    glBegin(GL_LINES);
    glColor3f(0.0, 0.0, 0.0);
    glVertex2f(415, 180);
    glVertex2f(390, 95);
    glEnd();
    // draw propane burner
    glBegin(GL_POLYGON);
    glColor3f(0.1, 0.1, 0.1);
    glVertex2f(335, 140);
    glVertex2f(335, 120);
    glVertex2f(375, 120);
    glVertex2f(375, 140);
    glVertex2f(335, 140);
    glEnd();
    // first vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(330, 95);
    glVertex2f(330, 40);
    glEnd();
    // second vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(340, 95);
    glVertex2f(340, 40);
    glEnd();
    // third vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(350, 95);
    glVertex2f(350, 40);
    glEnd();
    // fourth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(360, 95);
    glVertex2f(360, 40);
    glEnd();
    // fifth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(370, 95);
    glVertex2f(370, 40);
    glEnd();
    // sixth vertical line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(380, 95);
    glVertex2f(380, 40);
    glEnd();
    // first horizontal line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(390, 80);
    glVertex2f(320, 80);
    glEnd();
    // second horizontal line on basket
    glBegin(GL_LINES);
    glColor3f(0.6, 0.25, 0.1);
    glVertex2f(390, 55);
    glVertex2f(320, 55);
    glEnd();
    // draw basket
    glBegin(GL_POLYGON);
    glColor3f(0.6, 0.45, 0.1);
    glVertex2f(320, 95);
    glVertex2f(320, 40);
    glVertex2f(390, 40);
    glVertex2f(390, 95);
    glVertex2f(320, 95);
    glEnd();
}

// move the hot air balloon up
void update(int value) {
    if (flag) {
        squareY += 1.0f;
        if (squareY > 350.0) {
            flag = 0;
        }
    }
    glutPostRedisplay();
    glutTimerFunc(25, update, 0);
}

// This is the display function it is called when ever you want to draw something
// all drawing should be called form here
void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    // draw background  
    drawBackground();
    // draw hot air balloon
    glPushMatrix();
    drawAirBalloon();
    glPopMatrix();
    // draw rain
    drawRain();
    calcFPS();
    counter++;
    glFlush();
    glutSwapBuffers();
    glutPostRedisplay();
}

// This is the idle function it is called whenever the program is idle
// This has the effect of repeatedly calling the display function
void idle() {
    display();
}

// As with many programming languages the main() function
// is the entry point for execution of the program
int main(int argc, char** argv) {
    srand(1);
    initRain();
    glutInit(&argc, argv);  //perform the GLUT initialization
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); // more initialisation
    glutInitWindowSize(winWidth, winHeight); // set window position
    glutInitWindowPosition(0, 0); // set window size
    glutCreateWindow("Hot Air Balloon"); // create a display with a given caption for the title bar
    glEnable(GL_BLEND); //Enable blending.
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set blending function.
    init(); // call init function defined above
    glutIdleFunc(idle); //  define what function to call when the program is idle
    glutDisplayFunc(display); // define what function to call to draw
    glutTimerFunc(25, update, 0);
    // the last function in the program puts the program into infinite loop
    glutMainLoop();
    // this line exits the program
    return 0;
}