Well , I have this class created to do some basic OpenGL setup tasks, <GL/gl.h> and <GL/glu.h> are included in "glInit.h". Strangely I receive error: 'GLfloat' undeclared (first use this function) from compiler when trying to build.
I've already added -lopengl32 -lglu32 -gdi32 -user32 -kernel32 to "other option" in the linker tab of my project.
This is the code:
#include "glInit.h"
#pragma once
bool glInit::setupGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return true;
}
void glInit::changeSize(GLsizei width, GLsizei height)
{
GLfloat aspectRatio;
if(height==0){height=1;}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio = (GLfloat)width / (GLfoat)height; //ERROR IS HERE
if(width<=height)
{
glOrtho(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
}
else
{
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
#include <gl/gl.h>
int main()
{
GLfloat f = 0.0;
return 0;
};
compiles without errors using revision 2002. No Code::Blocks bug.
BTW, having that #pragma directive in a source file is not good, although that is very likely not the cause of the problem. If you compile with -Wall, the compiler will probably complain about that.
There are many possible causes why you see that error. One such cause may be that you have a bad GL/gl.h file somewhere in your include path by accident (which is then included).