这是我的代码:
int h, w, c;
unsigned char* img = stbi_load("bricks.jpg", &w, &h, &c, 0);
if (img == NULL) {
printf("Error in loading the image\n");
}
printf("Image loaded with width of %d, height of %d, and %d channels", w, h, c);
GLuint txtr = 0;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &txtr);
glBindTexture(GL_TEXTURE_2D, txtr);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
由于某种原因,当我取消注释glTexImage2D
时,我的窗口不再打开。 w
和h
都是由stbi_load
计算的,这是stb_image.h
库的一部分。 我在哪里犯了错误?
c
的值确定format
参数(在您的代码中静态设置为GL_RGB(A)
)。1→GL_RED(如果您使用OpenGL-3之前的版本,则为GL_LUMINANCE),2→GL_RG,3→GL_RGB,4→GL_RGBA。 - datenwolf