Author Topic: Strange Behaviour  (Read 11051 times)

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Strange Behaviour
« 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: C++
  1. #include "glInit.h"
  2. #pragma once
  3.  
  4. bool glInit::setupGL()
  5. {
  6.     glShadeModel(GL_SMOOTH);
  7.     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  8.     glClearDepth(1.0f);
  9.     glEnable(GL_DEPTH_TEST);
  10.     glDepthFunc(GL_LEQUAL);
  11.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  12.     return true;
  13. }
  14.  
  15. void glInit::changeSize(GLsizei width, GLsizei height)
  16. {
  17.     GLfloat aspectRatio;
  18.  
  19.     if(height==0){height=1;}
  20.  
  21.     glViewport(0, 0, width, height);
  22.     glMatrixMode(GL_PROJECTION);
  23.     glLoadIdentity();
  24.  
  25.     aspectRatio = (GLfloat)width / (GLfoat)height;  //ERROR IS HERE
  26.  
  27.     if(width<=height)
  28.     {
  29.         glOrtho(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
  30.     }
  31.     else
  32.     {
  33.         glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);
  34.     }
  35.     glMatrixMode(GL_MODELVIEW);
  36.     glLoadIdentity();
  37. }
  38.  

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Strange Behaviour
« Reply #1 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

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #2 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 .

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #3 on: February 15, 2006, 10:22:46 am »
Any other Idea of what can be?. Maybe a C::B bug?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4306
    • Code::Blocks IDE
Re: Strange Behaviour
« Reply #4 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).
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange Behaviour
« Reply #5 on: February 15, 2006, 10:48:55 am »
Code: [Select]
#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).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Strange Behaviour
« Reply #6 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)

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #7 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 ;)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Strange Behaviour
« Reply #8 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

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange Behaviour
« Reply #9 on: February 15, 2006, 04:04:38 pm »
Err... lol?
Quote
glInit.cpp:25: error: `GLfoat' undeclared (first use this function)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #10 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
« Last Edit: February 15, 2006, 04:19:45 pm by Cybrid »

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Strange Behaviour
« Reply #11 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

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #12 on: February 15, 2006, 04:22:30 pm »
Then should I use DOS directory naming?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange Behaviour
« Reply #13 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...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #14 on: February 15, 2006, 04:27:48 pm »
Err... sorry, maybe I'm a complete dumbass but...no I don't see it :(

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange Behaviour
« Reply #15 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #16 on: February 15, 2006, 04:35:05 pm »
OMG!!!!!!!!!!!!!!!!  :shock: how can I be so blind  :oops: :oops: :oops: :oops:

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange Behaviour
« Reply #17 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:
« Last Edit: February 15, 2006, 04:42:36 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #18 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)

Offline Szabadember

  • Multiple posting newcomer
  • *
  • Posts: 75
  • That's me!
Re: Strange Behaviour
« Reply #19 on: February 15, 2006, 07:39:25 pm »
Glfoat? LOL!!!
Didn't you mean Glfloat ?

Offline GLfoat

  • Single posting newcomer
  • *
  • Posts: 5
Re: Strange Behaviour
« Reply #20 on: February 15, 2006, 10:35:46 pm »
nice thread - somehow inspiring
Les ordinateurs sont mes amis ...

sethjackson

  • Guest
Re: Strange Behaviour
« Reply #21 on: February 15, 2006, 11:13:20 pm »
 :lol:

Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: Strange Behaviour
« Reply #22 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:
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~

Offline Cybrid

  • Multiple posting newcomer
  • *
  • Posts: 19
    • Coder Times
Re: Strange Behaviour
« Reply #23 on: February 16, 2006, 12:20:49 am »
Yeap, I supouse these kind of things can happen sometimes

sethjackson

  • Guest
Re: Strange Behaviour
« Reply #24 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