I'm using Visual Studio 2010.
I'm trying to write simple Camera class in OpenGL.
I need to include gl/gl.h in Camera.h
gl/gl.h is already included in main.cpp and Camera.h is included in main.cpp
When I put
#include <gl/gl.h>
in Camera.h i got bunch of errors like this one:Error 11 error C2086: 'int APIENTRY' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gl\GL.h 1153 1 Gaz 3D
files:
Camera.h
#include <math.h>
#include <gl/gl.h>
#ifndef _CAMERA_H
#define _CAMERA_H
class Camera
{
private:
Camera();
public:
static Camera& getCamera();
float x, y, z, rotv, roth;
void moveForward(float n);
void moveBackward(float n);
void moveLeft(float n);
void moveRight(float n);
void lookUp(float n);
void lookDown(float n);
void lookLeft(float n);
void lookRight(float n);
};
#endif
main.cpp:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <math.h>
#include "Camera.h"
// ... some variables ...
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
// main code ...
}
What am I doing wrong?
OpenGL is part of Windows XP and the Visual Studio. Its library files are usually in C:\Program Files\Microsoft Visual Studio . NET 2003\Vc7\PlatformSDK\Lib: opengl32.
Just do an include of windows.h first.
#include <windows.h>
As it's said in the OpenGL FAQ :
Also, note that you'll need to put an
#include <windows.h>
statement before the#include<GL/gl.h>
. Microsoft requires system DLLs to use a specific calling convention that isn't the default calling convention for most Win32 C compilers, so they've annotated the OpenGL calls in gl.h with some macros that expand to nonstandard C syntax. This causes Microsoft's C compilers to use the system calling convention. One of the include files included by windows.h defines the macros.
Resources :
Edit: Obviously Colin Hebert solved the problem, but as a general tip I`d like to say:
In Camera.h write
#ifndef _CAMERA_H
#define _CAMERA_H
above all other includes. And include all header files needed in your .cpp file in your .h file.
At least that`s what I think is best practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With