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

  • Home
  • SEARCH
  • 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 834905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:44:34+00:00 2026-05-15T04:44:34+00:00

I’m working on an algorithm to generate point to point linear gradients. I have

  • 0

I’m working on an algorithm to generate point to point linear gradients. I have a rough proof of concept implementation done:

GLuint OGLENGINEFUNCTIONS::CreateGradient( std::vector<ARGBCOLORF> &input,POINTFLOAT start, POINTFLOAT end, int width, int height,bool radial )
{
    std::vector<POINT> pol;
    std::vector<GLubyte> pdata(width * height * 4);
    std::vector<POINTFLOAT> linearpts;
    std::vector<float> lookup;
    float distance = GetDistance(start,end);
    RoundNumber(distance);
    POINTFLOAT temp;

    float incr = 1 / (distance + 1);
    for(int l = 0; l < 100; l ++)
    {

    POINTFLOAT outA;
    POINTFLOAT OutB;

    float dirlen;
    float perplen;
    POINTFLOAT dir;
    POINTFLOAT ndir;
    POINTFLOAT perp;
    POINTFLOAT nperp;

    POINTFLOAT perpoffset;
    POINTFLOAT diroffset;


    dir.x = end.x - start.x;
    dir.y = end.y - start.y;

    dirlen = sqrt((dir.x * dir.x) + (dir.y * dir.y));

    ndir.x = static_cast<float>(dir.x * 1.0 / dirlen);
    ndir.y = static_cast<float>(dir.y * 1.0 / dirlen);

    perp.x = dir.y;
    perp.y = -dir.x;

    perplen = sqrt((perp.x * perp.x) + (perp.y * perp.y));

    nperp.x = static_cast<float>(perp.x * 1.0 / perplen);
    nperp.y = static_cast<float>(perp.y * 1.0 / perplen);

    perpoffset.x = static_cast<float>(nperp.x * l * 0.5);
    perpoffset.y = static_cast<float>(nperp.y * l * 0.5);

    diroffset.x = static_cast<float>(ndir.x * 0 * 0.5);
    diroffset.y = static_cast<float>(ndir.y * 0 * 0.5);

    outA.x = end.x + perpoffset.x + diroffset.x;
    outA.y = end.y + perpoffset.y + diroffset.y;

    OutB.x = start.x + perpoffset.x - diroffset.x;
    OutB.y = start.y + perpoffset.y - diroffset.y;


    for (float i = 0; i < 1; i += incr)
    {
        temp = GetLinearBezier(i,outA,OutB);
        RoundNumber(temp.x);
        RoundNumber(temp.y);

        linearpts.push_back(temp);
        lookup.push_back(i);
    }

    for (unsigned int j = 0; j < linearpts.size(); j++) {
        if(linearpts[j].x < width && linearpts[j].x >= 0 &&
            linearpts[j].y < height && linearpts[j].y >=0)
        {
            pdata[linearpts[j].x * 4 * width + linearpts[j].y * 4 + 0] = (GLubyte) j;
            pdata[linearpts[j].x * 4 * width + linearpts[j].y  * 4 + 1] = (GLubyte) j;
            pdata[linearpts[j].x * 4 * width + linearpts[j].y  * 4 + 2] = (GLubyte) j;
            pdata[linearpts[j].x * 4 * width + linearpts[j].y  * 4 + 3] = (GLubyte) 255;
        }

    }
    lookup.clear();
    linearpts.clear();
    }


    return CreateTexture(pdata,width,height);
}

It works as I would expect most of the time, but at certain angles it produces little white dots. I can’t figure out what does this.

This is what it looks like at most angles (good) http://img9.imageshack.us/img9/5922/goodgradient.png

But once in a while it looks like this (bad): http://img155.imageshack.us/img155/760/badgradient.png

What could be causing the white dots?
Is there maybe also a better way to generate my gradients if no solution is possible for this?

Thanks

  • 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-15T04:44:35+00:00Added an answer on May 15, 2026 at 4:44 am

    I think you have a bug indexing into the pdata byte vector. Your x domain is [0, width) but when you multiply out the indices you’re doing x * 4 * width. It should probably be x * 4 + y * 4 * width or x * 4 * height + y * 4 depending on whether you’re data is arranged row or column major.

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

Sidebar

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.