Thread: color problem

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    color problem

    Hello!
    I use vertex-colors in my 2D elements of my program.
    I thought I understood the what the color is, but it seems I don't. I thought the color consists of RGB values: RRGGBB. So that 0000ff is blue, 00ff00 is green and ff0000 is red. These colors seem to work, but when I combine them something goes wrong. ffffff which should be white is something like this and ffff00 which should be bright yellow is actually like this.

    What's wrong with it?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what happens instead? We can probably figure out what is wrong if you give us a short table of
    Code:
    Value   Expected    Actual
    where "Value" might be 00FF00, and Expected "Green", and Actual "Blue".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Code:
    Value   Expected   Actual
    ffffff   white   this
    ffff00   this   this
    00ffff   this   this
    ff00ff   this   this
    It's no point to give more colors. It seems that all colors are darker and I can't give exact colors anyway.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Are you storing the colour numbers in a wide enough type? If you stuff "0xff" into a char, for example, you might not get the results you're expecting. An unsigned char would work; or, if you're putting all of the data into one variable, an unsigned long (or unsigned int if you wish I guess).

    Beyond that, you might want to post some relevant code.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    White is not FFFFFF. It is FFFFFFFF.

    Most color is expressed as RGBA, ARGB, or XRGB. What you have expressed is XRGB. If you are in a graphics API and you have alpha blending enabled but set alpha to 0.0f you will not get any colors at the vertices.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    OK, I forgot about alpha, because I don't use it. These colors are for rhw vertices. Nevertheless it seems to make no difference. It seems that ffffff and ffffffff give exactly the same result and the problem remains.

    I use DWORDs to store colors.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    It seems I know the problem now.
    D3DPRESENT_PARAMETERS :: EnableAutoDepthStencil

    When it is set to TRUE as in 3D it does weird things. I use 3D and 2D rhw simultaneously so I somehow need to change it, but it is not that simple, because it's used in CreateDevice. What should I do? Should I use two separate DirectX devices or is there some other way?

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Never mind the previous post, that wasn't the problem.
    The problem was, that I had to unset the texture, so the 2D elements used the colors of the previously set textures. Colors turned darker, because the texture's color was brown.
    Problem solved!

Popular pages Recent additions subscribe to a feed