Point sprites

  • Follow


Hi.

I'm starting to learn OpenGL, with some DirectX background. It looks like
transition will not be easy.

My question is: how to draw point sprites in OpenGL v1.2?  I mean, how to
draw sprite using single vertex and texture mapped onto it?

Is it possible? Thanks for help.

Vox





0
Reply Vox 3/14/2005 10:30:31 AM

Vox wrote:

> Hi.
> 
> I'm starting to learn OpenGL, with some DirectX background. It looks like
> transition will not be easy.
> 
> My question is: how to draw point sprites in OpenGL v1.2?  I mean, how to
> draw sprite using single vertex and texture mapped onto it?
> 
> Is it possible? Thanks for help.

You can use the GL_ARB_point_sprite extension if your GL implementation
supports it.
0
Reply Rolf 3/14/2005 11:46:50 AM


> You can use the GL_ARB_point_sprite extension if your GL implementation
> supports it.

It looks like it doesn't, I allready tried. Thanks.


0
Reply Vox 3/14/2005 12:21:04 PM

Vox wrote:
>>You can use the GL_ARB_point_sprite extension if your GL implementation
>>supports it.
> 
> 
> It looks like it doesn't, I allready tried. Thanks.
> 
> 
Try updating your drivers.
0
Reply Johan 3/14/2005 4:13:10 PM

Vox wrote:

> Hi.
> 
> I'm starting to learn OpenGL, with some DirectX background. It looks like
> transition will not be easy.
> 
> My question is: how to draw point sprites in OpenGL v1.2?  I mean, how to
> draw sprite using single vertex and texture mapped onto it?
> 
> Is it possible? Thanks for help.
> 
> Vox
> 
> 
> 
> 
> 

I think I know what you are talking about.  I 
remember doing a particle system sample in DirectX 
where all I had to do was specify a point and a 
texture and the point got drawn as a textured 
rectangle.  Pretty neat trick!  I don't think 
OpenGL does this natively though.

I do have 3 ideas for you though:

1)  You can use the following to set a point size:

// Set Point Size
void glPointSize(GLfloat size);

You are limited on the point size though so you 
need to use the following functions to determine 
what values you can specify:

// Store supported point size range here
GLfloat sizes[2];

// Store supported point size increments
GLfloat step;

// Get supported point size range and step size
glGetFloatv(GL_POINT_SIZE_RANGE,sizes);
glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);

The sizes array will contain a minimum point size 
and a maximum point size while step tells the 
smallest difference that can exist between point 
sizes.  This gives you a range and a step that 
tells you what point sizes you can use.  It is 
_important_ that I point out that to my knowledge 
OpenGL Specs only require a point size of 1.0 to 
be supported but there may be some systems that 
give you more.

2)  An alternative is to create your own function 
that will allow you to pass in a point and it will 
draw a square of the size you specify complete 
with texture coordinates.  That isn't difficult at 
all to do.  The hard part is to keep the point in 
front of the camera.  To do this you could switch 
to Ortho2D (be sure to turn off depth), draw your 
2D square, and switch back to 3D.  It would work 
similar to an HUD in a video game.

3)  Finally, you could also make use of 
billboarding for points that are effected by 
depth.  Those are textured rectangles/squares that 
always face the camera.  They are a little more 
work but they look nice.  You have to do some 
calculations at every frame to determine how to 
rotate the billboard so it always faces the 
camera.  It is just a little vector math.  Fun 
stuff I promise!

Just some ideas!

Good Luck!
Matthew Hanna
0
Reply Matthew 3/14/2005 4:14:18 PM

> Just some ideas!
>
> Good Luck!
> Matthew Hanna

Thank you for your ideas.

There is no problem here with using point primitives. They are working, from
my short experience, same way like in DirectX. If I multiply point size in
OpenGL by 10, I have some effect like in DirectX. Or, in other words, point
size and look is exactly the same. Billboarding works, point is always
facing camera when I use GL_POINT primitive. Perfect.

In your first statement there is what I want from OpenGL. To specify a point
and texture and get point drawn as textured rectangle. Why I want this?
Because of better performance (only one vertex per point sprite), and
becuase my engine has to support DirectX and OpenGL. They actually share
same API.

But, it looks like this is not possible with OpenGL 1.2.


0
Reply uf 3/14/2005 4:33:10 PM

> But, it looks like this is not possible with OpenGL 1.2.
>
>

Sorry, that was me before. But location was different :-)


0
Reply Vox 3/14/2005 4:36:58 PM

Johan "MrDutchy" van den Broek wrote:
> Vox wrote:
> 
>>> You can use the GL_ARB_point_sprite extension if your GL implementation
>>> supports it.
>>
>>
>>
>> It looks like it doesn't, I allready tried. Thanks.
>>
>>
> Try updating your drivers.

