Browse Source

Make the color example more useful

Now paints a full bg size and 2/3 size squares
Can serve as reference to pixel data later
gh-pages
falkTX 10 years ago
parent
commit
ccdee172e8
2 changed files with 42 additions and 13 deletions
  1. +37
    -12
      examples/color.cpp
  2. +5
    -1
      examples/image.cpp

+ 37
- 12
examples/color.cpp View File

@@ -43,6 +43,7 @@ public:
{
}

private:
void idleCallback() override
{
switch (cur)
@@ -96,27 +97,51 @@ public:
repaint();
}

private:
void onDisplay() override
{
int x = 0;
int y = 0;
int width = getWidth();
int height = getHeight();

// paint bg color (in full size)
glColor3b(r, g, b);

// full size
const int width = getWidth();
const int height = getHeight();
glBegin(GL_QUADS);
glTexCoord2i(x, y);
glVertex2i(x, y);

glTexCoord2i(x+width, y);
glVertex2i(x+width, y);

glTexCoord2i(x+width, y+height);
glVertex2i(x+width, y+height);

glTexCoord2i(x, y+height);
glVertex2i(x, y+height);
glEnd();

// centered 2/3 size
x = width/6;
y = height/6;
width = width*2/3;
height = height*2/3;

// paint invert color (in 2/3 size)
glColor3b(100-r, 100-g, 100-b);

glBegin(GL_QUADS);
glTexCoord2i(0, height);
glVertex2i(0, height);
glTexCoord2i(x, y);
glVertex2i(x, y);

glTexCoord2i(width, height);
glVertex2i(width, height);
glTexCoord2i(x+width, y);
glVertex2i(x+width, y);

glTexCoord2i(width, 0);
glVertex2i(width, 0);
glTexCoord2i(x+width, y+height);
glVertex2i(x+width, y+height);

glTexCoord2i(0, 0);
glVertex2i(0, 0);
glTexCoord2i(x, y+height);
glVertex2i(x, y+height);
glEnd();
}



+ 5
- 1
examples/image.cpp View File

@@ -39,12 +39,16 @@ public:
ExampleImageWidget(Window& win)
: Widget(win)
{
// TODO: load image
}

protected:
private:
void onDisplay() override
{
fImage.draw();
}

Image fImage;
};

// ------------------------------------------------------


Loading…
Cancel
Save