Hello guys,
I have been trying to solve this problem for a few days now.
I came across texture mapping as a way out to make the circles smooth. But I am not sure if I am doing it correctly. I generated a texture in an array with white colored pixels and used it. The code is below
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
/***************************************/
void create_texture(void)
{
width = 128;
height = 128;
texture_data = (unsigned char *)malloc( width * height * 3 );
for(int i = 0 ; i < width * height * 3 ; i++)
{
texture_data[i] = 0Xff;
}
}
/*****************************************/
Then in the init() function I wrote the following
//Function that creates the white color texture to be used in smoothing the circle boundary
create_texture();
//Initialize the 2D texture parameters
// allocate a texture name
glGenTextures( 1, &texture );
// select our current texture
glBindTexture( GL_TEXTURE_2D , texture );
// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
// when texture area is large, bilinear filter the original
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// the texture wraps over at the edges (repeat)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glNewList(texture = glGenLists(1),GL_COMPILE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_data); //check these parrameters
glEndList();
free(texture_data);
/*************************************/
void drawCircle(float radius)
{
double k;
float x , y;
glLineWidth(0.05);
glEnable(GL_TEXTURE_2D);
glCallList(texture);
glBegin(GL_LINE_LOOP);
for ( k=0; k <= 360.0;)
{
float degInRad = k*DEG2RAD;
x = cos(degInRad)*radius;
y = sin(degInRad)*radius;
glTexCoord2f(0.5,0.5);
glVertex2f(x,y);
k = k + 5;
}
glEnd();
glDisable(GL_TEXTURE_2D);
glLineWidth(1.5);
}
[/QUOTE]</div>
This is the code which I use to smooth the circles. But somehow I am not getting the smooth edges. Kindly help me…
Thanks
ATN