What does this error mean?

Jul 31, 2014 at 10:53pm
This is telling me that I have too many variables in glColor3f in my function drawMenu(). I'm getting pretty confused by it, I don't know what I'm doing but I feel like this should work. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include <iostream>
#include <cmath>
using namespace std;

#define WIDTH    	700
#define HEIGHT   	600

#define MENUWIDTH 	100
#define BOXHEIGHT	(HEIGHT/6)

#define NCOLORS 	6

#define RGBRED 		(1, 0, 0)
#define	RGBGREEN	(0, 1, 0)
#define RGBBLUE		(0, 0, 1)
#define RGBYELLOW	(1, 1, 0)
#define RGBMAGENTA	(1, 0, 1)
#define RGBCYAN		(0, 1, 1)

#define RGBWHITE	(1, 1, 1)

#define R		0
#define G		1
#define B		2
#define Y		3
#define M		4
#define C		5

static float colormenu[][6] = {{RGBRED}, {RGBGREEN}, {RGBBLUE}, {RGBYELLOW}, {RGBMAGENTA}, {RGBCYAN}};

int incolormenu(int x, int y) 
{

  return (x >= 0 && x <= MENUWIDTH && y >= 0 && y <= HEIGHT);
}

int colormenuindex(int x, int y) 
{

  if(!incolormenu(x, y))
    return -1;
  else
    return(y / BOXHEIGHT);
}

void handleButton(int button, int state, int x, int y)
{
  
  static int menuindex = -1;

  y = HEIGHT - y;

  if(button != GLUT_LEFT_BUTTON)
    return;

  if(state == GLUT_DOWN)
  {
    if(incolormenu(x, y))
      menuindex = colormenuindex(x, y);
  }
  else
  {
    if(incolormenu(x, y) && colormenuindex(x, y) == menuindex)
    {
      glColor3f(colormenu[menuindex][R], colormenu[menuindex][G], colormenu[menuindex][B], colormenu[menuindex][C], colormenu[menuindex][M], colormenu[menuindex][Y]);
      glRecti(MENUWIDTH, 0, WIDTH, HEIGHT);
    }
    
    glFlush();
  }
}

void drawMenu() 
{

  int i;

  glClear(GL_COLOR_BUFFER_BIT);

  for(i = 0; i < NCOLORS; i++)
  {
    glColor3f(colormenu[i][R], colormenu[i][G], colormenu[i][B], colormenu[i][C], colormenu[i][M], colormenu[i][Y]);
    glRecti(1, BOXHEIGHT * i + 1, MENUWIDTH - 1, BOXHEIGHT * (i + 1) - 1);
  }
  
  glFlush();
}

int main(int argc, char* argv[]) 
{
  glutInit(&argc, argv);

  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
  glutInitWindowSize(WIDTH, HEIGHT);
  glutCreateWindow("Color Menu");
  gluOrtho2D(0, WIDTH, 0, HEIGHT);

  glutDisplayFunc(drawMenu);
  glutMouseFunc(handleButton);
   
  glClearColor(RGBWHITE, 1, 1, 1);

  glutMainLoop();

  return 0;
}
Jul 31, 2014 at 10:54pm
Looks like glColor3f() takes in 3 arguments.
You're providing 6 at line 86.

The Internet wrote:
glColor3f() takes 3 arguments: the red, green and blue components of the color you want
Last edited on Jul 31, 2014 at 10:56pm
Jul 31, 2014 at 10:56pm
But how can I make it take six? I definitely need six.
Jul 31, 2014 at 11:07pm
RGB is one color model. CMY is another. You shouldn't need both at once, what exactly you're trying to do?

To convert from RGB to CMY (subtractive), the conversion is
(C, M, Y) = (1 − R, 1 − G, 1 − B )
Last edited on Jul 31, 2014 at 11:07pm
Jul 31, 2014 at 11:07pm
You can't. It only takes 3.

Colors in computer graphics are [usually] represented with Red/Green/Blue components. If you have colors in some other form, you'll have to convert them to RGB yourself before giving the color to OpenGL.
Jul 31, 2014 at 11:14pm
I'm trying to make a little "sketch" program and this is the first part of it. I'm just trying to get six colors to appear on the side of the "canvas" so that I can click it and change the color of the canvas How do I do that? I want those colors to be red, green, blue, cyan, magenta, and yellow.
Topic archived. No new replies allowed.