I have included the following file which does not include gl.h or glu.h
I have included the following file which uses neither GL.h nor GLU.h, but I can run and comiple it in my machine.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <vector>
using namespace std;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10, 10, -10, 10, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glScalef(5,5,5);
glBegin(GL_QUADS);
glColor3ub(255,0,0);
glVertex2f(-1,-1);
glColor3ub(0,255,0);
glVertex2f(1,-1);
glColor3ub(0,0,255);
glVertex2f(1,1);
glColor3ub(255,255,255);
glVertex2f(-1,1);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int win_w = 0;
int win_h = 0;
void reshape(int w, int h)
{
win_w = w;
win_h = h;
glViewport(0, 0, w, h);
}
void mouse( int x, int y )
{
// 4 bytes per pixel (RGBA), 1x1 bitmap
std::vector< unsigned char > pixels( 1 * 1 * 4 );
glReadPixels( x, win_h - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0] );
cout << "r: " << (int)pixels[0] << endl;
cout << "g: " << (int)pixels[1] << endl;
cout << "b: " << (int)pixels[2] << endl;
cout << "a: " << (int)pixels[3] << endl;
cout << endl;
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow("glReadPixels()");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutPassiveMotionFunc(mouse);
glutMainLoop();
return 0;
}