Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: Cybrid on February 14, 2006, 04:18:59 pm

Title: Strange Behaviour
Post by: Cybrid on February 14, 2006, 04:18:59 pm
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:

Code: cpp
#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();
}
Title: Re: Strange Behaviour
Post by: Michael on February 14, 2006, 04:26:34 pm
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
Title: Re: Strange Behaviour
Post by: 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 .
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 10:22:46 am
Any other Idea of what can be?. Maybe a C::B bug?
Title: Re: Strange Behaviour
Post by: mandrav on February 15, 2006, 10:47:18 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).
Title: Re: Strange Behaviour
Post by: thomas on February 15, 2006, 10:48:55 am
Code
#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).
Title: Re: Strange Behaviour
Post by: kkez on February 15, 2006, 01:22:33 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)
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 03:46:28 pm
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 ;)
Title: Re: Strange Behaviour
Post by: Michael on February 15, 2006, 03:55:04 pm
Hello,

May be you have to put an include path(es) in the Directories-->Compiler. Did you check that?

Best wishes,
Michael
Title: Re: Strange Behaviour
Post by: thomas on February 15, 2006, 04:04:38 pm
Err... lol?
Quote
glInit.cpp:25: error: `GLfoat' undeclared (first use this function)
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 04:15:56 pm
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
Title: Re: Strange Behaviour
Post by: Michael on February 15, 2006, 04:21:08 pm
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
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 04:22:30 pm
Then should I use DOS directory naming?
Title: Re: Strange Behaviour
Post by: thomas on February 15, 2006, 04:25:48 pm
Err... lol?
Quote
glInit.cpp:25: error: `GLfoat' undeclared (first use this function)
Excuse me, do you not see it? Look closely. You can stop searching in headers...
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 04:27:48 pm
Err... sorry, maybe I'm a complete dumbass but...no I don't see it :(
Title: Re: Strange Behaviour
Post by: thomas on February 15, 2006, 04:32:14 pm
It is a typo in your source file. You cast to GLfoat. The type defined in gl.h is GLfloat.
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 04:35:05 pm
OMG!!!!!!!!!!!!!!!!  :shock: how can I be so blind  :oops: :oops: :oops: :oops:
Title: Re: Strange Behaviour
Post by: thomas on February 15, 2006, 04:40:11 pm
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:
Title: Re: Strange Behaviour
Post by: Cybrid on February 15, 2006, 05:41:40 pm
Quote
This once again proves that nobody reads posts with more than 10 lines Laughing

Nice one 8)
Title: Re: Strange Behaviour
Post by: Szabadember on February 15, 2006, 07:39:25 pm
Glfoat? LOL!!!
Didn't you mean Glfloat ?
Title: Re: Strange Behaviour
Post by: GLfoat on February 15, 2006, 10:35:46 pm
nice thread - somehow inspiring
Title: Re: Strange Behaviour
Post by: sethjackson on February 15, 2006, 11:13:20 pm
 :lol:
Title: Re: Strange Behaviour
Post by: Vampyre_Dark on February 16, 2006, 12:11:43 am
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:
Title: Re: Strange Behaviour
Post by: Cybrid on February 16, 2006, 12:20:49 am
Yeap, I supouse these kind of things can happen sometimes
Title: Re: Strange Behaviour
Post by: sethjackson on February 16, 2006, 12:33:02 am
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