Multimedia
  Home arrow Multimedia arrow Page 4 - 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 - 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...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    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




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