glTexImage3D抛出异常
glTexImage3D throws exception
本文关键字:抛出异常 glTexImage3D 更新时间:2023-10-16
我正在尝试在VS13中编译此应用程序。我用这种方式连接了所有的图书馆:glew32。libReleaseWin32将glew32.dll放在与Debug相同的文件夹中有关glfw3
当我运行这段代码,它抛出一个异常在glTexImage3D;它说"访问违反执行位置0x00000000。"
#include <GL/glew.h>
#include <GL/glfw3.h>
#include <cstdlib>
#include <iostream>
GLenum volumeTexture;
int main() {
// Initialize GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW! I'm out!" << std::endl;
exit(-1);
}
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %sn", glewGetErrorString(err));
}
// Use red to clear the screen
glClearColor(1, 0, 0, 1);
glGenTextures(1, &volumeTexture);
glBindTexture(GL_TEXTURE_3D, volumeTexture);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 256, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
我注意到,如果我添加
,错误就会解决glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");
,但后来我得到同样的异常运行glGenFramebuffers(我得到它,即使我评论glTexImage3D行)我是不是把什么东西连接错了?
你的顺序不对。
glewInit()
需要一个当前的GL上下文来完成它的事情。如果没有当前上下文,它就不能查询GL的入口点,并将其所有函数指针(如glTexImage3D()
)设置为NULL。
glfwInit()
不创建GL上下文,也不创建当前的GL上下文。
你需要glfwCreateWindow()
和glfwMakeContextCurrent()
。
相关文章:
- 从构造函数抛出异常时如何克服内存泄漏
- 函数如何通知用户它基于函数原型抛出异常?
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- VisualStudios 会抛出异常,而代码块不会 [C++]
- 如果不包含 pthread,为什么 GCC 的线程标准库实现会抛出异常?
- ZMQ::send() 抛出异常并终止 QNX 进程.为什么以及如何从中恢复?
- new(std::nothrow) int[n] 抛出异常
- 为什么g_object_set抛出异常(vcruntime140.dll)?
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- C++子线程抛出异常
- 我们应该在抛出异常之前取消分配内存吗
- 有没有一种方法可以让OpenCLC++绑定为所有错误抛出异常
- 为什么访问模板化变体作为返回值抛出异常
- 如何实现,错误分配中止而不是抛出异常
- std::p riority_queue::p op什么时候会抛出异常
- 在0x5914F3BE抛出异常(基于.dll)
- std::vector 默认构造函数可以抛出异常吗?
- 挂钩创建文件抛出异常:读取访问冲突
- getaddrinfo 抛出异常
- 如果文件为c ,如何抛出异常