gpt4 book ai didi

c++ - 在 macOS 上编译 GLEW 和 GLUT?

转载 作者:行者123 更新时间:2023-11-30 03:21:41 25 4
gpt4 key购买 nike

我正在尝试将 glew 和 glut 标志添加到我的 cmd 行以正确编译我的程序。

没有 GLEW 和 GLUT 的代码:

#include <GLFW/glfw3.h>
#include <iostream>
#include <stdio.h>

using namespace std;
int main(void)
{
GLFWwindow* window;

/* Initialize the library */
if (!glfwInit())
return -1;

/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}

/* Make the window's context current */
glfwMakeContextCurrent(window);

/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.0f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();

/* Swap front and back buffers */
glfwSwapBuffers(window);

/* Poll for and process events */
glfwPollEvents();
}

glfwTerminate();
return 0;

}

用这个命令运行它:

g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework 
IOKit -framework CoreVideo

工作并绘制一个三角形。添加 include glew 和 glut 语句:

#include <GL/glew.h>
#include <GL/glut.h>

并改用此命令:

g++ openGL.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework 
IOKit -framework CoreVideo -lglut -lGLU -lGL -lGLEW

导致编译器给出超过 20 个错误并放弃。

完整的错误信息:

In file included from openGL.cpp:9:
In file included from ./openGL.hpp:12:
/usr/local/include/GL/glew.h:85:2: error: gl.h included before glew.h
#error gl.h included before glew.h
^
/usr/local/include/GL/glew.h:91:2: error: gltypes.h included before glew.h
#error gltypes.h included before glew.h
^
/usr/local/include/GL/glew.h:6586:22: error: typedef redefinition with different
types ('unsigned int' vs 'void *')
typedef unsigned int GLhandleARB;
^
/System/Library/Frameworks/OpenGL.framework/Headers/gltypes.h:28:18: note:
previous definition is here
typedef void *GLhandleARB;
^
In file included from openGL.cpp:9:
In file included from ./openGL.hpp:12:
/usr/local/include/GL/glew.h:19860:17: error: unknown type name
'PFNGLCOPYTEXSUBIMAGE3DPROC'; did you mean 'PFNGLCOPYTEXSUBIMAGE3DNVPROC'?
GLEW_FUN_EXPORT PFNGLCOPYTEXSUBIMAGE3DPROC __glewCopyTexSubImage3D;
^
/usr/local/include/GL/glew.h:16452:28: note: 'PFNGLCOPYTEXSUBIMAGE3DNVPROC'
declared here
typedef void (GLAPIENTRY * PFNGLCOPYTEXSUBIMAGE3DNVPROC) (GLenum target...
^
/usr/local/include/GL/glew.h:19861:17: error: unknown type name
'PFNGLDRAWRANGEELEMENTSPROC'; did you mean
'PFNGLDRAWRANGEELEMENTSEXTPROC'?
GLEW_FUN_EXPORT PFNGLDRAWRANGEELEMENTSPROC __glewDrawRangeElements;
^
/usr/local/include/GL/glew.h:10251:28: note: 'PFNGLDRAWRANGEELEMENTSEXTPROC'
declared here
typedef void (GLAPIENTRY * PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, ...
^
/usr/local/include/GL/glew.h:19862:17: error: unknown type name
'PFNGLTEXIMAGE3DPROC'; did you mean 'PFNGLTEXIMAGE3DNVPROC'?
GLEW_FUN_EXPORT PFNGLTEXIMAGE3DPROC __glewTexImage3D;
^
/usr/local/include/GL/glew.h:16454:28: note: 'PFNGLTEXIMAGE3DNVPROC' declared
here
typedef void (GLAPIENTRY * PFNGLTEXIMAGE3DNVPROC) (GLenum target, GLint ...
^
/usr/local/include/GL/glew.h:19863:17: error: unknown type name
'PFNGLTEXSUBIMAGE3DPROC'; did you mean 'PFNGLTEXSUBIMAGE3DNVPROC'?
GLEW_FUN_EXPORT PFNGLTEXSUBIMAGE3DPROC __glewTexSubImage3D;
^
/usr/local/include/GL/glew.h:16455:28: note: 'PFNGLTEXSUBIMAGE3DNVPROC' declared
here
typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE3DNVPROC) (GLenum target, GLi...
^
/usr/local/include/GL/glew.h:19865:17: error: unknown type name
'PFNGLACTIVETEXTUREPROC'; did you mean 'PFNGLACTIVETEXTUREARBPROC'?
GLEW_FUN_EXPORT PFNGLACTIVETEXTUREPROC __glewActiveTexture;
^
/usr/local/include/GL/glew.h:5701:28: note: 'PFNGLACTIVETEXTUREARBPROC' declared
here
typedef void (GLAPIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
^
/usr/local/include/GL/glew.h:19866:17: error: unknown type name
'PFNGLCLIENTACTIVETEXTUREPROC'; did you mean
'PFNGLCLIENTACTIVETEXTUREARBPROC'?
GLEW_FUN_EXPORT PFNGLCLIENTACTIVETEXTUREPROC __glewClientActiveTexture;
^
/usr/local/include/GL/glew.h:5702:28: note: 'PFNGLCLIENTACTIVETEXTUREARBPROC'
declared here
typedef void (GLAPIENTRY * PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
^
/usr/local/include/GL/glew.h:19867:17: error: unknown type name
'PFNGLCOMPRESSEDTEXIMAGE1DPROC'
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE1DPROC __glewCompressedTexImage1D;
^
/usr/local/include/GL/glew.h:19868:17: error: unknown type name
'PFNGLCOMPRESSEDTEXIMAGE2DPROC'
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE2DPROC __glewCompressedTexImage2D;
^
/usr/local/include/GL/glew.h:19869:17: error: unknown type name
'PFNGLCOMPRESSEDTEXIMAGE3DPROC'; did you mean
'PFNGLCOMPRESSEDTEXIMAGE3DNVPROC'?
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXIMAGE3DPROC __glewCompressedTexImage3D;
^
/usr/local/include/GL/glew.h:16450:28: note: 'PFNGLCOMPRESSEDTEXIMAGE3DNVPROC'
declared here
typedef void (GLAPIENTRY * PFNGLCOMPRESSEDTEXIMAGE3DNVPROC) (GLenum targ...
^
/usr/local/include/GL/glew.h:19870:17: error: unknown type name
'PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC'
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC __glewCompressedTexSubImage1D;
^
/usr/local/include/GL/glew.h:19871:17: error: unknown type name
'PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC'
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC __glewCompressedTexSubImage2D;
^
/usr/local/include/GL/glew.h:19872:17: error: unknown type name
'PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC'; did you mean
'PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC'?
GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC __glewCompressedTexSubImage3D;
^
/usr/local/include/GL/glew.h:16451:28: note:
'PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC' declared here
typedef void (GLAPIENTRY * PFNGLCOMPRESSEDTEXSUBIMAGE3DNVPROC) (GLenum t...
^
/usr/local/include/GL/glew.h:19873:17: error: unknown type name
'PFNGLGETCOMPRESSEDTEXIMAGEPROC'; did you mean
'PFNGLGETNCOMPRESSEDTEXIMAGEPROC'?
GLEW_FUN_EXPORT PFNGLGETCOMPRESSEDTEXIMAGEPROC __glewGetCompressedTexImage;
^
/usr/local/include/GL/glew.h:2486:28: note: 'PFNGLGETNCOMPRESSEDTEXIMAGEPROC'
declared here
typedef void (GLAPIENTRY * PFNGLGETNCOMPRESSEDTEXIMAGEPROC) (GLenum targ...
^
/usr/local/include/GL/glew.h:19874:17: error: unknown type name
'PFNGLLOADTRANSPOSEMATRIXDPROC'; did you mean
'PFNGLLOADTRANSPOSEMATRIXDARBPROC'?
GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXDPROC __glewLoadTransposeMatrixd;
^
/usr/local/include/GL/glew.h:7683:28: note: 'PFNGLLOADTRANSPOSEMATRIXDARBPROC'
declared here
typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
^
/usr/local/include/GL/glew.h:19875:17: error: unknown type name
'PFNGLLOADTRANSPOSEMATRIXFPROC'; did you mean
'PFNGLLOADTRANSPOSEMATRIXFARBPROC'?
GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXFPROC __glewLoadTransposeMatrixf;
^
/usr/local/include/GL/glew.h:7684:28: note: 'PFNGLLOADTRANSPOSEMATRIXFARBPROC'
declared here
typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXFARBPROC) (GLfloat m[16]);
^
/usr/local/include/GL/glew.h:19876:17: error: unknown type name
'PFNGLMULTTRANSPOSEMATRIXDPROC'; did you mean
'PFNGLMULTTRANSPOSEMATRIXDARBPROC'?
GLEW_FUN_EXPORT PFNGLMULTTRANSPOSEMATRIXDPROC __glewMultTransposeMatrixd;
^
/usr/local/include/GL/glew.h:7685:28: note: 'PFNGLMULTTRANSPOSEMATRIXDARBPROC'
declared here
typedef void (GLAPIENTRY * PFNGLMULTTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

我正在尝试学习 OpenGL,但不知道该做什么。

最佳答案

Glut 和 GLFW 是完全不同的库。看这里What is the difference between FreeGLUT vs GLFW?

我认为尝试将它们混合在同一个程序中是不明智的,并且 .h 文件可能会发生冲突 - 这可能解释了许多错误。

通常您可以使用 GLFW 或 GLUT,但不能同时使用它们,它们的行为完全不同。

我还注意到您正在使用即时模式在 OpenGL 中绘图。这很容易,而且是一个不错的起点,但不再像这样完成了。因此,请准备好使用顶点数组对象 (VBO) 来绘制更复杂但速度更快、功能更强大的方法。在执行即时模式时,请尝试提前阅读并完成一些 VBO 教程。

关于c++ - 在 macOS 上编译 GLEW 和 GLUT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51922640/

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