I had to find some example code online for this, wherein you take the
"textureImage->pixels" data, and reorder it in a new variable.
unsigned char *data = textureImage->pixels;
unsigned char *newData;
Then they created some variable for getting the pixel data, set it to
zero, byte-shifted it left, and used SDL_GetRGB(); on it given temp
values of r, g, and b (unsigned bytes), then placed them into the
newData structure, and fed those in order to:
glTexImage2D (GL_TEXTURE_2D, 0, 3, textureImage->w, textureImage->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, newData);
[changed is the “GL_RGB” and the “newData” – original below]
I’m not sure the reason for the byteshifting… um. Could someone
explain that, maybe?
Here’s the code of byte shifting and the SDL_GetRGB call:
int BytesPerPixel = textureImage->format->BytesPerPixel;
for(int j = BytesPerPixel - 1 ; j >=0; --j) // for
each byte in the pixel (from the right)
{
pixel_value = pixel_value << 8; // left
shift pixel value by 8 bits
pixel_value = pixel_value | data[ (i * BytesPerPixel) + j ]; //
then make the last 8 bits of pixel value =
}
// the byte that we extract from pBitmap’s data
SDL_GetRGB(pixel_value, texmap->format, (Uint8 *)&r, (Uint8 *)&g, (Uint8
*)&b);
If someone could explain why this is necessary, that’d be just
wonderful. Thanks a lot! I’m still new-ish to the more moderate
level programming techniques, and don’t fully understand byte data
storage, and byte shifting, and whatnot. Thanks a lot!
–Scott
Samuel wrote:>go to nehe.gamedev.net and try the tutorials. there are SDL/Linux ports at the
bottom of the tutorial.
also when doing textures in GL you must make sure that the texture is a factor
of 2
512x512, 256x256, 64x64, …
here check out this snipit
int LoadTextures ()
{
int status = FALSE;
SDL_Surface *textureImage;
/* load the bitmap, check for errors,
-
quit if bmp not found */
if ((textureImage = SDL_LoadBMP (“texture.bmp”)))
{
status = TRUE;
/* setup the texture image */
glGenTextures (1, &texture);
glBindTexture (GL_TEXTURE_2D, texture);
/* map out the texture image */
glTexImage2D (GL_TEXTURE_2D,
0,
3,
textureImage->w,
textureImage->h,
0, GL_BGR, GL_UNSIGNED_BYTE, textureImage->pixels);
/* filter the texture image with linear filtering */
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
/* free texture memory */
SDL_FreeSurface (textureImage);
}
return status;
}
On Tuesday 20 April 2004 08:37 am, Ralf Berger wrote:
Hello,
is somebody able to give me a pointer to a code-sniplet where a texture is
mapped to an OpenGL 3D surface (GL_QUADS)? The texture should be an
SDL_Surface.
I’ve already messed around with the examples from the testgl.c file and the
NeHe-Tutorial (lesson 6) with no success. With the testgl.c code I’m able
to load arbitrary images and use the SDL_Surface texture in the 2D-mode
only, but was not able to map the same texture to on of the cube surfaces.
Since no OpenGL and no SDL error is reported, I’m a little bit lost in
confusion! Any help will be appreciated.
Regards
Ralf
Der WEB.DE Virenschutz schuetzt Ihr Postfach vor dem Wurm Netsky.A-P!
Kostenfrei fuer alle FreeMail Nutzer. http://f.web.de/?mc=021157
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl