44BW_Render::Buffer::Buffer(
unsigned char* buffer_,
int scale_)
53BW_Render::Buffer::~Buffer()
57void BW_Render::Buffer::Set_H_Line(
int start_x,
int end_x,
int y)
59 if (y<minv || y>=maxv || end_x<minv || start_x>=maxv)
return;
60 if (start_x<minv) start_x=minv;
61 if (end_x>=maxv) end_x=maxv-1;
80void BW_Render::Buffer::Fill(
unsigned char c)
89 pixel_buffer(buffer,buffer_scale)
107 float half_scale=pixel_buffer.
Scale()*0.5f;
109 reinterpret_cast<float*
>(vertices),
117static inline bool Cull(
122 float x1=c2[0]-c1[0];
123 float y1=c2[1]-c1[1];
124 float x2=c3[0]-c1[0];
125 float y2=c3[1]-c1[1];
127 if (r<0)
return false;
135 for (
int n=0;n<index_count;++n) {
137 int idx_1=indices[0];
138 int idx_2=indices[1];
139 int idx_3=indices[2];
142 if (Cull(vertices[idx_1],vertices[idx_2],vertices[idx_3])==b)
continue;
144 Vector2 corner_1(vertices[idx_1][0],vertices[idx_1][1]);
145 Vector2 corner_2(vertices[idx_2][0],vertices[idx_2][1]);
146 Vector2 corner_3(vertices[idx_3][0],vertices[idx_3][1]);
150 if (corner_2[1]<corner_1[1])
Swap(corner_1,corner_2);
151 if (corner_3[1]<corner_1[1])
Swap(corner_1,corner_3);
152 if (corner_3[1]<corner_2[1])
Swap(corner_2,corner_3);
155 Vector3 xcf(corner_1[0],corner_2[0],corner_3[0]);
157 Render_Preprocessed_Triangle(xcf,yci);
164 for (
int n=0;n<index_count;++n) {
165 int idx_1=*indices++;
166 int idx_2=*indices++;
167 int idx_3=*indices++;
169 if (Cull(vertices[idx_1],vertices[idx_2],vertices[idx_3]))
continue;
171 Vector2 corner_1(vertices[idx_1][0],vertices[idx_1][1]);
172 Vector2 corner_2(vertices[idx_2][0],vertices[idx_2][1]);
173 Vector2 corner_3(vertices[idx_3][0],vertices[idx_3][1]);
177 if (corner_2[1]<corner_1[1])
Swap(corner_1,corner_2);
178 if (corner_3[1]<corner_1[1])
Swap(corner_1,corner_3);
179 if (corner_3[1]<corner_2[1])
Swap(corner_2,corner_3);
182 Vector3 xcf(corner_1[0],corner_2[0],corner_3[0]);
184 Render_Preprocessed_Triangle(xcf,yci);
188void BW_Render::Render_Preprocessed_Triangle(
Vector3& xcf,
Vector3i& yci)
191 float x_right=x_left;
192 int ycnt=yci[1]-yci[0];
195 float x_step_1=(xcf[1]-xcf[0])/
float(ycnt);
196 float x_step_2=(xcf[2]-xcf[0])/
float(yci[2]-y);
197 if (x_step_1>x_step_2) {
228 float one_per_ycnt=1.0f/float(ycnt);
229 float x_step_1=(xcf[2]-x_left)*one_per_ycnt;
230 float x_step_2=(xcf[2]-x_right)*one_per_ycnt;
Color scale(const Color &a, const Color &b)
WWINLINE void Swap(Vector2 &a, Vector2 &b)
void Render_Triangle_Strip(const unsigned long *indices, int index_count)
void Render_Triangles(const unsigned long *indices, int index_count)
BW_Render(unsigned char *buffer, int scale)
void Set_Vertex_Locations(Vector2 *vertices, int count)
void Fill(unsigned char c)
WWINLINE void Scale(float a, float b)
static void MulAdd(float *dest, float multiplier, float add, int count)
static long Float_To_Long(float f)