Home arrow Multimedia arrow Page 4 - Working with Colors in OpenGL for Game Programming with SDL

Testing the Colors - Multimedia

Colors magically bring a scene to life. No matter how interesting the plot is, how engrossing the special effects are, if the color combinations are not accurate or the colors are tepid, the liveliness of the game suffers. In short, it is the combination of and correct usage of colors that decide what the scene and eventually the whole game will be like.

TABLE OF CONTENTS:
  1. Working with Colors in OpenGL for Game Programming with SDL
  2. RGB and Indexed Mode
  3. Manipulating Color
  4. Testing the Colors
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 21
December 05, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
 

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: