标签: glfw

glDebugMessageCallback 导致访问冲突(GLFW + GLAD)

我安装了 OpenGL 4.4 版本、相应的 4.4 核心 GLAD 版本和 GLFW 版本 3.2(在 Visual Studio 2015 中编辑)。我正在使用回调函数,详见https://learnopengl.com/#!In-Practice/Debugging

void APIENTRY glDebugOutput(GLenum source, GLenum type, GLuint id, GLenum severity, 
    GLsizei length, const GLchar *message, const void *userParam);
Run Code Online (Sandbox Code Playgroud)

我有以下功能:

GLFWwindow* init(int width, int height, const char* header) {
    GLFWwindow* window;

    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    window = glfwCreateWindow(width, height, header, NULL, NULL);
    if (window == NULL) {
        glfwTerminate();
        throw std::runtime_error("Failed to create GLFW window.");
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, resizeCallback);

    if …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glfw visual-c++

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

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
查看次数

GLEW 未在 MSYS2 上定位 OpenGL 函数

我正在尝试在我的笔记本电脑上玩几个 OpenGL。作为最快的方法,我安装了 MSYS2。我安装了mingw-w64-x86_64-gccmingw-w64-x86_64-glew等等mingw-w64-x86_64-glfw3。我想我安装了所有必需的软件包。当我调用 OpenGL 例程时,我的程序就会出现分段错误。

为了制作一个最小的工作示例,我Hello, TriangleLearnOpenGL.com复制示例,以便保持较小的规模。我在这个程序中也遇到了同样的问题。

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

void processInput(GLFWwindow *window);

// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;

const char *vertexShaderSource = "#version 330 core\n"
    "layout (location = 0) in vec3 aPos;\n"
    "void main()\n"
    "{\n"
    "   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
    "}\0";
const char *fragmentShaderSource = "#version 330 core\n"
    "out vec4 FragColor;\n"
    "void main()\n"
    "{\n"
    "   FragColor …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glew glfw msys2

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

使用 CMake 找不到包 GLFW

我的项目结构如下所示:

  • CMakeLists.txt
  • 部门
    • 格卢
    • GLFW
  • 包括
  • 源代码
    • ...
    • 图形
      • ...
      • CMakeLists.txt

两个值得关注的 CMakeLists.txt 文件:

CMakeLists.txt

cmake_minimum_required(VERSION 3.9)
project(noam_engine)

find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)

set(CMAKE_CXX_STANDARD 11)
set(NE_LIBRARIES common math graphics)

FOREACH(lib ${NE_LIBRARIES})
    add_subdirectory(src/${lib})
ENDFOREACH(lib)

add_executable(noam_engine src/main.cpp)

if(OPENGL_FOUND AND GLEW_FOUND)
    target_include_directories(noam_engine PUBLIC include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
    target_link_libraries(noam_engine ${NE_LIBRARIES})
endif()
Run Code Online (Sandbox Code Playgroud)

src/graphics/CMakeLists.txt

cmake_minimum_required(VERSION 3.9)

find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)

file(GLOB SRC "*.cpp")
add_library(graphics ${SRC})

if(OPENGL_FOUND AND GLEW_FOUND)
    target_include_directories(graphics PUBLIC ${PROJECT_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
    target_link_libraries(graphics ${OPENGL_gl_LIBRARY} ${GLFW3_LIBRARY} ${GLEW_LIBRARIES})
    message(STATUS "GLFW and GLEW successfully linked")
    message(STATUS …
Run Code Online (Sandbox Code Playgroud)

opengl cmake glfw

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

了解 OpenGL 投影矩阵

我一直在编写一个程序来使用 OpenGL 显示 3D 模型,到目前为止我一直使用正交投影,但我想切换到透视投影,以便当相机朝向模型时,它看起来会变大。我知道我必须将三个矩阵(模型、视图和投影)相乘才能正确应用所有转换。正如您在下面的代码中看到的,我尝试这样做,并且能够正确创建模型和查看矩阵。我知道这些工作正常,因为当我将模型和视图投影相乘时,我可以旋转和平移对象,以及更改相机的位置和角度。我的问题是,当我将该乘积乘以投影矩阵时,我无法再在屏幕上看到该对象。

\n\n

这里相机结构的默认值是 {0,0,-.5},但我使用键盘操纵该值来移动相机。

\n\n

我正在使用 GLFW+glad,linmath.h用于矩阵数学。

\n\n
    //The model matrix controls where the object is positioned. The\n    //identity matrix means no transformations.\n    mat4x4_identity(m);\n    //Apply model transformations here.\n\n    //The view matrix controls camera position and angle.\n    vec3 eye={camera.x,camera.y,camera.z};\n    vec3 center={camera.x,camera.y,camera.z+1};\n    vec3 up={0,1,0};\n    mat4x4_look_at(v,eye,center,up);\n\n    //The projection matrix flattens the world to 2d to be rendered on a\n    //screen.\n    mat4x4_perspective(p, 1.57, width/(float)height, 1,10); //FOV of 90\xc2\xb0\n    //mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);\n\n    //Apply the transformations. …
Run Code Online (Sandbox Code Playgroud)

opengl glfw projection-matrix

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

如何让各向异性过滤扩展发挥作用?

在我的(C++/OpenGL)程序中,我加载一组纹理并设置纹理参数,如下所示:

\n\n
//TEXTURES\nglGenTextures(1, &texture1);\nglBindTexture(GL_TEXTURE_2D, texture1);\n// set the texture wrapping parameters\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\n// set texture filtering parameters\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\n\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);\n
Run Code Online (Sandbox Code Playgroud)\n\n

我发现各向异性过滤可以帮助我增强场景的外观。因此,我使用这一行来实现它:

\n\n
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 16);\n
Run Code Online (Sandbox Code Playgroud)\n\n

虽然我在我的笔记本电脑(有 AMD GPU 供应商)上编译这行代码没有任何问题,但我无法在使用 Intel(R) HD Graphics 530 (Skylake GT2) 的另一台计算机上编译这段代码。\n具体来说,尝试使用 g++ 编译该代码段会输出以下错误:

\n\n
error: \xe2\x80\x98GL_TEXTURE_MAX_ANISOTROPY\xe2\x80\x99 was not declared in this scope\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 16);\n
Run Code Online (Sandbox Code Playgroud)\n\n

更具体地说,在我的 Linux 终端中运行以下命令:

\n\n
glxinfo | grep -i opengl\n
Run Code Online (Sandbox Code Playgroud)\n\n

显示有关我的 GPU 供应商和 OpenGL 支持的以下详细信息:

\n\n

在此输入图像描述

\n\n

我知道在 中启用了各向异性过滤ARB_texture_filter_anisotropic,但老实说,我不知道如何检查我的 GPU 供应商是否支持该扩展,如果支持,我如何才能使用各向异性过滤? …

c++ opengl textures glfw opengl-extensions

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

如何在 Windows 上使用 OpenGL ES 和 GLFW?

因为NVIDIA DRIVE product supports the OpenGL ES 2 and 3 specifications,我想在 Windows 10 上使用 GTX 2070 运行 OpenGL ES 代码,这将消除另外的 GLFW 支持配置,例如glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API). 是否可以使用 GLFW 在 Windows 10 上运行 OpenGL ES 代码?

