OpenGL Color Change?

This is a discussion on OpenGL Color Change? within the Game Programming forums, part of the General Programming Boards category; how could i change the color in an animation, in my book, so far it's only shown hot to make ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question OpenGL Color Change?

    how could i change the color in an animation, in my book, so far it's only shown hot to make the object move. I tried making an array:

    Code:
    float clvl[3]={0.0,0.0,0.0};
    and putting it in with the drawing color:

    Code:
    glColor3f(clvl[0],clvl[1],clvl[2]);
    and then made a statement that cycles through the different variables and changes them accordingly:

    Code:
    int pos=rand()%3;
    if(clvl[pos]==1.0)
    {
         clvl[pos]=0.0;
    }
    else
    {
         clvl[pos]=clvl[pos]+.1;
    }
    The problem is, is that I don't know where to put this statement. I'm not using system specific code, so it should look like it fits in with a console application.

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Make a 2 dimensional array for the colors, like so:

    Code:
    float Color[5][3]= {
    {/*1.0f,0.0f,0.0f*/},{color2},etc.
    }
    then just call
    Code:
    glColor3f(Color[?]);
    and it will read the 2nd array into it.

    *EDIT*

    then for the cycling, make an array that every 2 frames, cycles through the colors, like so:
    Code:
    if (count ==2)
    {
    
    temp=Color[0];
    for (x=0;x<5;x++)
    {
    Color[x] = Color[x+1];
    }
    Color[4]=temp;
    count = 0;
    }
    
    count++
    or something similar, I am not thinking very well right now
    Last edited by EvBladeRunnervE; 03-02-2003 at 03:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21