I am trying to draw new shapes by setting the buffer for each pixel and the corresponding values for each pixel i.e red,green,alpha.blue.
but to my dismay i have been noticing many times that always few pixels miss in the shapes…
can anyone provide the reason for this…
Following are the code snipets:-
i
nt DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT); // Clear Screen And Depth Buffer
float varray[]={0.0,-200.0,-50.0,50,-40,-50};
p1=MyCalculations(20,0,-20);
p2=MyCalculations(20,40,-40);
p3=MyCalculations(-20,40,-40);
p4=MyCalculations(-20,0,-20);
p5=MyCalculations(0,80,-30);
//new Vertices(varray);
Draw_Line(p1,p5);
Draw_Line(p2,p5);
Draw_Line(p3,p5);
Draw_Line(p4,p5);
Draw_Line(p1,p2);
Draw_Line(p2,p3);
Draw_Line(p3,p4);
Draw_Line(p4,p1);
DrawBuffer *obj= new DrawBuffer((int)screenWidth,(int)screenHeight,colourbuffer);
obj->Draw();
return TRUE;
}
//Drawline function
void Draw_Line(point p1,point p2)
{
point pl=(p1.x<p2.x?p1:p2);
point pr=(p1.x>p2.x?p1:p2);
float m=(pr.y-pl.y)/(pr.x-pl.x);
int k=0;
for(k=pl.x;k<pr.x;k++)
{
int y=pl.y+(m*(k-pl.x));
colourbuffer[(int)(y*screenWidth + k)*4 + 0]=1;
colourbuffer[(int)(y*screenWidth + k)*4 + 1]=0;
colourbuffer[(int)(y*screenWidth + k)*4 + 2]=1;
colourbuffer[(int)(y*screenWidth + k)*4 + 3]=1;
}
}
//Drawbufferfunction
void DrawBuffer::Draw()
{
int SCREEN_WIDTH = _screenWidth;
int SCREEN_HEIGHT = _screenHeight;
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(int y=0;y<_screenHeight;y++)
{
for(int x=0;x<_screenWidth;x++)
{
unsigned char r = 255*_colorBuffer[ (y*SCREEN_WIDTH + x)*4 + 0];
unsigned char g = 255*_colorBuffer[ (y*SCREEN_WIDTH + x)*4 + 1];
unsigned char b = 255*_colorBuffer[ (y*SCREEN_WIDTH + x)*4 + 2];
unsigned char a = 255*_colorBuffer[ (y*SCREEN_WIDTH + x)*4 + 3];
if(b == 0)
{
int c = 10;
}
glColor4ub(r,g,b,a);
glVertex2i(x,y);
}
}