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();
}
Hello,
Did you tried to add <GL/gl.h> and <GL/glu.h> directly? Does it works?
Just a question. Where should GLfloat be defined?
Best wishes,
Michael
Yes, I've tried to add the headers directly and it didn't work. Responding to your question (I may be wrong) GLfloat is defined in gl.h .
Any other Idea of what can be?. Maybe a C::B bug?
Quote from: Cybrid on February 15, 2006, 10:22:46 AM
Any other Idea of what can be?. Maybe a C::B bug?
Post the full build log (enable it first in global compiler options and then rebuild).
#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).
Quote from: Cybrid on February 14, 2006, 10:40:51 PM
Yes, I've tried to add the headers directly and it didn't work. Responding to your question (I may be wrong) GLfloat is defined in gl.h .
Well, open that file and search for GLfloat! Maybe it's between some #define/#endif (i'm used with that on winapi applications, maybe it's your case too)
Trying to respond all of your questions:
This is the build log after enabling -Wall in Global compiler options.
Switching to target: default
Compiling: glScene.cpp
Compiling: main.cpp
In file included from main.cpp:4:
glInit.cpp: In member function `void glInit::changeSize(GLsizei, GLsizei)':
glInit.cpp:25: error: `GLfoat' undeclared (first use this function)
glInit.cpp:25: error: (Each undeclared identifier is reported only once for each function it appears in.)
glInit.cpp:25: error: expected `;' before "height"
main.cpp: In function `LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':
main.cpp:80: error: conversion from `glInit*' to non-scalar type `glInit' requested
Process terminated with status 1 (0 minutes, 1 seconds)
4 errors, 0 warnings
Checked, that "GLfloat" is defined in gl.h and it's not between #define/#endif. And the gl.h file is the one that came with C::B install.
P.S.: I can send all the proyect via e-mail if anyone wants it ;)
Hello,
May be you have to put an include path(es) in the Directories-->Compiler. Did you check that?
Best wishes,
Michael
Err... lol?
QuoteglInit.cpp:25: error: `GLfoat' undeclared (first use this function)
They're already included:
Under Directories->Compiler:
C:\Archivos de programa\CodeBlocks\include
C:\Archivos de programa\CodeBlocks\include\c++
C:\Archivos de programa\CodeBlocks\include\ddk
C:\Archivos de programa\CodeBlocks\include\GL
C:\Archivos de programa\CodeBlocks\include\sys
Under Directories->linker:
C:\Archivos de programa\CodeBlocks\lib
I do not know if it is relevant or not, but could be because of your path has white spaces, i.e., C:\Archivos de programa?
Michael
Then should I use DOS directory naming?
Quote from: thomas on February 15, 2006, 04:04:38 PMErr... lol?
QuoteglInit.cpp:25: error: `GLfoat' undeclared (first use this function)
Excuse me, do you not see it? Look closely. You can stop searching in headers...
Err... sorry, maybe I'm a complete dumbass but...no I don't see it :(
It is a typo in your source file. You cast to GLfoat. The type defined in gl.h is GLfloat.
OMG!!!!!!!!!!!!!!!! :shock: how can I be so blind :oops: :oops: :oops: :oops:
Don't worry. Someone who tells you that he never made a mistake like that is a bloody liar. 8)
This is a good example of how important accurate information ( = posting the complete compiler message) can be.
EDIT:
Of course the typo has been in the code you posted all the time, and nobody saw it. This once again proves that nobody reads posts with more than 10 lines :lol:
QuoteThis once again proves that nobody reads posts with more than 10 lines Laughing
Nice one 8)
Glfoat? LOL!!!
Didn't you mean Glfloat ?
nice thread - somehow inspiring
:lol:
Quote from: Cybrid on February 15, 2006, 04:35:05 PM
OMG!!!!!!!!!!!!!!!! :shock: how can I be so blind :oops: :oops: :oops: :oops:
Don't feel bad. It happens to me once in awhile. I had a function that wouldn't compile for months because my declaration in the header had a & and the actual function code didn't. I compared them at least 25 times until someone else pointed it out to me @ gamedev.net :lol:
Yeap, I supouse these kind of things can happen sometimes
Yup one time it took me four weeks to figure out why something wouldn't compile. I had forgot to put the semicolon at the end of my class definition. :oops: Yes four weeks. I was a newcomer to the classes thing. :P