Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Drawing appears but suddenly goes away

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Drawing appears but suddenly goes away

    Hi, I have a problem.
    I have a menu.
    newgame
    help

    Whenever the user clicks it the co-ordinates are checked and the specific function if called.
    Problem is the contents of the function help are only seen when I keep on holding down but not as soon as I remove it gets deleted.

    I will present the code below.

    [CODE]
    Code :
    int main(int argc, char *argv[])
    {
     glutInit (&argc, argv);
     glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGB);
     glutInitWindowPosition (1,1);
     glutInitWindowSize (900,650);
     glutCreateWindow ("Mastermind");
     glDepthFunc(GL_NEVER);
     glutReshapeFunc(changesize);
     if (checkmainmenu == true)
     {
         glutDisplayFunc(draw_background);
     }
     glutMouseFunc(mouseButton);
     glutMainLoop();
    }
    void draw_title()
    {
     
        if (checkmainmenu == true)
        {
            glutPrint(-1.5, 3,GLUT_BITMAP_TIMES_ROMAN_24, "", 1.0, 1.0, 1.0);
        }
    }
    void draw_background()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearColor(0, 0.3, 0.5, 0);
        glLoadIdentity();
        glEnable(GL_COLOR_MATERIAL); //Enable color
        glDepthFunc(GL_DOUBLE);
        gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f,  0.0f,  0.0f, 1.0f,  0.0f);
        draw_title();
        if (checkmainmenu == true)
        {
           menu.draw_mainmenu();
        }
        glutSwapBuffers();
    }
    void Cmainmenu :: draw_mainmenu()
    {
        menu.draw_newgame();
        menu.draw_stats();
        menu.draw_load();
        menu. draw_help();
        menu.draw_end();
    }
     
    void handlemouse( int x, int y, int button)
    {
        std :: cout << x << "  "<< y;
        if (checkmainmenu == true)
        {
              useroption(x,y);
        }
     
    }
    void new_game()
    {
        if(checknewgame == true)
        {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glClearColor(0, 0.3, 0.5, 0);
            glLoadIdentity();
            glEnable(GL_COLOR_MATERIAL); //Enable color
            glDepthFunc(GL_DOUBLE);
            gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f,  0.0f,  0.0f, 1.0f,  0.0f);
            glutSwapBuffers();
        }
    }
    void draw_gamebackground()
    {
        for (float y = 5.9; y > -0.8; y = y - 0.7)
         {
             glBegin(GL_LINES);
             glColor3f(1.0, 0,0);
             glVertex2f( -4,y );
             glColor3f(1, 0,0);
             glVertex2f( 2.8,y );
             glEnd();
         }
     
    }
    void helper()
    {
        if (checkhelp == true)
        {
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
         glClearColor(0, 0.3, 0.5, 0);
         gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
         glEnable(GL_COLOR_MATERIAL);
     
         glutSwapBuffers();
        }
    }
    void useroption(int x, int y)
    {
         if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 207 &amp;&amp; y > 167))
         {
             checkmainmenu = false;
             checknewgame = true;
             new_game();
     
         }
         else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 284 &amp;&amp; y > 247))
         {
              //statsdisplayer();
              //newgame = false;
              checkmainmenu = false;
              //stats= true;
              //help= false;
         }
         else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 361 &amp;&amp; y > 324))
         {
              //statsdisplayer();
              //newgame = false;
              checkmainmenu = false;
              //stats= true;
              //help= false;
         }
         else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 442 &amp;&amp; y > 401))
         {
     
              checkmainmenu = false;
              checkhelp = true;
              checknewgame = false;
              helper();
         }
         else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 520 &amp;&amp; y > 490))
         {
             ending();
         }
    }
     
    void mouseButton(int button, int state, int x, int y)
    {
     
       if  ((button == GLUT_LEFT_BUTTON) &amp;&amp; (state == GLUT_DOWN))
         {
                     handlemouse(x,y, button);
         }
    }

    Anything with the check in front are the boolean variables that keep track of where the program is.

    Thank you very much.

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    7

    Re: Drawing appears but suddenly goes away

    In your nwe_game(0 function you have

    glDepthFunc(GL_DOUBLE);


    I'm not sure that is valid. More common is to use GL_LESS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •