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 6129073
In Process

The Archive Base Latest Questions

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

I’ve created a basic orthographic shader that displays sprites from textures. It works great.

  • 0

I’ve created a basic orthographic shader that displays sprites from textures. It works great.

I’ve added a “zoom” factor to it to allow the sprite to scale to become larger or smaller. Assuming that the texture is anchored with its origin in the “lower left”, what it does is shrink towards that origin point, or expand from it towards the upper right. What I actually want is to shrink or expand “in place” to stay centered.

So, one way of achieving that would be to figure out how many pixels I’ll shrink or expand, and compensate. I’m not quite sure how I’d do that, and I also know that’s not the best way. I fooled with order of my translates and scales, thinking I can scale first and then place, but I just get various bad results. I can’t wrap my head around a way to solve the issue.

Here’s my shader:


// Set up orthographic projection (960 x 640)
mat4 projectionMatrix = mat4( 2.0/960.0, 0.0, 0.0, -1.0,
                             0.0, 2.0/640.0, 0.0, -1.0,
                             0.0, 0.0, -1.0, 0.0,
                             0.0, 0.0, 0.0, 1.0);                        

void main()
{
    // Set position
    gl_Position = a_position;

    // Translate by the uniforms for offsetting
    gl_Position.x += translateX;
    gl_Position.y += translateY;

    // Apply our (pre-computed) zoom factor to the X and Y of our matrix
    projectionMatrix[0][0] *= zoomFactorX;
    projectionMatrix[1][1] *= zoomFactorY;

    // Translate
    gl_Position *= projectionMatrix;

    // Pass right along to the frag shader
    v_texCoord = a_texCoord;
}
  • 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-23T16:42:01+00:00Added an answer on May 23, 2026 at 4:42 pm
    mat4 projectionMatrix =
    

    Matrices in GLSL are constructed column-wise. For a mat4, the first 4 values are the first column, then the next 4 values are the second column and so on.

    You transposed your matrix.

    Also, what are those -1’s for?

    For the rest of your question, scaling is not something the projection matrix should be dealing with. Not the kind of scaling you’re talking about. Scales should be applied to the positions before you multiply them with the projection matrix. Just like for 3D objects.

    You didn’t post what your sprite’s vertex data is, so there’s no way to know for sure. But the way it ought to work is that the vertex positions for the sprite should be centered at the sprite’s center (which is wherever you define it to be).

    So if you have a 16×24 sprite, and you want the center of the sprite to be offset 8 pixels right and 8 pixels up, then your sprite rectangle should be (-8, -8) to (8, 16) (from a bottom-left coordinate system).

    Then, if you scale it, it will scale around the center of the sprite’s coordinate system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.