OpenGL Performance

This is a discussion on OpenGL Performance within the Game Programming forums, part of the General Programming Boards category; Hi, I wrote a OpenGL prorgam to rotate 1 line around a fixed line. Every time the program is idle, ...

  1. #1
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49

    OpenGL Performance

    Hi,



    I wrote a OpenGL prorgam to rotate 1 line around a fixed line. Every time the program is idle, it rotates 2 degrees. The rotation of the full 360 degrees takes up to 5 seconds. Can someone see how to rotate this line faster?





    #include <GL/glut.h>

    #include <math.h>

    #include <unistd.h>



    #define SCREEN_HORIZONTAL 800

    #define SCREEN_VERTICAL 600

    #define DEG_TO_RAD .017453



    double theta=0;



    void keyHandler(unsigned char key, int x, int y)

    {

    if( key == 'q' || key == 'Q')

    exit(0);

    }





    void idleHandler()

    {

    theta += 2;

    if (theta >= 360) theta -= 360;



    glutPostRedisplay();

    }





    void reshapeHandler(int w, int h)

    {

    glViewport(0,0,w,h);



    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    glFrustum(-1,1,-1,1,1,50);



    glMatrixMode(GL_MODELVIEW);

    }





    void displayHandler()

    {

    glClear(GL_COLOR_BUFFER_BIT);



    glLoadIdentity();



    glTranslated(0,-2,-5);



    glBegin(GL_LINES);

    glColor3f(0,0,1);

    glVertex3f(0,0,0);

    glColor3f(0,0,1);

    glVertex3f(0, 5, 0);

    glEnd();



    glBegin(GL_LINES);

    glColor3f(1,1,1);

    glVertex3f(0,0,0);

    glColor3f(1,0,0);

    glVertex3f(cos(DEG_TO_RAD*theta), 5, sin(DEG_TO_RAD*theta));

    glEnd();



    glutSwapBuffers();

    }



    void init()

    {

    glutFullScreen();

    glClearColor(0,0,0,0);

    }



    int main(int argc, char** argv)

    {

    // glut init

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

    glutInitWindowSize(SCREEN_HORIZONTAL, SCREEN_VERTICAL);

    glutInitWindowPosition(0,0);

    glutCreateWindow("Rotate Program");





    // handler functions

    glutDisplayFunc(displayHandler);

    glutKeyboardFunc(keyHandler);

    glutReshapeFunc(reshapeHandler);

    glutIdleFunc(idleHandler);



    init();



    // start program

    glutMainLoop();

    }

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    increase the increment of theta

    like so

    Code:
    void idleHandler() 
    { 
        theta += 4; // increment this number( now it should be twice as fast)
        if (theta >= 360) theta -= 360; 
    
        glutPostRedisplay(); 
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    Yeah but that is cheating. The image will be more choppy if you rotate 4 degrees at a time
    Ivan

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    thats not cheating, its simply rotateing faster. If you want to rotate the same on all systems you will have to do time based animation, heres an example.

    #include <time.h>

    DWORD intime,outtime,rate = 1;


    ----Main Loop

    timein = timeGetTime();
    drawScene();
    idle();
    timeout = timeGetTime();
    rate = timeout-timein;


    ----Idle

    theta+=4*rate;
    if(theta>360) theta-=360;

    Working that type of thing into glut isnt to hard.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21