Author Topic: Strange Behaviour  (Read 15331 times)

Cybrid

  • Guest
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: 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();
}

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

Cybrid

  • Guest
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 .

Cybrid

  • Guest
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: 4315
    • 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
#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)

Cybrid

  • Guest
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."

Cybrid

  • Guest
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

Cybrid

  • Guest
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."

Cybrid

  • Guest
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 :(