Multimedia Page 4 - Working with Colors in OpenGL for Game Programming with SDL |
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...
blog comments powered by Disqus |
|
|
|
|
|
|
|