I recently have been working on a GLUT project in Code:Blocks. Everything in the code compiles correctly, yet every build seems to return the same result. I narrowed it down to an OpenGL, non-GLUT function : glFrustum. I change the parameters yet the runs are all the same. It could be a bug in OpenGL, my hardware or drivers, or Code:Blocks. My first thought was that Code:Blocks or OpenGL uses a cache which I haven't purged.

I've included functions which prove ar is correct, the program acts as if ar is where the twos are in the glFrustum function.

#define _STDCALL_SUPPORTED
#define _M_IX86
#include <iostream>
#include <windows.h>
#include <sstream>
#include <GL/gl.h>
#include <GL/glut.h>

using namespace std;

float ar;

void render(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1, 0, 0);

    double a = (glutGet(GLUT_ELAPSED_TIME) / 1000.0) * 90.0;

    glPushMatrix();
        glTranslated(0.0, 0.0, 0.0);
        glRotated(60, 1, 0, 0);
        glRotated(a, 0, 0, 1);
        glutSolidSphere(1, 16, 16);
    glPopMatrix();

    glutSwapBuffers();
}

void resize(int w, int h)
{
    if(h == 0)
    {
        h = 1;
    }

    if(w==700)
    {
        cout << "Something must work...\n";
    }

    ar = (float)w / (float)h;
    stringstream arr;
    arr << ar;

    cout << "Heres ar " << arr.str() << endl;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // Usually ar would be where the twos are, just a test...
    glFrustum(2.0, 2.0, -1.0, 1.0, -5.0, 10.0);

    glMatrixMode(GL_MODELVIEW);
}

void key (unsigned char key, int x, int y)
{
    switch(key)
    {
        case 27:
        case 'q':
            glutLeaveGameMode();
            exit(0);
        break;
    }

    glutPostRedisplay();
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(800, 600);
    glutInitWindowPosition(10, 10);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

    if(MessageBox(NULL, "Fullscreen mode?", "OpenGL Proto", MB_YESNO) == IDYES)
    {
        stringstream gms;
        gms << GetSystemMetrics(SM_CXSCREEN) << "x" << GetSystemMetrics(SM_CYSCREEN) << ":32@75";
        glutGameModeString(gms.str().c_str());
        glutEnterGameMode();
    }
    else
    {
        glutCreateWindow("OpenGL Proto");
        stringstream metric, get;
        metric << "Screen resolution X : " << GetSystemMetrics(SM_CXSCREEN);
        get << "Window X : " << glutGet(GLUT_WINDOW_X);
        cout << metric.str() << endl;
        cout << get.str() << endl;
    }

    glutDisplayFunc(render);
    glutReshapeFunc(resize);
    glutKeyboardFunc(key);
    glutIdleFunc(render);

    glutMainLoop();

    return EXIT_SUCCESS;
}

The function is not bugged you just didn't read the documentation on this function.

The way you have it set up you have two major problems.

#1 left and right values cannot be equal
#2 near and far must be both positive

If you were to write out the resulting projection matrix using the numbers you passed into the function, then you would get a divide by zero which will cause an error in the function and result in the default values to be used.

Example glFrustum(-ar, ar, -1.0, 1.0, 0.1, 10.0); To see general documentation and how the projection matrix is constructed using the input values you can look here.

I used your example as input without avail, allow me to explain. The right clipping plane is clipping upon resize regardless of recompile.

I have read my documentation thank you very much. :)

The assistance, as always, is much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.