Multimedia
  Home arrow Multimedia arrow Page 3 - Working with Colors in OpenGL for Game...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MULTIMEDIA

Working with Colors in OpenGL for Game Programming with SDL
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 19
    2007-12-05

    Table of Contents:
  • Working with Colors in OpenGL for Game Programming with SDL
  • RGB and Indexed Mode
  • Manipulating Color
  • Testing the Colors

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Working with Colors in OpenGL for Game Programming with SDL - Manipulating Color
    (Page 3 of 4 )

    OpenGL APIs: Manipulating Color

    The core of OpenGL color manipulation is two functions: glColor() and glIndex(). The former is for RGBA mode and the latter is for color-index/color-map mode. Here are the details:


    1. glColor*():

    The * is used to represent the fact that there are multiple versions of the function. In the case of glColor() there are 14 different versions, each taking different data-types as data-type parameters. The differentiation is done on the basis of a suffix applied to the function.

    For example, the version that takes integer parameters has i as the suffix, i.e. glColor3i(). All the versions having 3 as part of the suffix take three parameters: the values of the red, blue, and green components. The alpha is set to max implicitly. To explicitly set the value of alpha, the version with 4 as a part of its suffix needs to be used. It takes one extra parameter: the value of alpha component. For example, to set the current color to green without alpha set to max and to have the values to be supplied in integers, the statement would be:


    glColor3i(0,255,0,0);


    To set the current color to red with alpha set to maximum using integer values, the statement would be:

     

    glColor3i(255,0,0,1);



    2. glIndex*():

    This function comes into play when the requirement is color-index mode. It updates the current color index. The main thing to keep in mind is that the current index is saved as a floating point value. If the integer is passed as an argument, then it is converted to a floating point number.

    Just like its RGBA counterpart, glIndex*() has different versions based on the data-type of the parameter. In all the variants, this function takes one parameter: the color index to be used as the current color index. The variants include integer, float, and vector. Vector specified with V accepts array values. The v suffix is used in conjunction with integer (i) and float (f). For example, to set the color index to 25 in integer, the statement would be:


    glIndexi(25);


    Just as with glColor*(), glIndex*() can be called any time to update the current index. Also, it can be used between glBegin and glEnd. 


    That covers the main APIs for color manipulation. In the next section, I will be testing the APIs in the created test bed, which was used in previous parts of the series.

    More Multimedia Articles
    More By A.P.Rajshekhar


     

       

    MULTIMEDIA ARTICLES

    - Working with Colors in OpenGL for Game Progr...
    - Animation in OpenGL for Game Programming usi...
    - Game Programming with SDL: Getting Started w...
    - Using OpenGL with SDL for Game Programming
    - Learning Sound for Game Programming using SDL
    - Game Programming using SDL: Raw Graphics and...
    - Game Programming using SDL: Getting Started
    - Network Radio With Icecast
    - Learning To SMILe

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway