0

我想在右键单击鼠标调用菜单时添加选项,以通过用户输入更改颜色的值。我试过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;
        }
    }
}
4

1 回答 1

3

据我所知,您需要自己处理。

使用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);
    }
}
  1. glutBitmapCharacter
  2. glutKeyboardFunc
于 2012-06-17T22:44:10.513 回答