Im trying to render a model with anialiasing using OpenGL and SDL, but when I do I get strange artifacts.
When I render with antialiasing disabled everything looks fine.
When antialiasing is enabled I get white dots in edges of the model.

I'm using a Nvidia Geforce 320M graphics card and enabling the display as well as the multisampling with this code
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
glEnable(GL_MULTISAMPLE);
This is the fragment shader:
#version 330
#define MAX_NUM_LIGHTS 4
in vec3 normal0;
in vec3 pos;
out vec4 FragColor;
struct LightSource
{
vec4 position;
vec4 ambientColor;
vec4 diffuseColor;
vec4 specularColor;
// attenuation parameters
float attConstant;
float attLinear;
float attQuadratic;
};
struct Material
{
vec4 ambientColor;
vec4 diffuseColor;
vec4 specularColor;
float shininess;
};
uniform LightSource light[MAX_NUM_LIGHTS];
uniform Material material;
uniform vec3 viewPos;
uniform int numOfLights;
// function declarations
vec4 calcDirLight(LightSource light, Material material, vec3 normal, vec3 viewDirection);
vec4 calcPointLight(LightSource light, Material material, vec3 normal, vec3 fragPos, vec3 viewDirection);
void main()
{
vec3 viewDirection = normalize( viewPos - pos );
vec4 result = vec4(0.0f);
// Loop over all lights
for(int i = 0; i < numOfLights; i++)
{
// Directional light
if( light[i].position.w == 0.0f )
{
result += calcDirLight( light[i], material, normal0, viewDirection);
}
// Point light
else if ( light[i].position.w == 1.0f )
{
result += calcPointLight( light[i], material, normal0, pos, viewDirection);
}
}
FragColor = result;
}
vec4 calcDirLight(LightSource light, Material material, vec3 normal, vec3 viewDirection)
{
// Properties
vec3 lightDirection = normalize( vec3(light.position) );
vec3 reflectDirection = reflect( -lightDirection, normal);
// Ambient component
vec4 ambientComponent = light.ambientColor * material.ambientColor;
// Diffuse component
float diffuseReflection = clamp(dot(normal,lightDirection), 0.0, 1.0);
vec4 diffuseComponent = diffuseReflection * light.diffuseColor * material.diffuseColor;
// Specular component
float specularReflection = pow( max( dot( viewDirection,reflectDirection ), 0.0 ), material.shininess );
vec4 specularComponent = specularReflection * light.specularColor * material.specularColor;
return ( ambientComponent + diffuseComponent + specularComponent);
}
vec4 calcPointLight(LightSource light, Material material, vec3 normal, vec3 fragPos, vec3 viewDirection)
{
// Properties
vec3 lightDirection = normalize( vec3(light.position) - fragPos );
vec3 reflectDirection = reflect( -lightDirection, normal);
float distance = length( vec3(light.position) - fragPos );
float attenuation = 1.0f / ( light.attConstant + (light.attLinear * distance) + (light.attQuadratic * (distance * distance)) );
// Ambient component
vec4 ambientComponent = light.ambientColor * material.ambientColor * attenuation;
// Diffuse component
float diffuseReflection = clamp(dot(normal,lightDirection), 0.0, 1.0);
vec4 diffuseComponent = diffuseReflection * light.diffuseColor * material.diffuseColor * attenuation;
// Specular component
float specularReflection = pow( max( dot( viewDirection,reflectDirection ), 0.0 ), material.shininess );
vec4 specularComponent = specularReflection * light.specularColor * material.specularColor * attenuation;
return ( ambientComponent + diffuseComponent + specularComponent);
}
Can anyone point me in the direction of what might be the problem?