Help with pixel color

Discussion in '3DS - Homebrew Development and Emulators' started by Moocow9m, Dec 29, 2016.

  1. Moocow9m
    OP

    Moocow9m Newbie

    Newcomer
    8
    0
    Dec 29, 2016
    United States
    I have this code:

    Code:
    void drawPixel(int x, int y, u16 color, u8* screen)
    {
        int height=240;
        u32 v=((239-y)+x*height) *2;
        screen[v]=color;
        screen[v+1]=color;
        screen[v+2]=color;
    }
    
    void drawPixel(int x, int y, u16 r, u16 g, u16 b, u8* screen)
    {
        int height=240;
        u32 v=((239-y)+x*height) *2;
        screen[v]=r;
        screen[v+1]=g;
        screen[v+2]=b;
    }
    
    However I cannot figure out how colors work. Can anyone give me a table?
     
    Last edited by Moocow9m, Dec 29, 2016
  2. Mikemk

    Mikemk GBAtemp Maniac

    Member
    1,483
    517
    Mar 26, 2015
    United States
    Well, there's 16.8 million possible colors (65,536 if you uncomment the one line), so a table seems unlikely.

    But it's an intensity of red, green, and blue (the primary colors, yellow is not a primary color). A higher number is more of that color. 0/0/0 is black, 255/255/255 is white, 0/97/0 is dark green, 220/255/0 is a slightly greenish yellow, ...
     
  3. Moocow9m
    OP

    Moocow9m Newbie

    Newcomer
    8
    0
    Dec 29, 2016
    United States
    Well that commented line i forgot to remove before copying because I could not find a way to implement it. But when I ran a for loop it didn't give many correct color changes...

    This code:

    Code:
    drawPixel(i, ii, 0, 255, 255, gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0));
    and
    Code:
    drawPixel(i, ii, 255, gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0));
    makes white and this code:

    Code:
    drawPixel(i, ii, 255, 0, 0, gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0));
    and
    Code:
    drawPixel(i, ii, 0, gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0));
    makes black (first one also makes makes a blue line at the bottom).
    Can you explain this?
     
    Last edited by Moocow9m, Dec 29, 2016