如何从main到void获取信息
How to get info from main to void?
我的任务是使用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;
}
glutDisplayFunc
函数具有以下声明:
void glutDisplayFunc(void (*func)(void));
因此,您不能在实现display
函数时使用它。下面是一个快速示例,可以修复您的错误:
#include<iostream>
#include<gl/glut.h>
using namespace std;
static float yaxis;
static float xaxis;
void display()
{
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)
{
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("Rectangle");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 将尾部调用void(i32,..)位转换为llvm::函数以获取FnAttribute
- C++ 随机数生成器:尝试将结果作为向量获取,但通过制作 void 函数来执行此操作而出现错误
- 需要获取 void 或 int 的 Cpp 模板函子
- 尝试分配函数指针时获取"Void value not ignored as it ought to be"
- 从void指针中获取int,该指针指向一个简短的指针
- 将 map
转换为 void* 并返回并获取密钥 - 在头文件中的函数原型中获取指针数组:函数声明为 void
- *&在这里做什么?如何更改它以获取代码作为 void binaryTree::insert(binaryNode *root,string value)?可能吗?
- 获取 void* 指向 boost::any 内容的指针
- 在将 void 指针转换为结构时获取值时遇到问题
- 如何从main到void获取信息
- GetProcAddress取消闪烁以获取哪种形式的Void pascal Myfunction(BOOL)的地址
- 从返回类型的函数中获取结果'void'而结果变量是输入参数之一 - C++