PDA

View Full Version : Lighting Class Causing Errors in gl.h?



31337
12-11-2002, 07:22 PM
For some reason my lighting code always causes errors in gl.h. I've asked good ol' gl man and he seems somewhat stumped as well. I've reviewed several examples and compared them to mine (and read through a bit of the red book itself) and I'm yet to see the problem here. This is my lighting class cpp file:



#include "lighting.h"
#include <stdio.h> // Header File For Input/Output
#include <gl\gl.h> // Header File For The GL Library
#include <gl\glu.h> // Header File For The GLu Library
#include <gl\glaux.h>

#define DONE 0

Lighting::Lighting() {
ambient[0] = 0.5; ambient[1] = 0.5; ambient[2] = 0.5; ambient[3] = 1.0;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0; diffuse[3] = 1.0;
position[0] = 1.0; position[1] = 0.0; position[2] = 0.0; position[3] = 1.0;
}

Lighting::~Lighting() {

}

int Lighting::makeLight() {

glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION,position);
glEnable(GL_LIGHT0);
return DONE;
}

Simple enough right? Here's the header incase it matters:



#ifndef _LIGHTING_H
#define _LIGHTING_H

#include <gl/gl.h>

class Lighting {
public:
Lighting();
~Lighting();
int makeLight();
private:
GLfloat ambient[4];
GLfloat diffuse[4];
GLfloat position[4];
};

#endif


Any help would be appreciated however talk to me like a 3 year old. I have never done lighting before (that I can recall at the moment) and so my knowledge of it is still VERY primitive.

What should my lighting class contain? What kindof functions? I would like to get shadows goin on eventually as well. Thanks again

12-11-2002, 09:42 PM
What errors are you getting. (If on windows) try including windows.h before the gl includes

M/\dm/\n
12-11-2002, 09:43 PM
Why the h.ll you want to make your life worse? Lignthing functions are simple enough & usually you only need glEnable&#0124; &#0124;Disable(GL_LIGHT0&#0124; &#0124;LIGHTING) and max no of light is 8 http://www.opengl.org/discussion_boards/ubb/biggrin.gif I tried to do somthing similiar at first, but noticed that it's not worth that. By the way, for serious ligntning you dont use OGL ligghts anyway, there are thing like vertex programs, projected textures+lightmaps http://www.opengl.org/discussion_boards/ubb/biggrin.gif If you really want to make all those function calls shorter use inline functions & macros http://www.opengl.org/discussion_boards/ubb/biggrin.gif

fringe
12-12-2002, 01:48 AM
Hey,

just a newbie but I thought I would repeat things I have seen before that might be helpful.
When are you calling make light? Is it after creating your device context?

Also you you have to reennable lighting after you change the lights around?

fringe

M/\dm/\n
12-12-2002, 04:00 AM
It's loooong time since I worked with standart OGL lightning, but as far as I remember all enables were at init() function, & I think positions can be changed even in render f if you wish.

31337
12-12-2002, 06:26 AM
No I am not calling windows.h EVER. I would be willing to if it was nessecary.

The errors I get:

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

To the guy who suggested not doing OpenGL lights, what other technique should I use? Can I find a tutorial? Thanks

Also - the weird part is i'm never calling any of the functions in this class except for maybe the constructor.

Bob
12-12-2002, 06:34 AM
You MUST include windows.h because GL/gl.h REQUIRES it, at least on the Windows platform. The reason is because GL/gl.h uses macros that are defined in windows.h (or a file included from there). OK, it does not require the file itself, but some macros that are defined in there.

However, if you have a REALLY good reason not to include it you can define those macros yourself. Look in the GLUT header for hints on how to do so.

Structural
12-12-2002, 06:53 AM
Another thing...

include "lighting.h" AFTER the gl.h and glu.h headers... Your "lighting.h" has types from gl.h, thus you will get errors since the types have not been defined before you use them.

#include <gl\gl.h>
#include "lighting.h" //AFTER gl.h

And as said before, do not forget your Windows includes:

#include <windows.h>

Put it ABOVE gl.h

[This message has been edited by Structural (edited 12-12-2002).]

Bob
12-12-2002, 07:38 AM
He's including <GL/gl.h> from <lighting.h>, so he can safely include <lighting.h> before <GL/gl.h> if he want to.

31337
12-12-2002, 01:32 PM
Well I guess I will include windows.h, so much for cross-platform...

Old GLman
12-12-2002, 02:16 PM
Thats the first thing I told you!!!

You can still retain cross platform, at the top of your file just do:

#ifdef _WIN32
#include <windows.h>
#endif

Old GLman

Bob
12-12-2002, 02:22 PM
Are you trying to write platform independent code without #if/endif?

Structural
12-12-2002, 10:06 PM
Originally posted by Bob:
He's including <GL/gl.h> from <lighting.h>, so he can safely include <lighting.h> before <GL/gl.h> if he want to.


Oh yeh.... didn't notice that... my bad!

Won't he get "redifinition of type blah blah blah" errors then? Haven't tested this, nor have I had this problem before. =/

Bob
12-13-2002, 02:31 AM
No. If you look inside literally any header you will see include guards in the beginning of the file. <GL/gl.h> have them, so does his <lighting.h>.



#ifndef _LIGHTING_H
#define _LIGHTING_H

...

#endif

Tell me if you don't know how/why they work.

I just want to say some words about the leading underscore. Two leading underscores in an identifier is reserved for the compiler and libraries for the compiler. A single leading underscore with a following capital letter in the global namespace (though I'm not 100% sure about the capital letter) is also reserved for the compiler and it's libraries. So basically you should not use any names with leading underscores in the global namespace. That include goard above is in the global namespace and is therefore somewhat against the specification. I would suggest not using underscores at all.