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