【发布时间】:2017-12-21 04:51:26
【问题描述】:
我想要一个窗口标题,当窗口调整大小时,它会自行更新。它的格式应该可以显示标题 窗口大小 - [宽度] x [高度] 但结果我得到了一个显示 _alloca 已损坏的标题。
int main(void)
{
GLFWwindow *window = NULL; //initialise window with pointer to GLFW handle
glfwSetErrorCallback(error_callback);
//initialise GLFW
if (!glfwInit())
{
//if failed to initialise GLFW
exit(EXIT_FAILURE);
}
//minimum OpenGL version 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//create the window here
window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Window Size - " + WINDOW_WIDTH + "x" + WINDOW_HEIGHT, NULL, NULL);
//if window fail, terminate GLFW
if (window == NULL)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window); // set window context as the current context
glfwSwapInterval(1); // swap buffer interval
// initialise GLEW
if (glewInit() != GLEW_OK)
{
// if failed to initialise GLEW
cerr << "GLEW initialisation failed" << endl;
exit(EXIT_FAILURE);
}
//set key callback function
glfwSetKeyCallback(window, key_callback);
//render loop
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window); //swap buffers
glfwPollEvents(); //poll for events
}
//close window, terminate GLFW
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
【问题讨论】:
-
我至少可以知道我做错了什么,而不是仅仅投反对票。稍微解释一下就好了,谢谢
-
这里有一个问题:
"Window Size - " + WINDOW_WIDTH + "x" + WINDOW_HEIGHT这不是合法的 C++。你的编译器应该给你一个错误。 -
@NicolBolas:假设
WINDOW_WIDTH与#define WINDOW_WIDTH 300类似,则编译得非常好(在VS2013 上测试)。由于第一部分是const char*,因此可以向其添加一个整数(指针运算)。