我已經在下面回答了我的問題。感謝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