tags:

views:

54

answers:

2

hello i try out opengl.

i have a programm that creates a black border an white corner (quadrangle).

now i want to make the corner of the quadrangle in an different color.

i don't know where exactly to write the code, and i don't know much a but color4f, i searcherd on google, but didn't get it. (is there a good description somewhere?)

#include <iostream> 
#include <GL/freeglut.h>         

void Init() 
{


    glColor4f(100,0,0,0);

}

void RenderScene() //Zeichenfunktion
{

   glLoadIdentity ();   
   glBegin( GL_POLYGON );   
      glVertex3f( -0.5, -0.5, -0.5 );
      glVertex3f(  0.5, -0.5, -0.5 );
      glVertex3f(  0.5,  0.5, -0.5 );
      glVertex3f( -0.5,  0.5, -0.5 );
   glEnd();
  glFlush();  
}

void Reshape(int width,int height)
{

}

void Animate (int value)    
{

   std::cout << "value=" << value << std::endl;
   glutPostRedisplay();
   glutTimerFunc(100, Animate, ++value);          
}

int main(int argc, char **argv)
{
   glutInit( &argc, argv );                // GLUT initialisieren
   glutInitDisplayMode( GLUT_RGB );        // Fenster-Konfiguration
   glutInitWindowSize( 600, 600 );
   glutCreateWindow( "inkrement screen; visual screen" );   // Fenster-Erzeugung
   glutDisplayFunc( RenderScene );         // Zeichenfunktion bekannt machen
   glutReshapeFunc( Reshape );

   glutTimerFunc( 10, Animate, 0);
   Init();
   glutMainLoop();
   return 0;
}
A: 

Specify vertex color right before specifying the vertex itself, in the GL_POLYGON block.

However, I would recommend going for OpenGL 2.x instead of learning that old OpenGL 1.x stuff anymore. There you use VBOs (Vertex Buffer Objects) instead of glBegin/glEnd etc.

Tronic
James D
+3  A: 

First of all, you probably want glColor3f. glColor4f also takes an alpha (transparency) value, which you probably don't care about yet. The range of parameters is 0 for no intensity and 1 for max intensity of red, green and blue. So you could do something like:

  glColor3f( 1.0f, 0.0f, 0.0f );    // red
  glVertex3f( -0.5, -0.5, -0.5 );   // this vertex is red
  glColor3f( 0.0f, 1.0f, 0.0f );    // green
  glVertex3f(  0.5, -0.5, -0.5 );   // this vertex is green
  glColor3f( 0.0f, 0.0f, 1.0f );    // blue
  glVertex3f(  0.5,  0.5, -0.5 );   // this vertex is blue
  glVertex3f( -0.5,  0.5, -0.5 );   // since it wasn't changed, this one will be blue, too