PDA

View Full Version : How to define Point Size in openGL ?



Disney
07-07-2009, 05:08 PM
Following does not work:

glBegin(GL_POINTS);
glPointSize(0.2);
glVertex3f(-5,0,0);
glPointSize(2.0);
glVertex3f(-5,4,0);
glPointSize(26.8);
glVertex3f(-5,8,0);
glPointSize(48);
glVertex3f(-5,-4,0);
glPointSize(4);
glVertex3f(-5,-8,0);
glPointSize(0.6);
glVertex3f(-5,14,0);
glEnd();

This code draws points each with the same size. I changed and try this same code with many different values (big/small integers/floats) , but it always draws all points with the same size. Questions at that point: What does glPointSize do ? It propably not changes the point size. What is wrong in my code? How can I draw points with different sizes ?

MaxH
07-07-2009, 06:09 PM
Read the manual for glBegin. You'll see that there are only a few commands that can be called between glBegin and glEnd. glPointSize is not one of them. If you must use GL_POINTS to draw your dots, then you'll have to call glBegin and glEnd for every dot, with glPointSize called before each glBegin.

Disney
07-08-2009, 01:46 PM
ok, thx for your helpful answer. Now, it works, but one more question. Are you sure that I have to write glBegin and glEnd for each points ? Because I use GL_POINTS in glBegin , which means plural. It does not make much sense to me if I have each time to write glBegin and glEnd.

Is there any other opportunities to draw a filled sphere by a given 3d points and a radius r ?

What I do is , there is a set of 3d points which are connected with edges. I want the nodes to be drawn (where I use GL_POINTS at the moment), but the graph is 3d and rotatable by mouse. If I rotate them , the GL_POINTS do not look very fine. Would it be better to draw a sphere with some radius ? Or any other solutions for that ?

(I am new to OpenGL and to C++)

dletozeun
07-08-2009, 02:00 PM
Are you sure that I have to write glBegin and glEnd for each points ? Because I use GL_POINTS in glBegin , which means plural. It does not make much sense to me if I have each time to write glBegin and glEnd.


You can define as many points as you want between glBegin/glEnd calls. In your case it is possible because you call glPointSize for each point and it is invalid operation between glBegin and glEnd calls.
See errors in glPointSize man page (http://www.opengl.org/sdk/docs/man/xhtml/glPointSize.xml).

Disney
07-08-2009, 02:07 PM
ok thanks. Actuall I only need one and the same size, so I use glPointSize out of glBegin and it works now. My question was more for demonstration how to manage to draw points with different pointsize. At the moment I only need the same pointsize , but later I might need to draw different size. In this case I will use as many glBegin and glEnds as I need points with different size , right ?

MaxH
07-08-2009, 03:43 PM
I only need one and the same size, so I use glPointSize out of glBegin and it works now. My question was more for demonstration how to manage to draw points with different pointsize. At the moment I only need the same pointsize, but later I might need to draw different size. In this case I will use as many glBegin and glEnds as I need points with different size, right? That's correct. This is exactly what I do to display star fields. I put 7,000 stars into 6 bins by magnitude (brightness). Each bin is displayed as a set of points between a glBegin-glEnd pair, preceeded by a PointSize command.

scratt
07-08-2009, 07:46 PM
Some other methods are to use GL_POINT_DISTANCE_ATTENTUATION, or use the gl_PointSize command in a vertex shader which has access to an array of point sizes, or calculates them procedurally.

http://www.opengl.org/sdk/docs/man/xhtml/glPointParameter.xml