where it is drawn by a software rasterizer which I have written using active edge list
and drawing every pixel with GL_POINTS in C++/OpenGL.
Now that I managed to implement texture mapping on every face triangle of the
icosahedron by using a checkerboard, which consists of a 2D array containing
color RGB value, I now want to project the texture on every face triangle with a
perspective on it because now the texture on every face triangle is projected flat
on the screen seen in the image 'icotexnotcorrect.png'. I want have a perspective
projection on the texture mapping so that you can see the 3D-depth of the
icosahedron.
This has been described in the Wikipedia article Texture Mapping in the section
'Perspective Correctness' http://en.wikipedia....Texture_mapping and in the
paper 'Fundamentals of Texture Mapping and Image Warping' by Paul Heckbert
http://www.cs.cmu.ed...und/texfund.pdf
Especially in Paul Heckberts paper, he is describing about different kinds of
mapping like Affine, Bilinear and Projective. But I find it very confusing,
there is a lot of transformations he is mentioning from (u,v) space to (x, y) space
it is needed to be done with several unknown element values in a transformation
matrix. I dont know how and where I should implement any of those mapping inside
the code.
I have a 2D array that is representing a red-white checkerboard:
/* Create checkerboard texture */
#define checkImageWidth 2048
#define checkImageHeight 2048
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
void makeCheckImage(void)
{
int i, j;
float c;
for (i = 0; i < checkImageHeight; i++) {
for (j = 0; j < checkImageWidth; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*1.0f;
if(c == 1.0f)
{
checkImage[j][0] = (GLubyte) c; // Red
checkImage[j][1] = (GLubyte) 0.0f; // Green
checkImage[j][2] = (GLubyte) 0.0f; // Blue
}
else
{
checkImage[j][0] = (GLubyte) 1.0f; // Red
checkImage[j][1] = (GLubyte) 1.0f; // Green
checkImage[j][2] = (GLubyte) 1.0f; // Blue
}
checkImage[j][3] = (GLubyte) 1.0f; // Alpha
}
}
}
And here is the code where I am drawing the current face triangle
by using Active Edge List. At the current scanline I am drawing
the pixels along x from the first edge to the second edge of the
face triangle:
for (int k = 0; k < size; k+=2)
{
float currX = intersectVertices.at(k);
float currDZDX = spanVerticesDepth.at(k);
float dz = spanVerticesDepth.at(k+1) - spanVerticesDepth.at(k);
float dx = intersectVertices.at(k+1) - intersectVertices.at(k);
float dzdx = (dz/dx);
while(currX < intersectVertices.at(k+1))
{
if (texture)
{
//The texture mapping
texValueR = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][0];
texValueG = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][1];
texValueB = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][2];
//Sets current texture color
glColor3f(texValueR, texValueG, texValueB);
}
// Draw at the current scanline
if(currDZDX < zbufferdata[(int)currX+1000][(int)scanline+1000])
{
glVertex2f((currX)/1000.0f,
(scanline)/1000.0f);
zbufferdata[(int)currX+1000][(int)scanline+1000] = currDZDX;
}
currX += 1.0f;
currDZDX += dzdx;
}
}
This partial code produces the image that has been attached to this topic.
But how and where should I implement the Perspective Correct Texture Mapping?