C++ code using GLFW3 on Maverick: glShaderSource no matching function

ぐ巨炮叔叔 提交于 2019-12-13 21:26:24

问题


I am trying to compile a fairly simple C++ program using the library GLFW3 on Mac. The OS is OS 10.9.3 (Maverick). It compiles fine until I try to use GLSL functions such as glShaderSource, etc.

Here are the include files I use:

#include <GLFW/glfw3.h>
#include <cstdlib>
#include <cstdio>

I am using OpenGL3.2:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Here is the command line to compile the program:

clang++ -o xxxx xxxx.cpp  -framework Cocoa -framework OpenGL  -Wall -lglfw3 -I/usr/local/include/ -L/usr/local/lib  -framework Quartz -framework IOKit

And now the error:

xxxx:38:5: error: no matching function for call to 'glShaderSource'
    glShaderSource(vertexShader, 1, &vertexSource, NULL);

I am sure I missing something basic but what? Thanks for your help. I fear it has something to do with glext but not sure what to do really. I couldn't find anything on Stackoverflow on the web.


回答1:


On OS X, you need to include <OpenGL/gl3.h> to get definitions for GL3+ level entry points.

In the GLFW documentation, on the page "Building programs that use GLFX" (http://www.glfw.org/docs/latest/build.html), there is a section named "GLFW header option macros". The relevant sections are:

These macros may be defined before the inclusion of the GLFW header and affect the behavior of the header.

GLFW_INCLUDE_GLCOREARB makes the header include the modern GL/glcorearb.h header (OpenGL/gl3.h on OS X) instead of the regular OpenGL header.

So the following should do the trick:

#define GLFW_INCLUDE_GLCOREARB
#include <GLFW/glfw3.h>

Looking at the glfw3.h header (http://www.glfw.org/docs/latest/glfw3_8h_source.html) confirms that it will include <OpenGL/gl3.h> with this additional define.



来源:https://stackoverflow.com/questions/24664722/c-code-using-glfw3-on-maverick-glshadersource-no-matching-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!