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: low framerate problem

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52

    low framerate problem

    Hi, I have a problem with my game.
    After playing for several minutes framerate goes to low.

    I've tried playing in a simple scene: 3d model draw with VBO, no collisions, simple level e no other objects and I have the same problem.
    Some suggests?

    Maybe something wrong with my "main" file?

    main.cpp:

    void display();
    void animate();
    void reshape(int width, int height);
    void mouseFunc(int,int,int,int);
    void keyboardFunc(unsignedchar, int, int);
    void specialKeyboardFunc(int, int, int);
    void changeScene();




    GameScene *game;
    StartMenu *start;
    SelectionScene *selection;


    extern State CURRENTSTATE;


    int main (int argc, char ** argv)
    {
    myWindow window1;
    window1.init(argc, argv);

    StartMenu s;
    SelectionScene sl;
    GameScene g;
    Debug d;

    start = &s;
    selection = &sl;
    game = &g;





    glutReshapeFunc(reshape);
    window1.render(&display);
    window1.mouse(&mouseFunc);
    window1.keyboard(&keyboardFunc);
    window1.specialKeyboard(&specialKeyboardFunc);
    game->setTime(glutGet(GLUT_ELAPSED_TIME));
    glutIdleFunc(&animate);

    glutMainLoop();

    return 0;
    }



    void display()
    {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glLoadIdentity();




    switch (CURRENTSTATE) {
    case STARTMENU:
    if(start->initialize()) {
    start->render();
    }
    break;
    case SELECTION:
    if(selection->initialize()) {
    selection->render();
    }
    break;
    case GAME:
    if(game->initialize()) {
    game->render();
    }
    break;
    default:
    exit(1);
    }



    glutSwapBuffers();

    }


    void reshape(int width, int height)
    {
    switch (CURRENTSTATE) {
    case STARTMENU:
    start->reshape(width, height);
    break;

    case SELECTION:
    {
    SelectionScene selection;
    selection.reshape(width, height);
    break;
    }
    case GAME:
    game->reshape(width, height);
    break;
    case DEB:
    // debug->reshape(width, height);
    break;
    default:
    exit(1);
    }

    }


    void animate()
    {
    switch (CURRENTSTATE) {
    case SELECTION:
    {
    selection->animate();
    break;
    }
    case GAME:
    game->animate();
    break;
    case DEB:
    // debug->animate();
    break;
    default:
    break;
    }



    }


    void mouseFunc(int btn, int state, int x, int y)
    {
    switch (CURRENTSTATE) {
    case STARTMENU:
    start->mouse(btn, state, x, y);
    break;

    case SELECTION:
    selection->mouse(btn, state, x, y);
    break;

    case GAME:
    game->mouse(btn, state, x, y);
    break;

    default:
    break;
    }



    }


    void keyboardFunc(unsigned char key, int x, int y)
    {
    switch (CURRENTSTATE) {

    case GAME:
    game->keyboard(key, x, y);
    break;

    default:
    break;
    }


    }

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,256
    Usually, people who have this problem, I point them to the Common Mistakes page.
    http://www.opengl.org/wiki/Common_Mi...ender_function

    PS: there is no point in showing us you are calling selection->animate() start->render() and such functions.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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