Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GL_POINTS & Textures

632 views
Skip to first unread message

mchristyuk

unread,
Feb 2, 2010, 11:41:25 AM2/2/10
to
Hi all,

I recently posted on a different subject which whilst sorted has led
me on to another problem. Instead of going off topic I decided to
start a new topic so that if I find, or get presented with, a solution
then it'll be easier for others to find.

I have a series of vertices that are rendered as large GL_POINTS. I
wish to apply a texture to them such that each point represents a part
of the texture rather than the entire texture being shrunk and
repeated on each GL_POINT as with GL_POINT_SPRITES.

I've tried messing around with stencil buffers, blending and other
techniques but nothing is really coming together.

As far as I can see there appears to be no way of doing this unless I
turn my GL_POINTS into some form of screen facing quad. Would this be
the correct assumption? Also that using a geometry shader would be the
best way of converting the points to quads? If I am using automatic
coordinate generation with the texture would this still work after the
geometry shader has done it's work or would I have to do some work in
the fragment shader too? Or can GL_POINT_SPRITES be configured so that
they use just a sub sample of the texture rather than the whole thing?

This seems a fairly trivial problem but the correct answer is eluding
me so far...

Cheers

Mark

Skybuck Flying

unread,
Feb 2, 2010, 8:03:10 PM2/2/10
to
What you describe works for me in 2D... I don't know about 3D though...

Maybe it only works in 2D matrix/setup/ortho thingy ?!?

Or maybe you just doing something wrong !

Did you bind the shaders ? You need to associate the shaders with the input
texture as well..

Bye,
Skybuck.


mchristyuk

unread,
Feb 3, 2010, 3:04:11 AM2/3/10
to
Hi Skybuck,

I've not actually done anything with the shaders yet.. more theorised
what may or may not work before I get knee deep in code!

I presume you mean the fragment shader working on your 2D projections
to achieve what I'm looking for?

Cheers

Mark

Skybuck Flying

unread,
Feb 3, 2010, 5:11:08 AM2/3/10
to
I am not sure what you are trying to do.

What I did was: "Use fragment shader", "Use textures", "Use vertex buffers",
"Use framebuffer",

And the fragment shader is able to read a texture coordinate from a vertex,
and use it to do a texture lookup.

And then that color can be outputted towards the "screen".

So for example: Each vertex can read one texel from the texture map and
output it to the screen.

Multiple reads from texture possible too, multiple texture coordinates
possibly too... and up to 4 pixels can be written to the screen if using
multiple render targets.

This all worked with GL_POINTS ! ;)

Verteces can be anywhere on the screen inside the viewport...

Bye,
Skybuck.


mchristyuk

unread,
Feb 3, 2010, 6:45:37 AM2/3/10
to
Hi Skybuck,

You answered my questions thanks. :)

What I want is for a GL_POINT with size say 10 (so bigger than a pixel
dot) to be able to take some texture rather than just being a colour.
If you used the fixed pipeline and texture the GL_POINT then it just
becomes one solid colour. I am hoping that (and you seem to suggest
that it does work) that if I use a fragment shader I can apply a piece
of texture to the GL_POINT so that it is "textured" rather than
"coloured".

I don't have a lot of experience with programming the shaders so this
could be a rocky path I am going down.. but nothing ventured nothing
gained :)

Cheers

Mark

Wolfgang Draxinger

unread,
Feb 3, 2010, 6:46:36 AM2/3/10
to
mchristyuk wrote:

> Hi Skybuck,

Just a humble adivce: Don't talk to Skybuck. He/She is a nut, whose
knowledge about OpenGL is exactly zero. He might think he knows his bits,
but mostly his barking to the wrong tree.

You can get good answers from:
fungus
Ruud van Gaal
Dave Eberly

But definitely not Skybuck. Just browse the c.g.a.opengl archives, to
understand why. Best thing is to put him into your blocklist.

A few months ago I tried to reason with him, to no avail. IMHO Skybuck is a
lost case.


Wolfgang


Wolfgang Draxinger

unread,
Feb 3, 2010, 6:50:52 AM2/3/10
to
mchristyuk wrote:

> Hi Skybuck,
>
> You answered my questions thanks. :)
>
> What I want is for a GL_POINT with size say 10 (so bigger than a pixel
> dot) to be able to take some texture rather than just being a colour.
> If you used the fixed pipeline and texture the GL_POINT then it just
> becomes one solid colour. I am hoping that (and you seem to suggest
> that it does work) that if I use a fragment shader I can apply a piece
> of texture to the GL_POINT so that it is "textured" rather than
> "coloured".

No it won't because this simply is not, how GL_POINTS work. Now what you can
do, if you want multipass rendering is:

1. Render points of your desired size into a texture, the point colour
encoding the spatial coordinates of the point center.

