Is there any function that lets me specify the 4 points of a bitmap. The skewed drawimage function doesn't work cause I want an effect where the corners can be anywhere.
Printable View
Is there any function that lets me specify the 4 points of a bitmap. The skewed drawimage function doesn't work cause I want an effect where the corners can be anywhere.
I'm not sure if such a function exists in the language that you are using, however many articles regarding texture mapping at www.gamedev.net are relevent to what you want to do.
Let me know if you hit a dead end, or can't find anything helpfull there.
That can easily be done on DirectX and OpenGL. Don't rely on slow and limited functions like DrawImage. http://nehe.gamedev.net (goto OpenGL Tutorials located on the left) and www.gametutorials.com (Click on the tutorials button and pick either OpenGL or DirectX) has plenty of tutorials and source code on DX and OpenGL.
I wanted to do this manually first to get the idea and practice down, then I will use DX to do it for me. I'm having troubles. It seems as if we need to draw the image horizontal line by line, and skiping pixels to give depth and stretching pixels the closer to the camera we are. Am I on the right track?
Yep, that's correct.Quote:
Originally Posted by RickP
Now how does 1 go about doing that? :)
The first think i suggest you get working is being able to fill a triangle with a colour.
To do this you need to arrange the points from lowest Y coord to highest.
Then you need to get the gradient for each edge of the triangle.
Once you've done that you can calculate a scan-line. This is a horizontal line that you can fill in, to draw part of the triangle.
I don't really have time to explain it all but here's how i get the scan-lines:
To begin with just make your renderscanline function loop through each pixel in the line, using the same colour, ust to test whether it works.Code://Order the coordinates correctly
if(y1 < y0)
{
dt = y0; y0 = y1; y1 = dt;
dt = x0; x0 = x1; x1 = dt;
}
if(y2 < y1)
{
dt = y1; y1 = y2; y2 = dt;
dt = x1; x1 = x2; x2 = dt;
}
if(y2 < y0)
{
dt = y0; y0 = y2; y2 = dt;
dt = x0; x0 = x2; x2 = dt;
}
if(y1 < y0)
{
dt = y0; y0 = y1; y1 = dt;
dt = x0; x0 = x1; x1 = dt;
}
dx0 = x1 - x0;
dy0 = y1 - y0;
dx1 = x2 - x1;
dy1 = y2 - y1;
dx2 = x0 - x2;
dy2 = y0 - y2;
//Calculate gradients
if(dy0 != 0)
Gradient0 = dx0 / dy0;
else
Gradient0 = 0;
if(dy1 != 0)
Gradient1 = dx1 / dy1;
else
Gradient1 = 0;
if(dy2 != 0)
Gradient2 = dx2 / dy2;
else
Gradient2 = 0;
double sx,ex;
double id;
if(CurrentMultiFrameNumber == 1)
cout << "Frame #" << FrameNumber << " RENDERING POLYGON" << endl;
//Step through each line in the triangle, working out the scanline, then call the scanline rendering function
for(i = (int) y0; i < y1; i++)
{
id = (double) i;
sx = (x0 + ((id - y0) * Gradient2));
ex = (x0 + ((id - y0) * Gradient0));
if(sx < ex)
RenderScanLine(pImage,Triangle,sx,i,ex - sx, pTexture, AlphaBlend);
else
RenderScanLine(pImage,Triangle,ex,i,sx - ex, pTexture, AlphaBlend);
}
for(i = (int) y1; i < y2; i++)
{
sx = (x0 + ((i - y0) * Gradient2));
ex = (x1 + ((i - y1) * Gradient1));
if(sx < ex)
RenderScanLine(pImage,Triangle,sx,i,ex - sx, pTexture, AlphaBlend);
else
RenderScanLine(pImage,Triangle,ex,i,sx - ex, pTexture, AlphaBlend);
}