我遇到了GLUT的问题。当按下某个按钮或单击鼠标按钮时,我正在尝试关闭程序。这是ESC和右键单击。
我不知道为什么它不起作用,这是下面的代码
#include "stdafx.h"
#include <glut.h>
#include <iostream>
void keyboard(unsigned char c, int x, int y);
void mouse (int button, int state, int x, int y);
void render(void);
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100); //Position of the window
glutInitWindowSize(640, 480); //Screen Size
glutCreateWindow("Greeting Card"); //Creates the window and names it
glutDisplayFunc(render);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); //Finished, now render
}
void keyboard(unsigned char c, int x, int y) {
if (c == 27) {
exit(0);
}
}
void mouse (int button, int state, int x, int y) {
if (button == GLUT_RIGHT_BUTTON) {
exit(0);
}
以下是错误
Error 3 error C3861: 'exit': identifier not found i:\computer graphics\consoleapplication1\consoleapplication1\consoleapplication1.cpp 31 1 ConsoleApplication1
Error 2 error C3861: 'exit': identifier not found i:\computer graphics\consoleapplication1\consoleapplication1\consoleapplication1.cpp 25 1 ConsoleApplication1
Error 1 error C2381: 'exit' : redefinition; __declspec(noreturn) differs c:\program files (x86)\microsoft visual studio 11.0\vc\include\stdlib.h 360 1 ConsoleApplication1
我已经包含#include并且仍然遇到相同的错误:(
答案 0 :(得分:1)
答案 1 :(得分:0)
exit
实际上是在#include <iostream>
中定义的。
我已经通过加入iostream让这项计划得以实现。
永远不要忘记:如果你没有添加命名空间std ::你需要在exit()
之前添加它。