c++ - 在共享顶点上应用颜色

标签 c++ opengl

int x = 100;
int y = 100;
int width = 250;
int height = 250;
int border = 10;

int top     = y + border;
int bottom  = y + height;
int left    = x + border;
int right   = x + width;

static int vertices[] = {
    x,                  y,                  //0
    right,              y,                  //1
    right,              bottom,             //2
    x,                  bottom,             //3

    left,               top,                //4
    right - border,     top,                //5
    right - border,     bottom - border,    //6
    left,               bottom - border,    //7

    left,               top + (height - border - border) * 0.5,
    right - border,     top + (height - border - border) * 0.5
};


static unsigned int indices[] = {
    0, 1, 4, 5, //top border
    5, 1, 6, 2, //right border
    2, 6, 3, 7, //bottom border
    7, 4, 3, 0, //left border

    4, 5, 8, 9,
    8, 9, 7, 6,
};

static unsigned char colors[] = {
    0x00, 0x00, 0x00,
    0x00, 0x00, 0x00,
    0x00, 0x00, 0x00,
    0x00, 0x00, 0x00,

    0xff, 0x00, 0x00,
    0xff, 0x00, 0x00,
    0xff, 0x00, 0x00,
    0xff, 0x00, 0x00,

    0x00, 0xff, 0x00,
    0x00, 0xff, 0x00,
    0x00, 0xff, 0x00,
    0x00, 0xff, 0x00,

    0x00, 0x00, 0xff,
    0x00, 0x00, 0xff,
    0x00, 0x00, 0xff,
    0x00, 0x00, 0xff,
};

我当前不需要的输出:

enter image description here

在这种实现中是否可以在单个四边形上应用单一颜色?

最佳答案

“顶点”的意思是“位置”,这是一种常见的误解。一个顶点是其属性的整体组合,其中包括位置、颜色、纹理坐标等。如果两个顶点之间的属性之一不同,则顶点不相同。

如果您想为两个四边形赋予不同的纯色,则它们不共享顶点。

我认为其余的应该是显而易见的。

关于c++ - 在共享顶点上应用颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17576596/

相关文章:

c++ - 验证传递给函数的字符串类型(例如文字、数组、指针)

c++ - CUDA 主动扭曲与常驻扭曲

c++ - Qt GUI 数学应用程序在计算时挂出 GUI

c++ - 在 Windows 上以像素为单位获取 OpenGL 点大小?

python - 在 pyOpenGL 中对齐各个对象以创建更大的聚合对象

opengl - cl-opengl 过剩成熟了吗?

c++ - OpenGL:点在无穷远的三角形

c++ - clang-format noop .clang-格式文件

c++ - C++ 中的复制构造函数?

java - 平滑地形碰撞 - 3D