strange behaviour using OpenGL types

This is a discussion on strange behaviour using OpenGL types within the C++ Programming forums, part of the General Programming Boards category; I have to ask about an error which I encounter from time to time but don't understand. In gl.h GLfloat ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    32

    strange behaviour using OpenGL types

    I have to ask about an error which I encounter from time to time but don't understand.

    In gl.h GLfloat is typedefed as a regular float.

    so why is there a difference between the classes posted below?

    When I try to compile the one with GLfloat type I get the following errors. ( I have not forgotten to link with Opengl32.lib)
    Code:
    ..\include\gl\gl.h(1152) : error C2144: syntax error : missing ';' before type 'void'
    ..\include\gl\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
    ..\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
    Thank you for your time
    Code:
    #ifndef __c_color
    #define __c_color
    
    class c_color {
    public:
    	c_color(): r(1.0f),g(1.0f),b(1.0f) {}
    	c_color(float r_in, float g_in, float b_in): r(r_in), g(g_in), b(b_in){}
    
    	float get_r(){ return r;}
    	float get_g(){ return g;}
    	float get_b(){ return b;}
    
    private:
    	float r;
    	float g;
    	float b;
    };
    
    #endif //__c_color
    and:
    Code:
    #ifndef __c_color
    #define __c_color
    
    #include <gl/gl.h>
    
    class c_color {
    public:
    	c_color(): r(1.0f),g(1.0f),b(1.0f) {}
    	c_color(GLfloat r_in, GLfloat g_in, GLfloat b_in): r(r_in), g(g_in), b(b_in){}
    
    	GLfloat get_r(){ return r;}
    	GLfloat get_g(){ return g;}
    	GLfloat get_b(){ return b;}
    
    private:
    	GLfloat r;
    	GLfloat g;
    	GLfloat b;
    };
    
    #endif //__c_color

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    You will have to show us the source file that is actually #include'ing the c_color header file. If it is being included in multiple places, then you'll have to show us all of em. Or zip up and post you entire project and someone will give you a "why" the error occurs.

    gg

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    32
    Ok, here is an example that compiles fine using the float variant but fails when I use the GLfloat variant.
    Code:
    // test.cpp
    #include "c_color.h"
    #include <iostream.h>
    
    void main()
    {
    	c_color red;
    	cout << red.get_r() << endl;	
    }
    The compiler I use is MSVC6.0
    The project is linked with opengl32.lib

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    You need <windows.h> before <gl\gl.h>.
    Why?
    If you look at line 1152 in gl.h, you will see what exactly is "before type void" - WINGDIAPI - which is not defined in gl.h
    You have include windows.h to get the definition of WINGDIAPI.

    gg

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    32
    ahh! that makes sense

    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL_ttf and OpenGL
    By sand_man in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 06:06 PM
  2. OpenGL lighting
    By BabyG in forum Game Programming
    Replies: 3
    Last Post: 08-29-2004, 10:58 AM
  3. GetClientRect strange behaviour
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2002, 03:13 PM
  4. Strange behaviour
    By PrivatePanic in forum Windows Programming
    Replies: 11
    Last Post: 07-23-2002, 01:54 AM
  5. strange behaviour by rhide
    By ustuzou in forum C++ Programming
    Replies: 0
    Last Post: 03-17-2002, 11:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21