Problems with Object-Oriented OpenGL programming

I was using classes in my OpenGL program to organize my code better, but ever time I try to compile the code I keep getting the following three errors for ever C++ source file that contains a class in it.

c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ‘;’ before type ‘void’
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ‘WINGDIAPI’ : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found

I am using VC++ 6.0 (Introduction Version). In my header file I include gl.h,glu.h, glaux.h, and windows.h. When I comment out the include statements for gl.h, glu.h, and glaux.h, the errors go away. I have my WinMain funtion in the program, but that doesn’t seem to take care of the errors. The strangest thing is that whenever i double click on the erros to figure out where they are it keeps taking me to the gl.h file. There is no way that the gl.h file is wrong, but at the same time I can’t figure out what I did wrong.I would REALLY appreciate some help on this topic. Thanks!

This little code gives me the same error:

//HClass.h

#ifndef CLASSLOADED
#define CLASSLOADED

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <windows.h>

class CClass{
public:
CClass(){};
~CClass(){};
Draw();
}

#endif


// CClass.h

#include “HClass.h”

CClass::CClass(){}

CClass: raw(){
glBegin(GL_LINE_LOOP);
glVertex3f(0.0f,1.0f,2.0f);
glVertex3f(0.0f,2.0f,3.0f);
glVertex3f(1.0f,3.0f,2.0f);
glEnd();
}

CClass::~CClass(){}

//The windows code follows here. To make sure that I wasn’t doing anything wrong, I copied the code from the book OpenGL Game Programming. The windows code works perfect just by itself.

P.S. This isn’t the program I was working on. This is the smallest code that I could write that gave me the errors.

I didn’t mean for that smiley face to appear…it’s a “:” followed by a “D”.

include the windows.h BEFORE GL/gl.h

LOL…Thanks! It worked!! I really appreciate it… I can’t believe it was something this little…I’m a highschool student who’s never had any classes or anthign like that in C/C++…just Java. Since order doesn’t matter in Java, I didnt’ think it would matter in C/C++. Thanks again!

And y use classes at all? Structs are simpler and all their members are public by default. Example:

struct vector
{
float x
float y
float z
};

True… but I need a particle engine in my program… and I need to use classes for that. The example above just demonstrates the error…it isn’t what I’m working on.

Classes are v.good for thinks like particle engines… but in the majority of cases i wouldnt use them, too cumbersome imo, just use structs instead… except in the case of things like particle engines

Classes are much better than structs.
The code gets cleaner and if you want to produce object-oriented code you really should use them.

ehm, classes structs, there is no difference (only the privacy state)… so don’t compare them !

struct as class:
class{
public:

};

and class as struct:
struct{
private:

};

This sounds like an OO argument to…

of topic, but there actualy IS a difference : you can’t pre-initialize class but you can with structs :

struct { int a; } tab[3] = {{1},{2},{3}}; // OK
class {public: int a; } tab[3] = {{1},{2},{3}}; // won’t compile

So this is NOT equivalent.

[This message has been edited by rixed (edited 12-17-2001).]

Originally posted by rixed:
[b]of topic, but there actualy IS a difference : you can’t pre-initialize class but you can with structs :

struct { int a; } tab[3] = {{1},{2},{3}}; // OK
class {public: int a; } tab[3] = {{1},{2},{3}}; // won’t compile

So this is NOT equivalent.

[This message has been edited by rixed (edited 12-17-2001).][/b]

You are really using that syntax? Ever heard of constructors and initializing lists?
Works for both classes and structs.

class CClass{
public:
CClass(){};
~CClass(){};
Draw();
}

Class Defintion Should end in ;

class CClass{
public:
CClass(){};
~CClass(){};
Draw();
};

Classic C++ gaffe

another often overlooked + of classes is the ability to specify the default constructer, which in my opionion cleans up ur code very nicely

hmm…With all this talk of classes vs. structs, i’m getting a little confused here (I’m self-taught…so i’m not crystal clear on everything)…but my basic understanding was that structs were used to create custom type definitions for variables …and classes were meant for creating objects or for creating a foundation…I mean I can see how someone would use classes where structs would be better but aren’t their general purposes different? Structs : Variable type defenitions…Classes : A foundation of code to build upon.

structs are useful for basic things, but if you want to model real-world physics with ease then its time for classes.

Or you could have stuck with Java and save a whole load of pointless syntactical headaches and just get the job done…

Cas

Hi! i have the same problem in VC++
i solve doing that , include the <windows.h> at the top of your includes declaration , like this

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>

I feel like contributing to this off-topic discussion…

The only difference between classes and structs is that struct members default to public and class members default to private. That’s it! Everything you can do with a class, you can do with a struct and vice-versa.

I always use classes and never structs because mixing makes forward declarations a big hassle.