Sign in to follow this  
zerony

[Solved][NEWBIE]How to get a round point, not square?

Recommended Posts

zerony    122
I already read this thread, http://www.gamedev.net/community/forums/topic.asp?topic_id=333237 but I am not lucky, I can not figure out how I can get a round point with a big glPointSize(5). Here is another piece of code: glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_NOTEQUAL, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glPointSize( 5.0); glColor4f(1.0, 1.0, 0.0, 1.0); for (int i=0; i < dotCount; i++) { glBegin(GL_POINTS); glVertex2f(dot[i].x, dot[i].y); glEnd(); } glColor4f(1.0, 1.0, 1.0, 1.0); glDisable(GL_POINT_SMOOTH); glBlendFunc(GL_NONE, GL_NONE); glDisable(GL_BLEND); I get from http://paste.lisp.org/display/40834. The point is still square, not round. How can I fix the problem? Thanks. [Edited by - zerony on November 8, 2007 1:33:26 PM]

Share this post


Link to post
Share on other sites
swiftcoder    18432
Quote:
Original post by zerony
The point is still square, not round.
How can I fix the problem? Thanks.


Points are square, no way around that. You can however apply a texture to the point, and if your texture has an alpha channel, and you have blending setup, you can apply whatever shape you want to the point (i.e. the shape represented by the alpha channel).

Share this post


Link to post
Share on other sites
ramearess    158
To my knowledge there is no such thing as curves in OpenGL if you want something to appear round you have to make it out of small squares, the same way you have to make a circle out of lots of straight lines.

If you want a round dot try GL_POLYGON


#include <cmath.h> //may be <cmath>
#include <gl/gl.h>

//nov = number of vertex
//r = radius
void Dot(int nov, float r){

if (nov < 4) nov = 4;
if (nov > 360) nov = 360;

float angle = (360/nov)*(3.142159/180);
float x[360] = 0, y[360] = 0;

for (int i = 0; i < nov; i++){
x[i] = cosf(r*cosf(i*angle);
y[i] = sinf(r*sinf(i*angle);

glBegin(GL_POLYGON);
for (int i = 0; i < nov; i++){
vertex2f(x[i],y[i]);
}
glEnd();
}



I got a bit bored and thought I'd refresh some OpenGL if your really luck the above function will draw a dot for you.



Share this post


Link to post
Share on other sites
Brother Bob    10344
The specification requires that points are rasterized as circles when point smooth is enabled. The code provided does work as it is. If it doesn't, there's something else in another part or the whole program messing with point rendering, or a driver bug.

Share this post


Link to post
Share on other sites
zerony    122
Quote:
Original post by Brother Bob
The specification requires that points are rasterized as circles when point smooth is enabled. The code provided does work as it is. If it doesn't, there's something else in another part or the whole program messing with point rendering, or a driver bug.

I am pretty new to OPENGL. Here is my code, apapted from opengl example c codes.

#include <GL/glut.h>
#include <stdlib.h>

GLfloat points[3][3] = {
{ -1.0, -1.0, 0.0}, { 0.0, 0.0, 0.0},
{1.0, 1.0, 0.0}};

void init(void)
{
}

void display(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
/* The following code displays the control points as dots. */
glPointSize(8.0);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glBegin(GL_POINTS);
for (i = 0; i < 3; i++)
glVertex3fv(&points[i][0]);
glEnd();

glDisable(GL_POINT_SMOOTH);
glBlendFunc(GL_NONE, GL_NONE);
glDisable(GL_BLEND);
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w,
5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
else
glOrtho(-5.0*(GLfloat)w/(GLfloat)h,
5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}

Could you help me make this working for rendering round dots? appreciate your help.

Share this post


Link to post
Share on other sites
zerony    122
Quote:
Original post by Brother Bob
That exact code gives me three round dots. If you get something else, I suggest you try update the drivers for your graphics card.

Now I just test it on linux box with ati video Card, because I have not get windows box ready yet.
[updated]The code also gives me 3 red round dots on a linux box with NVIDIA Card.
Could you tell me what platform you use? Thanks.

[Edited by - zerony on November 5, 2007 8:05:54 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this