私が書いているプログラムの OpenGL でカラー ピッカーを作成しようとしています。「変数またはフィールド 'glReadPixels' は void を宣言しました」というエラーが表示され続けますが、調査しましたが、エラーの意味を見つけることができず、修正が困難です。
#ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
#endif
#include <iostream>
#include <cmath>
using namespace std;
#define WIDTH 750
#define HEIGHT 750
int i=0,mousex, mousey;
unsigned char pick[3];
float A = pick[0]/255;
float B = pick[1]/255;
float C = pick[2]/255;
bool mouseleftdown = false;
void hex(void){
glBegin(GL_POLYGON);
glColor3f(1,0,0); //red
glVertex2f(0, 2); //top
glColor3f(1,.38,.01); //orange
glVertex2f(2, 1); //top right
glColor3f(1,1,0); //yellow
glVertex2f(2, -1); //bottom right
glColor3f(0,1,0); //green
glVertex2f(0, -2); //bottom
glColor3f(0,0,1); //blue
glVertex2f(-2, -1); //bottom left
glColor3f(.8,0,.8); //purple
glVertex2f(-2, 1); //top left
glEnd();
glEnd();
}
void square(void){
glBegin(GL_POLYGON);
glVertex2i(1, -1);
glVertex2i(1, 1);
glVertex2i(-1, 1);
glVertex2i(-1, -1);
glEnd();
}
void mouse(int button, int state, int x, int y){
// Save the left button state
if (button == GLUT_LEFT_BUTTON)
{
mouseleftdown = (state == GLUT_DOWN);
glutPostRedisplay(); // Left button has changed; redisplay!
}
// Save the mouse position
mousex = x;
mousey = y;
}
void glReadPixels(mousex , mousey , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , pick);
void draw(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glColor3f(A,B,C);
glScalef(750,750,1);
square();
glPopMatrix();
glPushMatrix();
glScalef(20,20,1);
hex();
glPopMatrix();
glFlush();
}
void my_init(void){
glClearColor(0, 0, 0, 0); //sets clear color
glLineWidth(4);
gluOrtho2D(-100, 100, -100, 100); //sets origin
}
int main(int argc, char* argv[ ]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Color Picker");
glutDisplayFunc(draw);
glutMouseFunc(mouse);
my_init();
glClearColor(1, 1, 1, 0);
glutMainLoop(); //listens for events
return 0;
}