Multimedia
  Home arrow Multimedia arrow Page 3 - Working with Colors in OpenGL for Game Programming with SDL
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
MULTIMEDIA

Working with Colors in OpenGL for Game Programming with SDL
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 21
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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

    - Basic Lighting in OpenGL and SDL Game Progra...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek