filling triangles with bresenham's line algorithm to implement z-buffer
I guess I'm curious why you can't just draw it into the depth buffer by disabling the color buffer when you draw the triangle. If you are manually implementing a depth buffer then that isn't an option, but if it does apply then it seems worthwhile to state the simple solution.
Polygon Scan Converting.
Read that (and look around the site and check out the other articles).
John B
Read that (and look around the site and check out the other articles).
John B
I dont understand your code. what if the slope is not an integer value? you cant use integers for your slopes. unless you impliment an error term to keep track how far off the line you are(like bresenham/midpoint method).
Tim
Tim
@JohnBSmall's post
There are many ways to rasterize a triangle, it may be worth to check out
the DirectX rules for that (the SDK will have that at "Triangle Rasterization Rules".
Also, indeed, why is the normal Z-buffer not allowed in your project?
All but the oldest cards support z-buffer, and I do mean OLD.
There are many ways to rasterize a triangle, it may be worth to check out
the DirectX rules for that (the SDK will have that at "Triangle Rasterization Rules".
Also, indeed, why is the normal Z-buffer not allowed in your project?
All but the oldest cards support z-buffer, and I do mean OLD.
Quote:I dont understand your code. what if the slope is not an integer value?
int x0=50;int y0=50;int x1=600;int y1=200;int x2=300;int y2=400;float xleft=x0;float xright=x0;float dxleft = abs(x2-x0)/(y2-y0);float dxright = abs(x1-x0)/(y1-y0);int y,x;for (y=y0; y<=y1; y++){ for (x=xleft;x<=xright;x++) {putpixel(bmp,x,y,color);}xleft += dxleft;xright += dxright;}dxright = abs(x2-x1)/(y2-y1);for (y=y1; y<=y2; y++){ for (x=xleft;x<=xright;x++) {putpixel(bmp,x,y,color);}xleft += dxleft;xright += dxright;}}
Quote:Also, indeed, why is the normal Z-buffer not allowed in your project?
It is allowed, thats what i'm trying to do.
Is there a point in putting the the x,y value of each point of the segmant in an array and then drawing it?
Now this is cool.
If you want to draw textured triangles with z-buffer and using directx you DO NOT NEED to put pixels yourself. Just use Direct3D and the simplest DirectX tutorial that comes with the DirectX SDK.
On the other hand, if you are writing your own renderer (for use on systems that don't have a 3D video card, for example), then you need a custom Z-Buffer, hand written.
Now, back to the important question, what are the exact terms of your project/assigment?
If you want to draw textured triangles with z-buffer and using directx you DO NOT NEED to put pixels yourself. Just use Direct3D and the simplest DirectX tutorial that comes with the DirectX SDK.
On the other hand, if you are writing your own renderer (for use on systems that don't have a 3D video card, for example), then you need a custom Z-Buffer, hand written.
Now, back to the important question, what are the exact terms of your project/assigment?
NO DirectX. NO Direct3D. NO OpenGL. etc.
I want Z-buffer? I find out how it works and write one. And thats what i'm doing. [smile]
I want Z-buffer? I find out how it works and write one. And thats what i'm doing. [smile]
ok, then you have your answer,
scanline with floats.
Interpolation for x values.
Good luck with your idea.
scanline with floats.
Interpolation for x values.
Good luck with your idea.
Use a variation of the Bresenham algorithm that does dz/dx in addition to dy/dx, keeping in mind that the triangle exists in 3D. For any pixel (x,y), you do a depth check and if the new pixel is closer than the old pixel you write the color to the frame buffer and the z-value to the depth buffer.
@zipster
I don't think it's such a great idea to use integer steps...
Overlapping triangles, z-buffer and integers don't really mix.
For z axis he should really use floating/fixed point interpolation.
I don't think it's such a great idea to use integer steps...
Overlapping triangles, z-buffer and integers don't really mix.
For z axis he should really use floating/fixed point interpolation.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement