int RGB_2(float r, float g, float b)
{ glColor3f(r,g,b);
return 1; }
void SetPixel(int x, int y, int r)
{
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
glFlush();
}
int GetPixel (int x, int y)
{
GLubyte pixel[3] ;
glReadPixels(x,y,1,1, GL_RGB ,GL_UNSIGNED_BYTE,(void *)pixel);
return (int)pixel[1];
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height==0) height=1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-width/2,width/2,height/2,-height/2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return TRUE;
}
int DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT );
glEnable(GL_BLEND);
glEnable(GL_SMOOTH);
glLoadIdentity();
SetPixel (0,0, RGB_2(0,0.5,0));
GetPixel (0,0);
return TRUE;
}
Where do you set the color...?
--
<\___/>
/ O O \
\_____/ FTB.
http://www.topaz3d.com/ - New 3D editor for real time simulation
Rositsa Ilova wrote:
> Hello,
> I try to write my own getPixel - get the pixel color and setPixel -
> set the pixel color functions. I draw a green point on white
> background. And a want to get the green color. But I have problem -
> getPixel read background color (white), not the point color. I think I
> make a mess with color buffers. (I know that my getPixel function
> return only one parameter from RGB array). Could you help me please?
> Thanks a lot :)
> Here is part of my code :
>
> int RGB_2(float r, float g, float b)
> { glColor3f(r,g,b);
> return 1; }
>
> void SetPixel(int x, int y, int r)
> {
> glBegin(GL_POINTS);
> glVertex2i(x, y);
> glEnd();
> glFlush();
> }
> int GetPixel (int x, int y)
> {
> GLubyte pixel[3] ;
> glReadPixels(x,y,1,1, GL_RGB ,GL_UNSIGNED_BYTE,(void *)pixel);
> return (int)pixel[1];
> }
glReadPixels() expects window coordinates, while your drawing code uses
the full-blown Render-Pipleline with object coordinates - There is
nothing wrong with this approach, as long as you get the coordinate
transformations right.
> [...]
> glMatrixMode(GL_PROJECTION);
> glLoadIdentity();
> gluOrtho2D(-width/2,width/2,height/2,-height/2);
> glMatrixMode(GL_MODELVIEW);
> glLoadIdentity();
You set up your projection matrix to map (0,0) to the center of the
window, but are reading back the bottom-left corner pixel, so you are
getting your (white) background...
Regards,
Marcel
--
Marcel Heinz | <marcel...@informatik.tu-chemnitz.de> | PGP-KeyID: E78E9442
"Perfection is attained not when there is nothing more to add,
but when there is nothing more to remove." -- Antoine de Saint-Exup�ry
Plus, you are promoting a byte (pixel[1]) to int and returning it.
You want to return all 3 bytes for RGB!
GL_BGR or GL_BGRA may be faster, but be aware that this whole idea is
extremely slow. Think in terms of bulk buffers.
jbw