sonnendeck

11-16-2007, 10:39 AM

Hallo.

I have some problems with OpenGL. I have to write a program which implements linear interpolation for polygons.

For example: My polygon has 4 vertices and each vertice has another color. I want to interpolate each pixel in the polygon area according to this colors.

My idea is to draw at first the shape of the polygon in red (with white background) and after that i want to read a line with the glReadPixels(), but i don't understand this function exactly. Then i want to find the start and the end point of a line and after that to interpolate each pixel on this line.

Is there a function which tell me, if this pixel is red or not?

Thanks for help.

const GLfloat M = 200;

GLfloat vertices[][2] = { {0.0,M} , {-M,0.0},

{0.0,-2*M} , {2*M,0.0}};

void interpolate()

{

GLfloat xMin = vertices[0][0];

GLfloat yMin = vertices[0][1];

GLfloat xMax = xMin;

GLfloat yMax = yMin;

for(int i=1; i<4; i++)

{

if(xMin >= vertices[i][0])

xMin = vertices[i][0];

else if(xMax >= vertices[i][0])

xMax = vertices[i][0];

if(yMin >= vertices[i][1])

yMin = vertices[i][1];

else if(yMax >= vertices[i][1])

yMax = vertices[i][1];

}

GLint width = (int)(xMax-xMin);

GLint height = (int)(yMax-yMin);

GLint array[(int)(xMax-xMin)][(int)(yMax-yMin)];

glReadBuffer(GL_FRONT_LEFT);

glReadPixels((int)xMin,(int)yMin, width, height, GL_RED, GL_INT, array);

GLint numberOfIntersections = 0;

for(int i=0; i<width; i++)

for(int j=0; j<height; j++)

{

printf("%i\n", array[i][j]);

}

}

I have some problems with OpenGL. I have to write a program which implements linear interpolation for polygons.

For example: My polygon has 4 vertices and each vertice has another color. I want to interpolate each pixel in the polygon area according to this colors.

My idea is to draw at first the shape of the polygon in red (with white background) and after that i want to read a line with the glReadPixels(), but i don't understand this function exactly. Then i want to find the start and the end point of a line and after that to interpolate each pixel on this line.

Is there a function which tell me, if this pixel is red or not?

Thanks for help.

const GLfloat M = 200;

GLfloat vertices[][2] = { {0.0,M} , {-M,0.0},

{0.0,-2*M} , {2*M,0.0}};

void interpolate()

{

GLfloat xMin = vertices[0][0];

GLfloat yMin = vertices[0][1];

GLfloat xMax = xMin;

GLfloat yMax = yMin;

for(int i=1; i<4; i++)

{

if(xMin >= vertices[i][0])

xMin = vertices[i][0];

else if(xMax >= vertices[i][0])

xMax = vertices[i][0];

if(yMin >= vertices[i][1])

yMin = vertices[i][1];

else if(yMax >= vertices[i][1])

yMax = vertices[i][1];

}

GLint width = (int)(xMax-xMin);

GLint height = (int)(yMax-yMin);

GLint array[(int)(xMax-xMin)][(int)(yMax-yMin)];

glReadBuffer(GL_FRONT_LEFT);

glReadPixels((int)xMin,(int)yMin, width, height, GL_RED, GL_INT, array);

GLint numberOfIntersections = 0;

for(int i=0; i<width; i++)

for(int j=0; j<height; j++)

{

printf("%i\n", array[i][j]);

}

}