[英]GLFW program compiles fine but does not run
我從GLFW-文檔中編譯了示例代碼:
#include <glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
我正在Windows 10下使用g ++編譯器。
我使用以下命令編譯並鏈接了它:
g++ -I. example.cpp -oexample -lopengl32 -L. -lglfw3dll
該過程成功終止,但是當我嘗試執行exe
文件時,它不起作用。
請提供任何幫助(我也嘗試在源代碼的開頭添加#define GLFW_DLL
和#include <windows.h>
,但仍然無法正常工作)
編輯:調試程序后,似乎未創建window
對象。
實際上問題是我的PC圖形卡不支持最新版本的openGL。 我在支持openGL4的PC上執行了代碼。 4,它運行正常!
從提供的代碼中可以看到,您沒有調用“ glfwDefaultWindowHints()”來創建默認屬性。 可能的是,如果不指定這些內容,則將“ GLFW_VISIBLE”標志設置為false。 另一種嘗試是靜態鏈接OpenGL庫或使用GLEW。 對於靜態鏈接,我建議使用IDE,例如Visual Studio,Code :: Blocks,XCode或您喜歡的任何一種(我建議使用Visual Studio for Windows)。 有很多有用的教程 ,可以為OpenGL設置IDE。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.