Including OpenGL in a header?

Started by
13 comments, last by DreamGhost 18 years, 2 months ago
I still can't do it. :(

If I have opengl.h (for example) and include gl.h and the others there and then include these in the main.cpp and opengl.cpp I get errors in gl.h like:

Windows error C2144: syntax error : 'void' should be preceded by ';'

The line with above error:
WINGDIAPI void APIENTRY glAccum (GLenum op, GLfloat value);


What would I do so it doesn't do this?
Advertisement
That is the error you get when you don't include windows.h before including gl.h. As mantioned already, you have to include windows.h on Windows.
Ok, so is there any way of including windows.h in one header, gl.h + others in another header adn including them both in main?
What's wrong with just including windows.h everywhere you include gl.h? If you include windows.h indirectly via another file, you gonna have to remember to include that file instead at every point you need gl.h.
Quote:The OpenGL code is platform independent, but everything around that is not. The gl.h that belongs to Microsofts implementation of OpenGL present on virtually all installation of Windows does requires windows.h to be included*.


Well I don't use the Microsoft version so that might be why hehe.

I say just organize the way you feel works best for you but if your just starting out I'd stick to one file until you learn how to work with everything to simplify everything a bit. Working with headers can get rough at times when just starting out with new api.

One thing you could do is have:
opengl.h
#ifndef _OPENGL_H
#define _OPENGL_H

#include <windows.h>
#include <gl.h>

(function declarations)

#endif

opengl.c
#include "opengl.h"

(whatever opengl functions you want to use)

main.c
#include "opengl.h"

(windows stuff)

This would remove the platform independency though, I use Dev-C++ and I incorporate their version of gl.h and glu.h which doesn't require windows.h to be included before it. So instead main.c would have #include <windows.h>.

If you're still having problems just paste some source code so we might be able to help you.

[Edited by - DreamGhost on January 27, 2006 9:40:58 AM]

This topic is closed to new replies.

Advertisement