Hi, im new in this forum and new in openGL. i’m from germany and my english isn’t well. but i’ trying it as well as i can
My first goals in openGL are screensavers. Quick and you see something at first i wrote some “traces of fishes” … nice colors, nice rotations und nice moves. but the problem i have is the antialiasing. it works, but it doesn’t work. sounds paradoxical, but so it is …
the aa only works in context of the background. if there on the background other lines in color, the aa calculates still in context of the background.
i have a picture, but i can’t upload it anywhere
to explain the construction:
BACKGROUND
LINE
AND THEN A LINE OVER THE FIRST LINE
on the interceptpoint, the aa isn’t to the color of the first line, but to the backgound. this don’t looks well …
//I need to say, the code is quick and dirty ... thats only for playing
//The mother in this case is a point, who moves on x, y, and z-achsis
//like a ping/pong (Think at mystify in 2D, but here in 3D)
//In every pass of the infinity-loop, the mother ist on the next step and
//150 of this childfishes follow the mother
//the length of the traces are 300
void CChildFish::Paint(CCoord mother)
{
//This is the calculting of the mov of the childfish
//with acceleration und velocity fpr smoothed moves
//every fish has another accelertation an max-velocity
//so the fishswarm-move ist realy naturell
//you see, there are many many lines in every way
if(mother.GetX() > m_Coord[pos].GetX())
{
m_VX += m_A;
if(m_VX > m_MaxV)
{
m_VX = m_MaxV;
}
}
else if(mother.GetX() < m_Coord[pos].GetX())
{
m_VX -= m_A;
if(m_VX < -m_MaxV)
{
m_VX = -m_MaxV;
}
}
if(mother.GetY() > m_Coord[pos].GetY())
{
m_VY += m_A;
if(m_VY > m_MaxV)
{
m_VY = m_MaxV;
}
}
else if(mother.GetY() < m_Coord[pos].GetY())
{
m_VY -= m_A;
if(m_VY < -m_MaxV)
{
m_VY = -m_MaxV;
}
}
if(mother.GetZ() > m_Coord[pos].GetZ())
{
m_VZ += m_A;
if(m_VZ > m_MaxV)
{
m_VZ = m_MaxV;
}
}
else if(mother.GetZ() < m_Coord[pos].GetZ())
{
m_VZ -= m_A;
if(m_VZ < -m_MaxV)
{
m_VZ = -m_MaxV;
}
}
int posMem = pos;
pos++;
if(pos >= length)
{
pos = 0;
}
m_Coord[pos].SetX(m_Coord[posMem].GetX() + m_VX);
m_Coord[pos].SetY(m_Coord[posMem].GetY() + m_VY);
m_Coord[pos].SetZ(m_Coord[posMem].GetZ() + m_VZ);
float x = 0;
float y = 0;
float z = 0;
glBegin( GL_LINE_STRIP );
//This is only for blending in and out the strips/traces of fishes
float length2 = length / 2;
for(int i = 0; i < length; i++)
{
//this is nessecary, to begin and end at the right point in the array
//the pos moves in every step, so i need to begin at over poses
int currentPos = pos - i;
if(currentPos < 0)
{
currentPos += length;
}
x = m_Coord[currentPos].GetX();
y = m_Coord[currentPos].GetY();
z = m_Coord[currentPos].GetZ();
//This is only for blending in and out the strips/traces of fishes
float transparency = ((float)((length2 - abs(length2-i))/length))*5;
if(transparency > 1.0)
{
transparency = 1.0;
}
transparency *= 0.4;
//This color works fine, believe me :)
glColor4f((x+1000)/2000, (y+1000)/2000, (z+1000)/2000, transparency);
//This you need at the beginning
if(x != -9999)
{
//Here, the lines
//they are everywhere and in everey direction
glVertex3f(x, y, z);
}
}
glEnd();
}
Yes, you use GL_LINE_SMOOTH. This function doesn’t really give you “antialiasing” (although the documentation claims so). It’s something a bit different (and IMO useless). If you want proper antialiasing, you need to create a multisampled backbuffer.
The Problem is the order of paint the lines. if the first line you draw is closer then the next line, the aliasing did not work fine. but if the second line is closer to you, it works.
i have tried the multisample backbuffer … i tried at first the sample, which is on the page. but the pc didn’t show any aa? so i cancel the try.
is there in opengl an order, where you can push all the thinks you want to draw, then opengl calculates the distances in dependence to your rotation an draws in order far away to near?
No, GPUs are not capable to cache and sort things for you. This is a major pain especially for proper transparency.
However antialiasing using a multisampled backbuffer does work without a proper rendering-order, ie. it does not matter in which order you render your lines.