-2
我希望有一個窗口標題,每當窗口被調整大小時都會自動更新。它應該是一個格式,使標題顯示爲 窗口大小 - [寬度] 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);
}
而不只是反對投票至少我可以知道那是什麼,我已經做了錯誤。謝謝 – Monomoni
這裏有一個問題:''窗口大小 - 「+ WINDOW_WIDTH +」x「+ WINDOW_HEIGHT'這不是合法的C++。你的編譯器應該給你一個錯誤。 –
@NicolBolas:假設'WINDOW_WIDTH'類似於'#define WINDOW_WIDTH 300',這個編譯非常好(在VS2013上測試)。由於第一部分是一個'const char *',因此可以向它添加一個整數(指針算術)。 – BDL