FreeGLUT API文档中没有包含条目glutInitContextVersion,当我谷歌搜索它时,我发现的所有问题都没有直接解决其使用或效果.
是否记录在任何地方?
当我尝试运行这个简单的OpenGL测试程序时,我遇到了分段错误.只有在使用核心配置文件标志创建上下文时才会发生这种情况.如果我使用兼容性配置文件标志,程序运行没有问题.
编辑:我检查了函数的指针glGenVertexArrays,然后返回NULL.如果glfwCreateWindow没有返回NULL,并glGetString(GL_VERSION)确认上下文是版本4.3并glewInit返回GLEW_OK那么为什么glGenVertexArrays == NULL?
我的操作系统是64位Windows 7,而我的GPU是带有331.82 WHQL驱动程序的Nvidia GTX 760.
码:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
#define GLSL(src) "#version 430 core\n" #src
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
GLuint create_program(const char* vertex_source, const char* fragment_source)
{
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, &vertex_source, NULL);
glCompileShader(vs); …Run Code Online (Sandbox Code Playgroud) 我已经在堆栈上看了几个关于这个问题的其他问题,它提到了取消引用空指针,但我不明白这是否适用于我的代码.
在尝试生成VAO时,代码在World.cpp的第33行崩溃:
glGenVertexArrays(1, &vao);
Run Code Online (Sandbox Code Playgroud)
给我标题中显示的错误.如果我注释掉该行程序运行正常.
PhaseEngineMain.cpp
#include "PhaseEngineMain.h"
#include "PhaseEngineController.h"
int main(int argc, char *argv[])
{
PhaseEngineController engine;
engine.start();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
PhaseEngineController.h
#pragma once
#include "SDL.h"
#include "glew.h"
#include "World.h"
#include <iostream>
class PhaseEngineController
{
public:
PhaseEngineController();
~PhaseEngineController();
void InitialiseEngine();
void IntitialseOpenGL();
void InitialiseSDL(Uint32 x, Uint32 y, Uint32 width, Uint32 height, Uint32 flags);
void InitialiseGLEW();
void SetClearColour(float r, float g, float b, float a);
void PrintIntialisationInfo();
void start();
void stop();
void run();
void UpdateLoop();
void RenderLoop();
void SwapBackBuffer();
private: …Run Code Online (Sandbox Code Playgroud)