Multimedia
  Home arrow Multimedia arrow Page 4 - 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 - Testing the Colors
    ( Page 4 of 4 )

     

    Testing the Colors

    So here is the code. I will be using the RGBA mode. Each vertex of the triangle to be created will have different colors. The points where the colors intersect are of no concern as OpenGL takes care of that. For your information, it is the same one that was developed for testing the animation.


    void Draw3D(SDL_Surface *S) // OpenGL drawing code here

    {

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //clear screen and

    //depth buffer. Screen color has been cleared

    //at init

    glRotatef(angle,0.0f,1.0f,0.0f);// Rotate The Triangle On The Y axis

    glLoadIdentity(); // reset the modelview matrix

    glBegin(GL_TRIANGLES);

    glVertex3f( 0.0f, 1.0f, 0.0f);

    glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);

    glEnd();



    glFlush(); // flush the gl rendering pipelines


    return;

    }


    So now I will be adding the color display code. Each vertex will have different colors -- red, blue and green.


    void Draw3D(SDL_Surface *S) // OpenGL drawing code here

    {

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //clear screen and

    //depth buffer. Screen color has been cleared

    //at init

    glRotatef(angle,0.0f,1.0f,0.0f);// Rotate The Triangle On The Y axis

    glLoadIdentity(); // reset the modelview matrix

    glBegin(GL_TRIANGLES);

    glColor3f(1.0f,0.0f,0.0f);//the vertex displayed after this

    //statement would be red

    glVertex3f( 0.0f, 1.0f, 0.0f);


    glColor3f(0.0f,1.0f,0.0f);//the vertex displayed after this

    //statement would be green

     

    glVertex3f(-1.0f,-1.0f, 0.0f);


    glColor3f(0.0f,0.0f,1.0f);//the vertex displayed after this

    //statement would be blue


    glVertex3f( 1.0f,-1.0f, 0.0f);

    glEnd();



    glFlush(); // flush the gl rendering pipelines


    return;

    }


    That completes adding colors to our test application. It is simple when compared to what can be achieved using OpenGL. The aspects that this article doesn't discuss include dithering and smoothing of the rendered image. These aspects will be the focus of the next part of this series. Till next time...



     
     
    >>> 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