OpenGL - changing colours of a shape

This is a discussion on OpenGL - changing colours of a shape within the Game Programming forums, part of the General Programming Boards category; Hi there, I am new to game programming, and I hope it's ok if some of you could kindly help ...

  1. #1
    Registered User anoop29's Avatar
    Join Date
    Mar 2012
    Location
    Uk, London
    Posts
    4

    OpenGL - changing colours of a shape

    Hi there,

    I am new to game programming, and I hope it's ok if some of you could kindly help me out. I understand there may be other people with problems in other threads so I will make this quick.

    I've started using OpenGL for game programming. I am using opengl commands for editing colours of a shape. I have no clue how to change the colours of the shape.

    is the following command:

    //send the verticles and colours for the triangle
    glcolour4f(1.0f , 0.0f , 0.0f , 1.of ) ;
    glVertex3f (.0f , 2.5f , -1.0f ) ;
    glColor4f (0.0f , 1.0f , 0.0f , 1.0f ) ;
    glvertex3f (-3.5f , -2.5f , -1.0f ) ;
    glColor4f (0.0f , 0.0f , 1.0f , 1.0f ) ;
    glVertex3f (2.0f , -4.0f , -1.0f ) ;
    glEnd ():

    It asks me to make the triangle red....
    now how do I go about doing this?

    I'm so sorry to have asked, I'm a newbie to opengl and all

    Would appreciate any help...
    I do apologise if this thread is in the wrong section, please feel free to move it.

    Thankyou

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,623
    Do you know about the RGB components? Red is (1.0f, 0.0f, 0.0f) or (1.0f, 0.0f, 0.0f, 1.0f).

    glColor3f() <- Use this instead, it's easier( sort of )
    Parameters:
    #1: The Red component of the color
    #2: The Green -||-
    #3: The Blue -||-

    If you want a single color, and not gouraud shading or something, you don't have to set the color for each vertex, just once before the first one will suffice.
    Devoted my life to programming...

  3. #3
    Registered User anoop29's Avatar
    Join Date
    Mar 2012
    Location
    Uk, London
    Posts
    4
    Thanks ever so much GReaper.

    I think, I need to know the basics of C++ before going into anything else.

    I'm currently using OPENGL beginners guide for Game programming.

    I think I am jumping to conclusions, not knowing where to start of with.

    Thanks for the help anyway =]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. draw a shape in c
    By ofelia in forum C Programming
    Replies: 2
    Last Post: 05-22-2011, 11:35 PM
  2. Changing colours
    By 250co in forum C Programming
    Replies: 2
    Last Post: 05-12-2006, 01:06 AM
  3. Window shape
    By StephanC in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2004, 08:47 AM
  4. changing color in OpenGL
    By godhand in forum Game Programming
    Replies: 1
    Last Post: 04-14-2004, 08:31 AM
  5. Changing Text/Background colours for window controls ...
    By Shag in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 10:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21