到目前为止,我已经在MacOs上安装了GLFW和GLEW。它们安装在下面的目录中(usr/local/c业力/)。
我从教程中获取了以下脚本,并添加了一些遗留的OpenGL,希望能够测试OpenGL的所有链接和工作。(我之所以这么做,是因为我还在学习OpenGL,而且我还没有在阴影下学习等等)。
CMakeList.txt
cmake_minimum_required(VERSION 3.3)
project(Lib_Test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa -framework OpenGL -framework IOKit")
set(SOURCE_FILES src/main.cpp CMakeLists.txt)
# add extra include directories
include_directories(/usr/local/include)
# add extra lib directories
link_directories(/usr/local/lib)
add_executable(Lib_Test main.cpp)
target_link_libraries(Lib_Test glfw)
target_link_libraries(Lib_Test glew)
find_package (GLM REQUIRED)
include_directories(include)main.cpp
#include <stdio.h>
// Include GLEW. Always include it before gl.h and glfw.h, since it's a bit magic.
#include <GL/glew.h>
// Include GLFW
#include <GLFW/glfw3.h>
// Include GLM
#include <glm/glm.hpp>
using namespace glm;
int main(){
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
// Open a window and create its OpenGL context
GLFWwindow* window; // (In the accompanying source code, this variable is global for simplicity)
window = glfwCreateWindow( 800, 600, "My App", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
// Ensure we can capture keys being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do{
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 buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
}所有的东西都会编译并运行。但什么都画不出来。我甚至可以改变背景颜色(使用glClear)。我的问题是,如果什么东西不起作用,我甚至不知道那是什么东西。
谢谢
发布于 2018-02-07 18:56:51
你是混合了旧的固定管道方式和现代(与着色器)方式。
glBegin - glEnd之间和包含的所有行都只适用于旧OpenGL。
GLFW_OPENGL_FORWARD_COMPAT不应对OSX产生任何影响。无论如何,记住它与GLFW_OPENGL_CORE_PROFILE不兼容。
我的建议是,你写着色器填充代码(编译等),即使它是漫长和困难的第一次。
顺便说一句,Mac不需要glew。OSX提供gl-函数,因此不需要检索指向它们的函数指针。不过,使用它是无害的。
https://stackoverflow.com/questions/48671188
复制相似问题