如何在"glutCreateMenu"上添加用户输入
How to add user input on a "glutCreateMenu"
我想在用鼠标右键单击调用菜单以通过用户输入更改颜色值时添加选项。我试过cin>> RED1;
但它无法识别cin
.
我不知道如何完成这项工作,除非给出一个固定的值来改变颜色。 如何实现用户对此案例的输入?
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#define _USE_MATH_DEFINES
#include <cmath>
#include <gl/glut.h>
GLfloat angle = 0.0;
static int RED1 = 1, GREEN1 = 3, BLUE1 = 0, RED2 = 2, GREEN2 = 2, BLUE2 = 1;
static int MENUsub, Face1, Face2, i, LINES;
static int SELECIONA = 2, f = 0, VALOR = 0, SOLID = 0, LINE = 1;
static double NoFaces = 32, ihc, cordX = 1, cordY = 1, cordZ = 1;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void creatMENU(void)
{
Face1 = glutCreateMenu(MENU);
glutAddMenuEntry("Change Colour Values", 1);
MENUsub = glutCreateMenu(MENU);
glutAddSubMenu("Face 1", Face1);
glutAddMenuEntry("Sair", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
void MENU (int OPT)
{
if(OPT == 0)
{
exit(0);
}
else
{
switch(OPT);
{
case 1 :
//cin>> RED1;
RED1 = 2;
break;
}
}
}
据我所知,你需要自己处理。
使用glutKeyboardFunc
获取键盘输入,并使用glutBitmapCharater
将文本打印到窗口。
因此,您可以保留一个全局布尔值changingColor
当选择菜单项时,您可以切换到true
。然后,您可以使用矩形或其他东西呈现输入。您的键盘功能可能看起来有点像这样:
std::string colorInput;
void keyboard(unsigned char key, int x, int y) {
if (changingColor) {
colorInput += key;
}
}
在你的渲染函数中,类似于:
if (changingColor) {
glRasterPos3f(x, y, z);
for (auto it = colorInput.begin(); it != colorInput.end(); ++it) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *it);
}
}
- 贪吃位图字符
- 贪吃键盘功能
相关文章:
- 如何在 c++ 中交替添加和减去用户输入
- 即使在多任务处理时,添加用户时间 + 系统时间(来自 shell 的时间命令)是否是一种可靠的措施?
- 如何从用户那里接收多个字符串并将这些字符串添加到 c++ 中的数组中?
- 如何将用户下载的标头文件添加到系统中默认情况下的标题文件列表
- 我想添加两个字符串类型的矩阵.用户将不会输入行数或列的数量.用户将仅输入数组
- C++ 如何将用户控件添加到窗体,以便我可以在面板之间转换
- 自动将"Additional include directory"添加到静态库的用户
- 如何在移动列表视图中添加滚动条?并且用户只能垂直滚动特定区域
- 根据用户输入的每个字母添加到数组索引
- C 在用户输入上添加多个变量
- 使用结构显示军事时间,并将一秒钟的时间添加到用户输入(C )中
- C++基本的转换,然后添加用户输入
- 我在C++从函数中的用户获取输入、添加到数组和打印该数组时遇到问题
- 在回调(CPXcutcallbackadd)中添加用户剪切后,如何编写问题公式(CPXwriteprob)
- 如何让用户在数组中添加和删除"slots"?
- 如何创建一个向量,用户可以在菜单更改之间继续添加值
- 向图像查看器插件添加用户界面
- 如何在"glutCreateMenu"上添加用户输入
- 在Mac OS X上共享一个c++库,这样我就可以在mySQL中添加用户定义的函数
- 为新类型的迭代器添加用户定义的迭代器标记的推荐方法是什么?