PDA

View Full Version : Problems with Object-Oriented OpenGL programming



Kdawg2002
12-16-2001, 09:34 AM
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: http://www.opengl.org/discussion_boards/ubb/biggrin.gifraw(){
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.

Kdawg2002
12-16-2001, 09:36 AM
I didn't mean for that smiley face to appear...it's a ":" followed by a "D".

Tron
12-16-2001, 09:38 AM
include the windows.h BEFORE GL/gl.h

Kdawg2002
12-16-2001, 10:05 AM
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!

Keermalec
12-16-2001, 10:45 AM
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
};

Kdawg2002
12-16-2001, 10:55 AM
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.

MrShoe
12-16-2001, 11:43 PM
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

dbugger
12-17-2001, 04:23 AM
Classes are much better than structs.
The code gets cleaner and if you want to produce object-oriented code you really should use them.

T2k
12-17-2001, 04:28 AM
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:
...
};

endo
12-17-2001, 04:38 AM
This sounds like an OO argument to...
http://www.opengl.org/discussion_boards/ubb/biggrin.gif

rixed
12-17-2001, 06:43 AM
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).]

Juha Hiekkamäki
12-17-2001, 09:45 AM
Originally posted by rixed:
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).]


You are really using that syntax? Ever heard of constructors and initializing lists? http://www.opengl.org/discussion_boards/ubb/smile.gif
Works for both classes and structs.

Kristian Spangsege
12-17-2001, 10:54 AM
class CClass{
public:
CClass(){};
~CClass(){};
Draw();
}


Class Defintion Should end in ;




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


Classic C++ gaffe http://www.opengl.org/discussion_boards/ubb/smile.gif

12-17-2001, 05:02 PM
another often overlooked + of classes is the ability to specify the default constructer, which in my opionion cleans up ur code very nicely http://www.opengl.org/discussion_boards/ubb/smile.gif

Kdawg2002
12-17-2001, 06:27 PM
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.

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

cix>foo
12-19-2001, 03:30 PM
Or you could have stuck with Java and save a whole load of pointless syntactical headaches and just get the job done...

Cas http://www.opengl.org/discussion_boards/ubb/smile.gif

juglarx
12-20-2001, 04:31 AM
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>

Jambolo
12-20-2001, 04:32 PM
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.