render points of different size? (solved)

Started by
2 comments, last by unbird 14 years, 3 months ago
hi everybody, I have a simple question: is it possible to render points (in a single vertex buffer) in variable, user-defined sizes? in all implementations I've seen so far the point size has to be set in the renderstate settings and seems fix. thanks, nicolas [Edited by - nicmenz on January 15, 2010 7:59:32 AM]
Advertisement
Sure. I assume you use the fixed function pipeline. Use a vertex format with a point size. Here is what I do (Note: this is C#/MDX, and I also got a color for each point): First, set up a custom vertex structure:
[StructLayout(LayoutKind.Sequential)]public struct PositionColoredPointSize{    public Vector3 Position;     public float PointSize;    public int Color;         // 32-bit integer}

Then set your device's vertex format appropriately, and enable scaling.
device.VertexFormat = VertexFormats.Position | VertexFormats.PointSize |VertexFormats.Diffuse;device.RenderState.PointScaleEnable = true;


In C++ it'd (probably!) be

struct PositionColoredPointSize{    FLOAT    x, y, z;    FLOAT    PointSize;    D3DCOLOR Color;};

and
device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE);device->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);


If you don't need different colors, omit Color in the above struct and VertexFormats.Diffuse (D3DFVF_DIFFUSE in C++) in the vertex format. Haven't tried, though.

Important: Have a look at the render states D3DRS_POINTSCALE_A, D3DRS_POINTSCALE_B, and D3DRS_POINTSCALE_C and the entry "Point Sprites" in the DirectX SDK documentation, to learn how the final size is actually calculated. There you can find out how to use a texture, too.

Hope that helps
thanks you VERY much for this answer!! rating++
You're welcome, and thanks.

Just for the next time: Be more specific with your question/description: What API, what language, what have you tried (and failed?), etc.

Have fun

unbird

This topic is closed to new replies.

Advertisement