• Advertisement
Sign in to follow this  

[OPENGL] random multicolored lines

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking for an effective way to generate random multicolored lines. My random float function is this:
float FLOAT_RAND(float a, float b)
{
return static_cast<float>(((b-a)*((float)rand()/RAND_MAX))+a);
}




particle code:
glbegin...
glColor4f(FLOAT_RAND(0.0f,1.0f),FLOAT_RAND(0.0f,1.0f),FLOAT_RAND(0.0f,1.0f),FLOAT_RAND(0.5f,1.0f)
glend..




But the effect isn't nice. Is there any way to create nice looking colors? thanks!.

Share this post


Link to post
Share on other sites
Advertisement
Only randomise two of the rgb values. This will give you nicer colours in the area you have chosen. For example rbg(0, rand(), rand()) will give you different shades of blue / green.

Share this post


Link to post
Share on other sites
Hmm , much better now! (i combined your ideas !:)thanks!

By the way here's how my app works:(maybe im doing something wrong here)


-create window (ortho mode)
-set up opengl
-extra opengl parameters:
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glEnable(GL_COLOR_MATERIAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
-draw some lines(GL_LINES).

Should i use GL_POINTs with (GL_POINT_SMOOTH) parameter active?

Share this post


Link to post
Share on other sites
Libraries like Microsoft's Crypto API and Mersenne Twister have functionality to fill arrays with random bits. That way if you know ahead of time how many you'll need, you can generate them all in one function call. Should save time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement