3 Replies - 1064 Views - Last Post: 18 April 2010 - 10:57 AM Rate Topic: -----

#1 sebsebmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 24-January 10

OpenGL color problem

Posted 17 April 2010 - 05:55 PM

working on learning OpenGL but when i compile the colors get mixed together somehow.
here is the draw scene:
void drawScene() {
    //Clear information from last draw
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
    glLoadIdentity(); //Reset the drawing perspective  glBegin(GL_QUADS);
        glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f); //Rotate the camera
    glTranslatef(0.0f, 0.0f, -5.0f);

        glPushMatrix(); //Save transformations performed so far
        glTranslatef(0.0f, -1.0f, 0.0f);
        glRotatef(_angle, 0.0f, 0.0f, 1.0f);
          
    glBegin(GL_QUADS);
     glColor3f(0.5f, 0.0f, 0.8f);
    //Trapezoid
    glVertex3f(-0.7f, -0.5f, 0.0f);
    glVertex3f(0.7f, -0.5f, 0.0f);
    glVertex3f(0.4f, 0.5f, 0.0f);
    glVertex3f(-0.4f, 0.5f, 0.0f);
    
    glEnd();
    
    glPopMatrix();
    glPushMatrix();
    glTranslatef(1.0f, 1.0f, 0.0f);
    glRotatef(_angle, 0.0f, 1.0f, 0.0f);
    glScalef(0.7f, 0.7f, 0.7f);
    
    glBegin(GL_TRIANGLES);
    glColor3f(0.0f, 0.75f, 0.0f);
    
    //Pentagon
    glVertex3f(-0.5f, -0.5f, 0.0f);
    glVertex3f(0.5f, -0.5f, 0.0f);
    glVertex3f(-0.5f, 0.0f, 0.0f);
    
    glVertex3f(-0.5f, 0.0f, 0.0f);
        glVertex3f(0.5f, -0.5f, 0.0f);
    glVertex3f(0.5f, 0.0f, 0.0f);
    
    glVertex3f(-0.5f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.0f, 0.0f);
    glVertex3f(0.0f, 0.5f, 0.0f);
    glEnd();
    
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-1.0f, 1.0f, 0.0f);
    glRotatef(_angle, 1.0f, 2.0f, 3.0f);
    
    
    glBegin(GL_TRIANGLES);
    
    //Triangle
        glColor3f(0.0f, 0.65f, 0.65f);
    glVertex3f(0.5f, -0.5f, 0.0f);
        glColor3f(0.0f, 0.65f, 0.65f);
    glVertex3f(0.0f, 0.5f, 0.0f);
        glColor3f(0.0f, 0.65f, 0.65f);
    glVertex3f(-0.5f, -0.5f, 0.0f);
    
    glEnd();
        glPopMatrix(); //Undo the move to the center of the triangle
        glutSwapBuffers(); //Send the 3D scene to the screen
}


Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL color problem

#2 johnmatthais  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 271
  • Joined: 21-January 09

Re: OpenGL color problem

Posted 17 April 2010 - 06:09 PM

What colors get mixed together? What's supposed to happen? Why do you have the same color code 3 times for the same triangle?
Was This Post Helpful? 0
  • +
  • -

#3 sebsebmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 24-January 10

Re: OpenGL color problem

Posted 18 April 2010 - 08:58 AM

nevermind the triangle should be green but the source code i got from the tutorial made it light blue.
Was This Post Helpful? 0
  • +
  • -

#4 johnmatthais  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 271
  • Joined: 21-January 09

Re: OpenGL color problem

Posted 18 April 2010 - 10:57 AM

Hmm?

So you figured it out? Good job. ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1