我正在开发一个 OpenGL 应用程序,在Linux (x86_32 和 x86_64)下一切正常,但在将应用程序移植到Windows期间我遇到了困难。我的应用程序使用非常基本的OpenGL 1.0、很棒的glfw 2.7.6和libpng 1.5.7。在移植整个程序之前,我尝试编写尽可能简单的代码来测试这些库是否在 Windows 下正常工作,并且一切似乎都工作得很好,直到我开始使用纹理!
在我的程序中使用纹理glTexImage2D(..)会出现访问冲突,并出现以下错误:
First-chance exception at 0x69E8F858 (atioglxx.dll) in sidescroll.exe: 0xC0000005: Access violation reading location 0x007C1000.
Unhandled exception at 0x69E8F858 (atioglxx.dll) in sidescroll.exe: 0xC0000005: Access violation reading location 0x007C1000.
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,发现这可能是 GPU 驱动程序错误。遗憾的是,我有一台配备AMD Radeon HD5650的东芝 L650-1NU笔记本电脑,没有提供任何驱动程序,而是由供应商分发的过时驱动程序。给定帖子的作者建议使用,但由于我使用OpenGL 1.0,我无法访问此方法。 glBindBuffer
您是否知道如何在不使用较新的 OpenGL 的情况下绕过此问题?不过,如果这是唯一的解决方案,可以向我提供有关如何将OpenGL 2.1与glfw一起使用的教程或代码片段吗?
这是我的代码片段,它导致了错误:
img = img_loadPNG(BACKGROUND);
if (img) {
printf("%p %d …Run Code Online (Sandbox Code Playgroud) 我正在尝试在openGL中编译一个非常简单的程序:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main()
{
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Use OpenGL 3.X
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Use openGL X.3
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create OpenGL context
GLFWwindow* window; // May be needed to make it global
window = glfwCreateWindow(1024, 768, "Tutorial 01", NULL, NULL);
if(window == NULL) …Run Code Online (Sandbox Code Playgroud) 在这里完成 CMake Noob。我正在尝试在 Clion IDE 中使用 glfw 库,即使经过 2 天的谷歌搜索,我也不明白我错过了什么/做错了什么。
以下是详细信息:
操作系统:Windows 8 Pro 64 位
IDE:克里昂
制作工具:CMake
编译器:MinGW v3.21
错误日志:
"C:\Program Files (x86)\JetBrains\CLion 1.2.3\bin\cmake\bin\cmake.exe"--build C:\Users\PranayKarani\.CLion12\system\cmake\generated\185d1d8\185d1d8\Debug --target openGL -- -j 4
[ 50%] Linking CXX executable openGL.exe
CMakeFiles\openGL.dir/objects.a(main.cpp.obj): In function `key_callback':
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:15: undefined reference to `glfwSetWindowShouldClose'
CMakeFiles\openGL.dir/objects.a(main.cpp.obj): In function `main':
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:22: undefined reference to `glfwSetErrorCallback'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:24: undefined reference to `glfwInit'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:27: undefined reference to `glfwCreateWindow'
E:/Pranay/BotX games/C++ projects/openGL/main.cpp:30: undefined reference to `glfwTerminate' …Run Code Online (Sandbox Code Playgroud) 我创建了一个名为 InputControl 的类。我正在使用一个名为 GLFW 的库和一个函数 glfwSetKeyCallback。该函数定义为:
GLFWkeyfun glfwSetKeyCallback ( GLFWwindow * window, GLFWkeyfun cbfun )
类型定义如下:
typedef void(* GLFWkeyfun) (GLFWwindow *, int, int, int, int)
问题是我无法将我的方法转换为函数指针。我觉得我已经尝试以各种可能的方式施展它。我不确定我还需要如何强制转换此方法。是否有特定于将相对方法作为函数指针传递的内容?我的代码如下:
#pragma once
#include <GLFW/glfw3.h>
#include "config.h"
class InputControl {
public:
void bind();
void unbind();
private:
void __glfw__keycallback_bind(GLFWwindow* window, int key, int scancode, int action, int mods);
};
Run Code Online (Sandbox Code Playgroud)
输入控件.cpp
void InputControl::bind() {
glfwSetKeyCallback(__application__window, __glfw__keycallback_bind);
}
void InputControl::unbind() {
}
void InputControl::__glfw__keycallback_bind(GLFWwindow * window, int key, int scancode, int action, int mods) {
//... other code …Run Code Online (Sandbox Code Playgroud) 我正在学习有关 Udemy - Modern Opengl 3.0 的教程。我已成功进入基本教程第 5 部分“投影和坐标系”。这在具有相同代码的 Mac 上完美运行,但我无法在 Windows 上运行。我什至重新启动了本教程,以确保我没有遗漏任何内容,并且之前的所有教程都有效,但我得到了相同的结果。它只是不会正确渲染。我在 Windows 上的 Visual Studio 2015 上做了这个。在 mac 上,我通过使用 vim 和 Makefile 来使用它……您会认为使用为您编译的 IDE 会更容易,但显然不是。
这就是我的屏幕上显示的内容,只是它闪烁得非常快并且移动很多,而不是我应该得到的旋转立方体。
这是代码:
着色器.h:
#ifndef SHADER_H
#define SHADER_H
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <GL/glew.h>
class Shader
{
public:
GLuint Program;
// Constructor generates the shader on the fly
Shader(const GLchar *vertexPath, const GLchar *fragmentPath)
{
// 1. Retrieve the vertex/fragment source code from filePath
std::string vertexCode;
std::string fragmentCode;
std::ifstream vShaderFile; …Run Code Online (Sandbox Code Playgroud) 我包括这样的glfw:
ExternalProject_Add(glfw-external
URL https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/glfw
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/install
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
add_dependencies(ShittyLife glfw-external)
if(UNIX)
set(GLFW_LIB <What to put here?> libglfw3.a)
else()
set(GLFW_LIB ${install_dir}/lib/glfw3.lib)
endif()
Run Code Online (Sandbox Code Playgroud)
稍后使用GLFW_LIB变量链接lib.
它在Windows上运行良好,但在Linux上我缺少一些库.glfw网页提供了解决方案,但它们似乎都没有与ExternalProject_add的兼容性.
关于如何弄清楚所需的库是什么的任何想法,最好是以跨不同机器/发行版的方式工作?
如果它有用,这是我在尝试构建时遇到的错误:
相关位:
/usr/bin/ld: /home/molion/Desktop/ShittyLife/build/install/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
Run Code Online (Sandbox Code Playgroud)
所有的:
[ 94%] Building CXX object CMakeFiles/ShittyLife.dir/src/main.cpp.o
[100%] Linking CXX executable ShittyLife
/usr/bin/ld: /home/molion/Desktop/ShittyLife/build/install/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status …Run Code Online (Sandbox Code Playgroud) 我正在创建一个GLFWKeyCallback,由于它非常简单,我决定使用 lambda。这个回调修改了一个成员变量,所以我必须将其传递到捕获列表中。到目前为止,我的代码如下所示:
glfwSetKeyCallback(window,
[this](GLFWwindow* window, int key, int scancode, int action, int mods)
{
if(action == GLFW_PRESS)
{
//use a mutex
//Modify member variable
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,每当我将其传递到捕获列表时,Visual Studio 2019 都会显示以下错误:
不存在从“lambda [] void (GLFWwindow *window, int key, int scancode, int action, int mods)->void”到 GLFWKeyfun”的合适转换函数
我是否错过了什么或者该代码只是无效?
在 GLFW 中,有一个称为“用户指针”的东西,我可以使用 glfwSetWindowUserPointer 来设置它。我不知道的是用户指针。这是我的猜测。用户指针是指向使用该窗口的用户的指针。我是对还是错?
我目前正在用 Rust 开发一个简单的程序,在屏幕上绘制一个彩色三角形。我按照OpenGL 的说明进行操作。我的程序运行良好,三角形按预期呈现:
之后,我尝试抽象代码: 和VAO成为VBO处理ShaderProgram绑定、附加着色器等的结构。那行得通。现在解决问题:
当我尝试抽象属性时遇到了问题。我将这两个方法添加到结构中ShaderProgram,它们应该处理属性的启用,而不必对诸如步幅或属性在向量中的位置开始的指针之类的内容进行硬编码。
pub fn add_attribute(&mut self, name: &'a str, length: i32) {
let mut props = VertexAttributeProps::new(name, length);
self.attributes.push(props);
}
pub fn apply_attributes(&self) {
const GL_FLOAT_SIZE: i32 = mem::size_of::<gl::types::GLfloat>() as i32;
let stride = self
.attributes
.iter()
.fold(0, |prev, attr| prev + attr.length)
* GL_FLOAT_SIZE;
let mut current_pos: i32 = 0;
for attr_options in self.attributes.iter() {
// println!("{:?}", current_pos);
unsafe {
let attribute = VertexAttribute::new( …Run Code Online (Sandbox Code Playgroud)