Ich habe gerade mit OpenGL ich begann ein Programm für die Grenze füllen Algorithmus, ich verwendete glClearColor
, um die Hintergrundfarbe zu rot ändern, aber wenn ich eine Pixelfarbe mit glReadPixels
lesen gibt es RGB-Wert 0,0,0 statt 1 0,0,Wie funktioniert glReadPixels?
#include<stdio.h>
#include<math.h>
#include<GL/glut.h>
#include<GL/freeglut.h>
int WIDTH=500,HEIGHT=500;
void boundaryfill(int x, int y)
{
int pixel[4];
glReadPixels(x,y,1,1, GL_RGB, GL_FLOAT, &pixel);
printf("%f %f %f %f\n",pixel[0],pixel[1],pixel[2],pixel[4]);
if(pixel[0]==(float)1 && pixel[1]==(float)0 && pixel[2]==(float)0)
{
printf("njerngwneroingoierngoineriongioerngiernogineiorngoiern");
}
else
{
glBegin(GL_POINTS);
glColor3f(0,1,0);
glVertex2i(x,y);
glEnd();
glFlush();
//boundaryfill(x,y+1);
//boundaryfill(x+1,y);
//boundaryfill(x,y-1);
//boundaryfill(x-1,y);
}
}
void display()
{
glClearColor(1.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2i(250,250);
glVertex2i(-250,250);
glVertex2i(-250,-250);
glVertex2i(250,-250);
glEnd();
boundaryfill(250,250);
glFlush();
}
void myinit_func()
{
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
gluOrtho2D(-250,250,-250,250);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(WIDTH,HEIGHT);
glutCreateWindow("Boundary fill");
myinit_func();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Ich glaube GLUT sollte das Ansichtsfenster für Sie bei der Erstellung festlegen, aber haben Sie versucht, es nach der Fenstererstellung manuell einzustellen? – SporreKing