C++ 很高兴初始化失败
我遇到一个问题,以下代码行总是打印“初始化失败”,然后退出程序:C++ 很高兴初始化失败,c++,opengl,visual-studio-2015,glfw,C++,Opengl,Visual Studio 2015,Glfw,我遇到一个问题,以下代码行总是打印“初始化失败”,然后退出程序: if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout您从
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout您从未通过glfwMakeContextCurrent()
将GL上下文设置为当前。与其他GL窗口框架不同,GLFW在glfwCreateWindow()
成功时不会将GL上下文设置为当前
:
GLFWwindow*window=glfwCreateWindow(800600,“Lab3”,NULL,NULL);
如果(窗口==NULL)
{
谢谢,只是错过了教程中的一行。
#include "stdafx.h"
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <iostream>
using namespace std;
void init_glfw();
void framebuffer_size_callback(GLFWwindow*, int, int);
int main(int argc, char **argv)
{
init_glfw();
GLFWwindow* window = glfwCreateWindow(800, 600, "Lab3", NULL, NULL);
if (window == NULL)
{
cout << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
glViewport(0, 0, 800, 600);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
while (!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void init_glfw()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
GLFWwindow* window = glfwCreateWindow(800, 600, "Lab3", NULL, NULL);
if (window == NULL)
{
cout << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent( window );
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}