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 6 of 6

Thread: glutReshapeFunc

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    amelia
    Posts
    2

    glutReshapeFunc

    I have a small OpenGL program that displays a small square in a window. When I add the glutReshapeFunc to the program it crashes at the call to glutMainLoop.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: glutReshapeFunc

    You need to post the code, without seeing what you are doing we have no clue as to what is causing the crash.


    Originally posted by bagiles:
    I have a small OpenGL program that displays a small square in a window. When I add the glutReshapeFunc to the program it crashes at the call to glutMainLoop.


  3. #3
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    amelia
    Posts
    2

    Re: glutReshapeFunc

    #include <gl\glut.h>

    void RenderScene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0f,0.0f,0.0f);

    glRectf(100.0f,150.0f,150.0f,100.0f);

    glFlush();
    }

    void SetupRC(void)
    {
    glClearColor(0.0f,0.0f,0.0f,1.0f);
    }

    void ChangeSize(GLsizei w, GLsizei h)
    {
    //prevent divide by zero
    if(h==0)
    h=1;

    //set viewport to window dimensions
    glViewport(0,0,w,h);

    //Reset corrdinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    //Establish clipping volume (left,right,bottom,near,far)
    if(w<=h)
    glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0f,-1.0f);
    else
    glOrtho(0.0f,250.0f*w/h,0.0f,250.0f,1.0f,-1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    int main(void)
    {
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutCreateWindow("Simple");
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);


    SetupRC();

    glutMainLoop();

    return 0;

    }

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2000
    Location
    Phoenix, AZ, US
    Posts
    29

    Re: glutReshapeFunc

    Don't you have to size the window initially?

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    glutInitWindowSize(width,height);

    glutCreateWindow("Simple");
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);

    I think entering in the initial size might help. Otherwise you could get a divide by 0 on line :

    glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0f,-1.0f);

    because if w and h = 0 this line is run. Only the divide by 0 for h was taken care of with:

    //prevent divide by zero
    if(h==0)
    h=1;

    See if that works.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: glutReshapeFunc

    What's that SetupRC thing? Throw it away, it's certainly not needed with glut and might interfere!

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2000
    Location
    Phoenix, AZ, US
    Posts
    29

    Re: glutReshapeFunc

    zeckensack,
    SetupRC is ok. Thats how examples are done in the OpenGL Superbible. Shouldn't be a problem here.

Posting Permissions

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