Yep. ARB_point_sprite is quite widely supported,
maybe you just need a driver update.

http://www.delphi3d.net/hardware/extsupport.php?extension=GL_ARB_point_sprite

If you're releasing the the public you'll have
to fall back to drawing little quads on other
cards.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

Governments, like diapers, should be changed often,
and for the same reason.
0
Reply fungus 3/14/2005 6:57:18 PM

uf wrote:
>
> In your first statement there is what I want from OpenGL. To specify a point
> and texture and get point drawn as textured rectangle. 
> 
> But, it looks like this is not possible with OpenGL 1.2.
> 

Sure it's possible, I do it all the time.
Only thing is just have to do it yourself,
the API won't do it for you.


> Why I want this?
> Because of better performance (only one vertex per point sprite), and
> becuase my engine has to support DirectX and OpenGL. They actually share
> same API.

I bet that DirectX does it in software on a lot
of cards so the performance will be the same.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.
0
Reply fungus 3/14/2005 7:07:57 PM

Rolf Magnus wrote:
> Vox wrote:
> 
> 
>>Hi.
>>
>>I'm starting to learn OpenGL, with some DirectX background. It looks like
>>transition will not be easy.
>>
>>My question is: how to draw point sprites in OpenGL v1.2?  I mean, how to
>>draw sprite using single vertex and texture mapped onto it?
>>
>>Is it possible? Thanks for help.
> 
> 
> You can use the GL_ARB_point_sprite extension if your GL implementation
> supports it.
	I don't advise use point sprites extension. Point and line primitives 
rendering usually falls to software in low-end cards. I advise to use 
textured screen aligned quads. It is not very difficult to implement and 
your program will run on systems without point_sprite extension with 
full hardware acceleration.

-- 
Jacobo Rodr�guez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
0
Reply Jacobo 3/14/2005 8:13:23 PM

> I don't advise use point sprites extension. Point and line primitives
> rendering usually falls to software in low-end cards. I advise to use
> textured screen aligned quads. It is not very difficult to implement and
> your program will run on systems without point_sprite extension with
> full hardware acceleration.
>

Sounds interesting. How to do that (textured screen aligned quads)? Sorry,
but I'm just starting with OpenGL, not experienced yet.

I looked in some examples, one have used triangle fans to draw quads.


0
Reply Vox 3/15/2005 9:24:12 AM

This code will draw a textured screen aligned quad at (originX,originY) 
and with a size of (width,height):


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, windowWidth, 0, windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(texture);
glBegin();
   glTexCoord2f(0.0f,0.0f); glVertex(originX, originY);
   glTexCoord2f(1.0f,0.0f); glVertex(originX + width, originY);
   glTexCoord2f(1.0f,1.0f); glVertex(originX + width, originY + height);
   glTexCoord2f(0.0f,1.0f); glVertex(originX, originY + height);
glEnd();