2. Pass this image as a texture/sampler into a fragment shader, which from
each pixels colour and it's position within the image deduces the texture
coordinates and takes the sample from the final texture.

Be aware though, that this will only work for fully opaque points. Any kind
of blending will mess up your spatial coding image.


Wolfgang


Skybuck Flying

unread,
Feb 3, 2010, 5:57:50 PM2/3/10
to
"mchristyuk" <mark.ch...@gmail.com> wrote in message
news:38b107d0-4c93-4d99...@l19g2000yqb.googlegroups.com...

> Hi Skybuck,
>
> You answered my questions thanks. :)
>
> What I want is for a GL_POINT with size say 10 (so bigger than a pixel
> dot) to be able to take some texture rather than just being a colour.
> If you used the fixed pipeline and texture the GL_POINT then it just
> becomes one solid colour. I am hoping that (and you seem to suggest
> that it does work) that if I use a fragment shader I can apply a piece
> of texture to the GL_POINT so that it is "textured" rather than
> "coloured".

Yes OpenGL does have some kind of extensions which can do what you want,
it's enabled with for example:

glPointSize( 50 );
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE_ARB,GL_COORD_REPLACE_ARB,GL_TRUE);

Then in the fragment shader you will get multiple texture coordinates which
you can use to do texture fetches.

However it uses some kind of weird "point texture coordinate space" which I
don't quite understand, so I don't use this feature... But it's kinda
interesting ! ;) So maybe I investigate it in the future ! ;) :)

There is a document about it, see here:

http://www.opengl.org/registry/specs/ARB/point_sprite.txt

>
> I don't have a lot of experience with programming the shaders so this

Neither do I ;) :)

> could be a rocky path I am going down.. but nothing ventured nothing
> gained :)

Yup rocky as hell ! ;) =D LOL.

Bye,
Skybuck =D


Skybuck Flying

unread,
Feb 3, 2010, 6:14:47 PM2/3/10
to
The test program I was using was using "GL_TEXTURE_RECTANGLE_ARB".

The window size was 500x500 or so...

The texture coordinates are like that as well from 0 to 499.

It seems the point sprite has same texture coordinates as the window but
scaled down towards the sprite itself...

So the sprite is like a mini window inside the big window with same
dimensions...

So the window texture coordinates go from 0 to 499.

So the sprite texture coordinates go from 0 to 499 ! ;)

Funny isn't it ?! ;) )

If you were using GL_TEXTURE_2D then it would probably be simply 0 to 1.0 ?
(I didn't test that though ;))

Bye,
Skybuck =D


Skybuck Flying

unread,
Feb 3, 2010, 7:33:00 PM2/3/10
to
Ok,

Now I understand what it is that you are trying to do...

Apperently you have a texture inside the gpu... and you have these "large"
point sprites...

And you want to apply a "part" of the texture to those point sprites.

The point sprites texture coordinates themselfes are probably going to range
from 0 to 1.0 or 0 to (Window Size)-1 (for rectangular).

So you would need to "transform" these basic/simple point sprite texture
coordinates... to somewhere on your "real" texture ! ;) :)

So for example you want part (50,60) to (100, 200) of your texture into the
point sprite. (Squashed and what not ;))

So then the "texture fetch coordinate" is something like:
FetchX = 50 + Position.x * 50;
FetchY = 60 + Position.y * 140;

Assuming position is normalized... meaning from 0 to 1.0... otherwise use
this:
FetchX = 50 + (Position.x/WindowWidth) * 50;
FetchY = 60 + (Position.y/WindowHeight) * 140;
^ That normalizes it for rectangular textures ;)

I guess you know this already... just spelling it out for you and helping
you a little bit :)

So that code would go into the fragment shader ! ;)

Bye,
Skybuck.


Wolfgang Draxinger

unread,
Feb 4, 2010, 2:35:52 AM2/4/10
to
Skybuck Flying wrote:

> It seems the point sprite has same texture coordinates as the window but

> scaled down towards the sprite itself (...)

It's all well specified. From the point sprite specification:

| The following formula is used to evaluate the s and t coordinates:
|
| s = 1/2 + (x_f + 1/2 - x_w) / size
| t = 1/2 - (y_f + 1/2 - y_w) / size
|
| where size is the point's size, x_f and y_f are the (integral) window
| coordinates of the fragment, and x_w and y_w are the exact, unrounded
| window coordinates of the vertex for the point.

However I still doubt, that this is really what the OP wants - asking about
projecting textures. To me this means a completely different set of
applications than point sprites.


Wolfgang


mchristyuk

unread,
Feb 4, 2010, 3:58:12 PM2/4/10
to
Hi Wolfgang,

I've got things working now and I used your suggestion of rendering
small spheres instead of points for the moment. It's taken a lot of
playing with the matricies to get the projections right but got there
in the end!

Cheers

Mark

0 new messages