#include "GL/glut.h" #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define TEXSIZE 64 static GLfloat buf1[3]; // Buffers for reading screen static GLfloat *rgbRasPosTexture; static GLuint texImages; static GLfloat mMap[] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, }; static GLfloat mScale[] = { 1.0/64.0, 0.0, 0.0, 0.0, 0.0, 1.0/64.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, }; #define RASPOSX (22) #define RASPOSY (36) static void CreateRasterPosTexture(void) { GLint x, y; GLfloat *prgb = rgbRasPosTexture; for (y = 0; y < TEXSIZE; y++) { for (x = 0; x < TEXSIZE; x++) { if ((x == RASPOSX)&&(y == 0)) { *prgb++ = 0.0; *prgb++ = 1.0; *prgb++ = 0.0; } else if ((x == RASPOSX)&&(y == RASPOSY)) { *prgb++ = 1.0; *prgb++ = 0.0; *prgb++ = 0.0; } else { *prgb++ = 0.0; *prgb++ = 0.0; *prgb++ = 1.0; } } } } void init() { glDisable(GL_DITHER); glClearColor (0.0, 0.0, 0.0, 0.0); // Allocate memory for creating the ramp tecture rgbRasPosTexture = (GLfloat *)malloc(TEXSIZE*TEXSIZE*3*sizeof(GLfloat)); glGenTextures(1, &texImages); glBindTexture (GL_TEXTURE_2D, texImages); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); CreateRasterPosTexture (); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0, GL_RGB, GL_FLOAT, rgbRasPosTexture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glEnable (GL_TEXTURE_2D); glMatrixMode (GL_TEXTURE); glLoadIdentity (); glLoadMatrixf (mScale); glMultMatrixf (mMap); } long Test (GLint x1, GLint y1) { glReadPixels(x1, y1, 1, 1, GL_RGB, GL_FLOAT, buf1); printf ("pixel color: %f %f %f\n", buf1[0], buf1[1], buf1[2]); return 0; } #define X1 4 #define Y1 4 void test(){ GLubyte bitmap[] = {0xFF}; glClear (GL_COLOR_BUFFER_BIT); glNewList (1, GL_COMPILE_AND_EXECUTE); // glNewList (1, GL_COMPILE); glBindTexture (GL_TEXTURE_2D, texImages); glTexCoord1d (22.0); glRasterPos2f (X1 + 0.25, Y1 + 0.25); glBitmap (1, 1, 0.0, 0.0, 0.0, 0.0, bitmap); glEndList(); // glCallList(1); Test (X1, Y1); } void display() { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEY, 0, WINDSIZEX); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init(); glutDisplayFunc(display); glutMainLoop(); }