C++ opengl / glsl / sdl 代码中的访问冲突
我正在关注一些有关 GLSL 的在线教程。我已经将代码实现到我当前的程序中。它编译得很好,但是当我调试它时,我遇到了访问冲突:
First-chance exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.
Unhandled exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.
我不知道为什么。这是它指向的行:
GLuint v,f,f2,p,ge;
int gw = RESOLUTION_X;
int gh = RESOLUTION_Y;
void setShaders()
{
char *vs = NULL, *fs = NULL, *fs2 = NULL, *gs = NULL;
v = glCreateShader(GL_VERTEX_SHADER); //<-- this line
f = glCreateShader(GL_FRAGMENT_SHADER);
ge = glCreateShader(GL_GEOMETRY_SHADER_EXT);
...
我需要提供任何额外的代码吗?我只是不确定这里做错了什么。
I am following some tutorials online regarding the GLSL. I have been implementing the code into my current program. It compiles just fine, but when I debug it, I get an access violation:
First-chance exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.
Unhandled exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.
I am not sure why. Here is the line it is pointing to:
GLuint v,f,f2,p,ge;
int gw = RESOLUTION_X;
int gh = RESOLUTION_Y;
void setShaders()
{
char *vs = NULL, *fs = NULL, *fs2 = NULL, *gs = NULL;
v = glCreateShader(GL_VERTEX_SHADER); //<-- this line
f = glCreateShader(GL_FRAGMENT_SHADER);
ge = glCreateShader(GL_GEOMETRY_SHADER_EXT);
...
Do I need to provide any additional code? I'm just not sure what is being done wrong here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您忘记调用
SDL_Init
?或者也许从多个线程调用这个函数?Perhaps you forgot to call
SDL_Init
? Or maybe calling this function from multiple threads?我想说 glCreateShader 是一个指向函数的 NULL 指针。并非所有驱动程序都支持此功能,因此您应该使用某种 GL 扩展包装器,例如优秀的 GLEW。
在使用扩展之前,您应该检查当前实现是否支持它:在您的情况下,它是一个 GL2.0 函数,因此:
if (GLEW_VERSION_2_0) ...
。I'd say that glCreateShader is a NULL pointer to function. This is a function that not all drivers support, so you should be using some kind of GL extension wrapper, such as the excellent GLEW.
And before using an extension you should check that it is supported by the current implementation: in your case it is a GL2.0 function so:
if (GLEW_VERSION_2_0) ...
.