Jump to content
  • Advertisement
Sign in to follow this  
Elvis Enmanuel

OpenGL Draw Circles using GL_POINTS

This topic is 4072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been inserted an entry in my blog about drawing circle primitives in openGL using GL_POINTS. If anyone needs... File: circles_with_gl_points.vert //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Circles with GL_POINTS [Vertex shader] //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uniform vec2 windowSize; varying vec3 screenPos; varying float radius; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_PointSize = 20.0; // Convert position to window coordinates vec3 halfsize = vec3(windowSize.x, windowSize.y, 1.0) * 0.5; screenPos = halfsize + ((gl_Position.xyz / gl_Position.w) * halfsize); // Convert radius to window coordinates radius = gl_PointSize * 0.5; } File: circles_with_gl_points.frag //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Circles with GL_POINTS [Fragment shader] //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uniform float alphaLevel; varying vec3 screenPos; varying float radius; void main() { // Sphere shaded if( distance(gl_FragCoord.xy, screenPos.xy) > radius ) discard; gl_FragData[0] = gl_Color; } You can download shader files here at: http://gamedusa.blogspot.com/ ains.

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the post but i guess that your code will be more readable if you put it between [ source ] [ /source ] (remove the spaces) [wink]

Share this post


Link to post
Share on other sites
True :) new version with minor changes

File: circles_with_gl_points.vert

uniform vec4 windowSize;
varying vec2 screenPos;
varying float radius;

void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_PointSize = 20.0;

// Convert position to window coordinates
vec2 halfsize = vec2(windowSize.z * 0.5, windowSize.w * 0.5);
screenPos = windowSize.xy + halfsize +
((gl_Position.xy / gl_Position.w) * halfsize);

radius = gl_PointSize * 0.5;
}


File: circles_with_gl_points.frag

varying vec2 screenPos;
varying float radius;

void main() {
if( distance(gl_FragCoord.xy, screenPos) > radius ) discard;
gl_FragData[0] = gl_Color;
}



ains.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!