Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:23:13+00:00 2026-05-31T16:23:13+00:00

It seems this should be easy but I’m having a lot of difficulty using

  • 0

It seems this should be easy but I’m having a lot of difficulty using part of a texture with a point sprite. I have googled around extensively and turned up various answers but none of these deal with the specific issue I’m having.

What I’ve learned so far:

  1. Basics of point sprite drawing
  2. How to deal with point sprites rendering as solid squares
  3. How to alter orientation of a point sprite
  4. How to use multiple textures with a point sprite, getting closer here..
  5. That point sprites + sprite sheets has been done before, but is only possible in OpenGL ES 2.0 (not 1.0)

Here is a diagram of what I’m trying to achieve

Point sprite diagram

Where I’m at:

  • I have a set of working point sprites all using the same single square image. Eg: a 16×16 image of a circle works great.
  • I have an Objective-C method which generates a 600×600 image containing a sprite-sheet with multiple images. I have verified this is working by applying the entire sprite sheet image to a quad drawn with GL_TRIANGLES.
  • I have used the above method successfully to draw parts of a sprite sheet on to quads. I just cant get it to work with point sprites.
  • Currently I’m generating texture coordinates pointing to the center of the sprite on the sprite sheet I’m targeting. Eg: Using the image at the bottom; star: 0.166,0.5; cloud: 0.5,0.5; heart: 0.833,0.5.

Code:

Vertex Shader

uniform mat4 Projection;
uniform mat4 Modelview;
uniform float PointSize;

attribute vec4 Position;
attribute vec2 TextureCoordIn;

varying vec2 TextureCoord;

void main(void)
{
    gl_Position = Projection * Modelview * Position;
    TextureCoord = TextureCoordIn;
    gl_PointSize = PointSize;
}

Fragment Shader

varying mediump vec2 TextureCoord;
uniform sampler2D Sampler;

void main(void)
{
    // Using my TextureCoord just draws a grey square, so
    // I'm likely generating texture coords that texture2D doesn't like.
    gl_FragColor = texture2D(Sampler, TextureCoord);

    // Using gl_PointCoord just draws my whole sprite map
    // gl_FragColor = texture2D(Sampler, gl_PointCoord);
}

What I’m stuck on:

  1. I don’t understand how to use the gl_PointCoord variable in the fragment shader. What does gl_PointCoord contain initially? Why? Where does it get its data?
  2. I don’t understand what texture coordinates to pass in. For example, how does the point sprite choose what part of my sprite sheet to use based on the texture coordinates? I’m used to drawing quads which have effectively 4 sets of texture coordinates (one for each vertex), how is this different (clearly it is)?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:23:14+00:00Added an answer on May 31, 2026 at 4:23 pm

    A colleague of mine helped with the answer. It turns out the trick is to utilize both the size of the point (in OpenGL units) and the size of the sprite (in texture units, (0..1)) in combination with a little vector math to render only part of the sprite-sheet onto each point.

    Vertex Shader

    uniform mat4 Projection;
    uniform mat4 Modelview;
    // The radius of the point in OpenGL units, eg: "20.0"
    uniform float PointSize;
    // The size of the sprite being rendered. My sprites are square
    // so I'm just passing in a float.  For non-square sprites pass in
    // the width and height as a vec2.
    uniform float TextureCoordPointSize;
    
    attribute vec4 Position;
    attribute vec4 ObjectCenter;
    // The top left corner of a given sprite in the sprite-sheet
    attribute vec2 TextureCoordIn;
    
    varying vec2 TextureCoord;
    varying vec2 TextureSize;
    
    void main(void)
    {
        gl_Position = Projection * Modelview * Position;
        TextureCoord = TextureCoordIn;
        TextureSize = vec2(TextureCoordPointSize, TextureCoordPointSize);
    
        // This is optional, it is a quick and dirty way to make the points stay the same
        // size on the screen regardless of distance.
        gl_PointSize = PointSize / Position.w;
    }
    

    Fragment Shader

    varying mediump vec2 TextureCoord;
    varying mediump vec2 TextureSize;
    uniform sampler2D Sampler;
    
    void main(void)
    {
        // This is where the magic happens.  Combine all three factors to render
        // just a portion of the sprite-sheet for this point
        mediump vec2 realTexCoord = TextureCoord + (gl_PointCoord * TextureSize);
        mediump vec4 fragColor = texture2D(Sampler, realTexCoord);
    
        // Optional, emulate GL_ALPHA_TEST to use transparent images with
        // point sprites without worrying about z-order.
        // see: http://stackoverflow.com/a/5985195/806988
        if(fragColor.a == 0.0){
            discard;
        }
    
        gl_FragColor = fragColor;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like in Perl this should be easy or a module, but I have
This seems like it should be easy enough, but I'm having trouble in what
This seems like something that should be easy, but I am having a tough
This seems like this should be easy but I have not been able to
This seems like it should be an easy thing to do, but for the
This seems like it should be something very easy to do, but every time
This should be easy (at least no one else seems to be having a
This seems like it should be easy but i've spent way too much time
Ok this should be easy but I can NOT figure it out. I have
Seems like this should be easy, but I'm not finding a simple configuration setting.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.