我正在尝试获取以下代码块

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture1, 0);

使用动态颜色附件(例如GL_COLOR_ATTACHMENT1,GL_COLOR_ATTACHMENT2等)

问题在于'gl_color_attachment'是'glenum'的类型,因此以下代码将不起作用。
std::string temp = "GL_COLOR_ATTACHMENT" + std::to_string(nrComp);

最佳答案

颜色附件枚举是顺序的,因此您可以将nrComp添加到GL_COLOR_ATTACHMENT0的int值中并进行回退:

glenum temp = static_cast<glenum>(static_cast<int>(GL_COLOR_ATTACHMENT0)+nrComp);

否则,您可以创建附件和索引的数组:
glenum[] attachments = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,...};

glenum temp = attachments[nrComp];

10-08 18:16