windows opengl-es glfw

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

由于 GLAD 错误,无法在 Ubuntu 中编译 OpenGL 程序

我成功安装了GLWF。我可以证明,由于该程序可以编译:

#include <GLFW/glfw3.h>

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);

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

        /* Poll for and …
Run Code Online (Sandbox Code Playgroud)

opengl compiler-errors glfw glad

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

当渲染循环中运行大量模拟时如何刷新 GUI 框架?

我正在尝试创建一个应用程序,用户可以通过按一下按钮来运行(耗时的)后端物理模拟。但与此同时,我希望 GUI 的其余部分保持功能,并且在模拟结束之前不会“冻结”。现在我知道在 OpenGL 中组合多个线程进行渲染并不是一个好主意,所以我的想法相当简单:1)使用一个线程(我想是默认线程)来运行除物理之外的所有内容。2)使用另一个线程,仅运行我在一个函数中限制的物理,正如您将看到的。但即使这样,整个 GUI 仍然“冻结”,因此在物理结束之前它毫无用处。我该如何解决这个问题?

下面是我认为可行的代码。它呈现一个“测试按钮”,以检查我是否可以在物理运行时实际按下它,以及触发大量计算的“运行物理”按钮。

#include"imgui.h"
#include"imgui_impl_glfw.h"
#include"imgui_impl_opengl3.h"

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

#include<cstdio>
#include<cmath>
#include<thread>

//Hypothetical "heavy" computation
void run_physics()
{
    for (double z = 0.0; z < 10000.0; z += 0.001)
    {
        double y = exp(sin(sqrt(z*abs(z)+ cos(z))));
    }
    return;
}

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow *window = glfwCreateWindow(800,600, "Test", NULL, NULL);
    if (window == NULL)
    {
        printf("Failed to open a glfw window. Exiting...\n");
        return 0;
    }

    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;
    if (glewInit() …
Run Code Online (Sandbox Code Playgroud)

c++ opengl multithreading glfw imgui

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

Vulkan RAII。尝试创建 VkSurfaceKHR 时遇到 VK_ERROR_NATIVE_WINDOW_IN_USE_KHR

我正在学习 Vulkan_raii API 并遇到了这个问题:

我有源文件:

#include <vulkan/vulkan_raii.hpp>
#include <GLFW/glfw3.h>
#include <iostream>

int main() {

  glfwInit();
  GLFWwindow *window =
      glfwCreateWindow(800, 600, "First window", nullptr, nullptr);
  if (!window) {
    std::cerr << "Failed to create a window!" << std::endl;
    return 0;
  }

  vk ::raii::Context context;
  uint32_t version = context.enumerateInstanceVersion();
  vk::ApplicationInfo appInfo{"instance", version, "instance", version, version};
  vk::InstanceCreateInfo create_info{
    vk::InstanceCreateFlags{},nullptr, 0, nullptr, 0, nullptr
  };
  vk::raii::Instance instance{context, create_info};

  VkSurfaceKHR c_style_surface;
  auto res = glfwCreateWindowSurface(*instance, window, nullptr, &c_style_surface);
  if (res != VK_SUCCESS) {
    std::cerr << "Failed …
Run Code Online (Sandbox Code Playgroud)

c++ glfw vulkan

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