This the simplest method, but there are others that could be better, 
depending on what you will need, for example, all types of billboarding 
(http://www.lighthouse3d.com/opengl/billboarding/ )

-- 
Jacobo Rodr�guez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
0
Reply Jacobo 3/15/2005 9:34:27 AM

Jacobo Rodriguez wrote:
sorry, I mean glBegin(GL_QUADS);, not glBegin();

> glMatrixMode(GL_PROJECTION);
> glLoadIdentity();
> gluOrtho2D(0, windowWidth, 0, windowHeight);
> glMatrixMode(GL_MODELVIEW);
> glLoadIdentity();
> glEnable(GL_TEXTURE_2D);
> glBindTexture(texture);
> glBegin();
>   glTexCoord2f(0.0f,0.0f); glVertex(originX, originY);
>   glTexCoord2f(1.0f,0.0f); glVertex(originX + width, originY);
>   glTexCoord2f(1.0f,1.0f); glVertex(originX + width, originY + height);
>   glTexCoord2f(0.0f,1.0f); glVertex(originX, originY + height);
> glEnd();
> 
> This the simplest method, but there are others that could be better, 
> depending on what you will need, for example, all types of billboarding 
> (http://www.lighthouse3d.com/opengl/billboarding/ )
> 


-- 
Jacobo Rodr�guez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
0
Reply Jacobo 3/15/2005 9:35:40 AM

OK, thanks, this is great.

Can you explain following: glMatrixMode(GL_PROJECTION) and then
gluOrtho2D(0, windowWidth, 0, windowHeight). We use orthognal projection
here?

What about quad center on the screen? For every quad, originX and originY
has to be first calculated from 3D to screen coordinate?


"Jacobo Rodriguez" <sdf@skdjf.com> schrieb im Newsbeitrag
news:E%xZd.26140$US.6525@news.ono.com...
> Jacobo Rodriguez wrote:
> sorry, I mean glBegin(GL_QUADS);, not glBegin();
>
> > glMatrixMode(GL_PROJECTION);
> > glLoadIdentity();
> > gluOrtho2D(0, windowWidth, 0, windowHeight);
> > glMatrixMode(GL_MODELVIEW);
> > glLoadIdentity();
> > glEnable(GL_TEXTURE_2D);
> > glBindTexture(texture);
> > glBegin();
> >   glTexCoord2f(0.0f,0.0f); glVertex(originX, originY);
> >   glTexCoord2f(1.0f,0.0f); glVertex(originX + width, originY);
> >   glTexCoord2f(1.0f,1.0f); glVertex(originX + width, originY + height);
> >   glTexCoord2f(0.0f,1.0f); glVertex(originX, originY + height);
> > glEnd();
> >
> > This the simplest method, but there are others that could be better,
> > depending on what you will need, for example, all types of billboarding
> > (http://www.lighthouse3d.com/opengl/billboarding/ )
> >
>
>
> -- 
> Jacobo Rodr�guez Villar
>
> TyphoonLabs Lead Programmer
>
> http://www.typhoonlabs.com


0
Reply Vox 3/15/2005 10:04:42 AM

Vox wrote:
> OK, thanks, this is great.
> 
> Can you explain following: glMatrixMode(GL_PROJECTION) and then
> gluOrtho2D(0, windowWidth, 0, windowHeight). We use orthognal projection
> here?
> 
> What about quad center on the screen? For every quad, originX and originY
> has to be first calculated from 3D to screen coordinate?
> 
originX and originY are relatives to the lower left corner of the screen 
and are mapped to 1 unit = one pixel. With this orthographic proyection, 
if you draw a point at glVertex(50,600); you are writting a point at the 
pixel located on x = 50 and y = 600 (relatives to lower left corner), so 
the mapping is really simple. For example, if you want to draw a quad 
that covers ALL the screen, you must write:
glVertex(0,0);
glVertex(windowWidth,0);
glVertex(windowWidth,windowHeight);
glVertex(0,windowHeight);
> 
> "Jacobo Rodriguez" <sdf@skdjf.com> schrieb im Newsbeitrag
> news:E%xZd.26140$US.6525@news.ono.com...
> 
>>Jacobo Rodriguez wrote:
>>sorry, I mean glBegin(GL_QUADS);, not glBegin();
>>
>>
>>>glMatrixMode(GL_PROJECTION);
>>>glLoadIdentity();
>>>gluOrtho2D(0, windowWidth, 0, windowHeight);
>>>glMatrixMode(GL_MODELVIEW);
>>>glLoadIdentity();
>>>glEnable(GL_TEXTURE_2D);
>>>glBindTexture(texture);
>>>glBegin();
>>>  glTexCoord2f(0.0f,0.0f); glVertex(originX, originY);
>>>  glTexCoord2f(1.0f,0.0f); glVertex(originX + width, originY);
>>>  glTexCoord2f(1.0f,1.0f); glVertex(originX + width, originY + height);
>>>  glTexCoord2f(0.0f,1.0f); glVertex(originX, originY + height);
>>>glEnd();
>>>
>>>This the simplest method, but there are others that could be better,
>>>depending on what you will need, for example, all types of billboarding
>>>(http://www.lighthouse3d.com/opengl/billboarding/ )
>>>
>>
>>
>>-- 
>>Jacobo Rodr�guez Villar
>>
>>TyphoonLabs Lead Programmer
>>
>>http://www.typhoonlabs.com
> 
> 
> 


-- 
Jacobo Rodr�guez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
0
Reply Jacobo 3/15/2005 10:29:45 AM

Sorry, you haven't understood my question.

Question is about quad position on the screen. If I use perspective view,
and point is at position 10,10,10 in world coordinates, this in not same
like having point at same position and view is orthogonal, right? Quad
center will be at different postition on the screen?

Web site about billboarding is interesting. Thanks. I think I have something
to do now :-)


0
Reply Vox 3/15/2005 10:57:08 AM

Vox wrote:
> Sorry, you haven't understood my question.
> 
> Question is about quad position on the screen. If I use perspective view,
> and point is at position 10,10,10 in world coordinates, this in not same
> like having point at same position and view is orthogonal, right? Quad
> center will be at different postition on the screen?
> 

That's what all the math is for...to compensate
for this.



-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.
0
Reply fungus 3/15/2005 11:23:07 AM

16 Replies
234 Views

(page loaded in 0.349 seconds)

Similiar Articles:













7/17/2012 4:16:07 PM


Reply: