我已经在下面回答了我的问题。感谢gavinb的帮助。将Uint8转换为无符号字符的RGB值
问题: 我试图复制纹理只是为了学习体验。我使用24位TGA图像,并使用SDL加载它。我已经创建了自己的结构
struct Colour24
{
unsigned char r;
unsigned char g;
unsigned char b;
}
unsigned char* texture = new unsigned char[width * height * 3];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = (y * width) + x;
Colour24 colour = getColourAt(x, y);
newTexture[index] = colour.r;
newTexture[index + 1] = colour.g;
newTexture[index + 2] = colour.b;
}
}
Colour24 getColour(int x, int y)
{
Uint32 pixel;
Uint8 red, green, blue;
Colour24 rgb;
pixel = getPixel(m_surface, x, y); // using the SDL get pixel function
SDL_GetRGB(pixel, m_surface->format, &red, &green, &blue);
rgb.r = red;
rgb.b = blue;
rgb.g = green;
return rgb;
}
OLD: 我打算发送到一个OpenGL纹理这个和它的工作时,我直接将表面 - >像素。但我想自己创建数据数组。非常感谢帮助!
编辑:对不起,我没有解释得很好。我试图从包含24位TGA图像的SDL_Surface中手动重新创建纹理,然后我将它交给opengl来创建纹理。我已经用surface-> pixels测试了我的opengl代码,它工作正常。我只是试图找出我在哪里加载错误。
究竟是什么问题?编译器错误?不符合你的期望?至少你的代码是不完整的,因为它包含与函数定义相同级别的代码。 – bjhend 2012-04-20 10:40:09
我可以将这个纹理加载到opengl中,但它不正确。我得到了很多红色,绿色和蓝色的交叉孵化发生。 – rocklobster 2012-04-20 10:48:12