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;
}