我正在使用找到的教程 here .我正在使用 GLFW。我的窗口加载正常,但调用时
GLuint vertexBuffer;
glGenBuffers( 1, &vertexBuffer );
printf( "%u\n", vertexBuffer );
它没有写入控制台,如果我关闭 openGL 窗口它就会中断(如果我关闭控制台则不会)。我想这是指针有问题?但这对我来说似乎是正确的,而且他在教程中也是如此。
这是我的整个非常小的 .cpp (VS2012):
#define GLEW_STATIC
#include <GL/glew.h>
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment( lib, "glfw.lib")
#pragma comment( lib, "opengl32.lib")
#pragma comment( lib, "glew32s.lib")
int main() {
glfwInit();
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW );
glfwSetWindowTitle( "OpenGL" );
printf("This works");
while( glfwGetWindowParam( GLFW_OPENED ) ) {
glfwSwapBuffers();
}
glewExperimental = GL_TRUE;
glewInit();
GLuint vertexBuffer;
glGenBuffers( 1, &vertexBuffer );
printf( "%u\n", vertexBuffer );
glfwTerminate();
exit( EXIT_SUCCESS );
}
最佳答案
它无法将其写入控制台,因为相关代码从未到达。
只要窗口打开,您的代码中就会有一个几乎无限的 while 循环。
while(glfwGetWindowParam(GLFW_OPENED))
{
glfwSwapBuffers();
}
你应该把所有的初始化代码放在这个循环之前。
glewExperimental = GL_TRUE;
glewInit();
并在循环之前或循环中创建缓冲区对象。实际上,当您想要将新内容加载到现有场景时,您会在循环内创建缓冲区对象。
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
printf("%u\n", vertexBuffer);
你的最终main
函数可能如下所示。
int main()
{
// GLFW initialization
glfwInit();
// ...
glfwOpenWindow(800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
glfwSetWindowTitle("My first OpenGL Application");
// GLEW initialization
glewExperimental = GL_TRUE;
glewInit();
// vertex buffer
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
printf("%u\n", vertexBuffer);
// main loop
bool running = true;
while(running) {
// exit
if (!glfwGetWindowParam(GLFW_OPENED))
running = false;
// display
glfwSwapBuffers();
}
// clean up
glfwTerminate();
exit(EXIT_SUCCESS);
}
关于c++ - 无法将 OpenGL 缓冲区打印到 GLEW 应用程序中的控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13369296/