我的任務是使用GLUT來要求用戶輸入座標並顯示一個矩形。但是,我似乎無法獲得從「int main」到「void display」的座標。如何從主要信息獲取信息到無效?
這裏是我到目前爲止的代碼:
#include<iostream>
#include<gl/glut.h>
using namespace std;
void display(float yaxis, float xaxis)
{
glClearColor(1, 1, 1, 1);
glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_QUADS);
glColor3f(0, 0, 0);
glVertex2f(yaxis, -xaxis);
glVertex2f(yaxis, xaxis);
glVertex2f(-yaxis, xaxis);
glVertex2f(-yaxis, -xaxis);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
float xaxis;
float yaxis;
cout << "Please enter the co-ordinates for the x axis and press enter.";
cin >> xaxis;
cout << "You entered: " << xaxis
<< ".\n Please enter the co-ordinates for the y axis and press enter.";
cin >> yaxis;
cout << "You entered: " << yaxis << ".\n Here is your rectangle.";
glutInit(&argc, argv);
glutInitWindowSize(640, 500);
glutInitWindowPosition(100, 10);
glutCreateWindow("Triangle");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
您從用戶,並立即'return'獲取輸入。你不想那麼做嗎? –
'return'表示現在離開功能。返回後的任何代碼都會被忽略。應該是一個編譯器警告或兩個有關。 – user4581301
我投票結束這個問題作爲題外話,因爲它不是一個錯字,但是一個糟糕的'返回'對幫助未來的提問者沒有多大用處。 – user4581301