小编Gri*_*fin的帖子

OpenGL 三角形无法在 macOS 上渲染?

当我尝试在 macOS 上使用 OpenGL 渲染三角形时,出现黑屏:

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

static unsigned int CompileShader(unsigned int type, const std::string& source){
    unsigned int id = glCreateShader(type);
    const char* src = source.c_str();
    glShaderSource(id, 1, &src, nullptr);
    glCompileShader(id);
    
    int result;
    glGetShaderiv(id, GL_COMPILE_STATUS, &result);
    
    if(result == GL_FALSE){
        int length;
        glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
        char* message = (char*) alloca(length*sizeof(char));
        glGetShaderInfoLog(id, length, &length, message);
        std::cout << "Failed to compile " << (type == GL_VERTEX_SHADER ? "vertex" : "fragment") << " shader" << std::endl;
        std::cout << message << …
Run Code Online (Sandbox Code Playgroud)

c++ opengl macos glfw

1
推荐指数
1
解决办法
618
查看次数

标签 统计

c++ ×1

glfw ×1

macos ×1

opengl ×1