In OpenGL 4.6, I (attempt to) create and initialize a solid color texture as follows:
glCreateTextures(GL_TEXTURE_2D, 1, &_textureHandle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); // This doesn't change the outcome
std::vector<unsigned char> data(3 * WIDTH * HEIGHT, static_cast<unsigned char>(200));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, data.data());
I then use the texture in Dear ImGUI like this:
ImGui::Image((void*)(intptr_t) _textureHandle, ImVec2(WIDTH, HEIGHT));
However, this simply shows a black texture.
I also tried a different way of initialization (to no avail):
unsigned char* data = new unsigned char[3 * WIDTH * HEIGHT];
for (unsigned int i = 0; i < (int)(WIDTH * HEIGHT); i++) {
data[i * 3] = (unsigned char)255;
data[i * 3 + 1] = (unsigned char)50;
data[i * 3 + 2] = (unsigned char)170;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
Does anyone know what I'm doing wrong?