gpt4 book ai didi

opengl - 不能包含

转载 作者:行者123 更新时间:2023-12-03 20:15:45 33 4
gpt4 key购买 nike

我正在使用 Visual Studio 2010。
我正在尝试在 OpenGL 中编写简单的 Camera 类。
我需要在 Camera.h 中包含 gl/gl.h
gl/gl.h 已经包含在 main.cpp 中,Camera.h 包含在 main.cpp 中
当我放

#include <gl/gl.h>

在 Camera.h 中,我遇到了一堆这样的错误: Error 11 error C2086: 'int APIENTRY' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gl\GL.h 1153 1 Gaz 3D
文件:
相机.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

主.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 ...
}

我究竟做错了什么?

最佳答案

只需先包含 windows.h。

#include <windows.h>

正如 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.



资源:
  • social.msdn.microsoft.com - OpenGL problems
  • OpenGL FAQ - Why am I getting compile, link, and runtime errors?
  • 关于opengl - 不能包含 <gl/gl.h>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3760949/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com