glTexImage2D formats clarification

Posts: 321
Joined: 2004.10
Post: #1
Up to now I've only used glTexImage2D() with GL_RGBA for internalFormat
and format parameters. I'm trying to branch out so I looked at some
existing code. The bumps.c demo caught my eye because it uses
GL_LUMINANCE. Here's the code snippet:

bumptex = read_texture("", &texture_width,
&texture_height, &texcomps);

texture_width, texture_height, 0, GL_RGBA,

What puzzles me is that the format of the texture image data is
GL_RGBA, but the texture is a 256 grey (8 bit) data file. I checked
this with Graphic Converter.

Maybe I don't understand the format parameter, but doesn't the
GL_RGBA mean that the bumptex data should be in the form
R, G, B, A, R, G, B, A.... whereas we are giving it Grey1, Grey2, Grey3....

Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #2
First, read the manpage. The prototype is:
void glTexImage2D( GLenum target,
                          GLint level,
                          GLint internalformat,
                          GLsizei width,
                          GLsizei height,
                          GLint border,
                          GLenum format,
                          GLenum type,
                          const GLvoid *pixels )

Note that there is "internal format" and "format, type". GL will convert from "format, type" to "internal format" as required. You can give it RGBA data and tell it to use it as luminance if you want; in that case it will use the R channel and ignore GBA (again, see the manpage.)

Second, you are correct, if the format is RGBA and the actual data is only 8bpp, this is an error. GL will read past the end of the buffer during upload and probably crash. However, it is possible, depending on the image loader, for the 8 bit image data to be decompressed to 32 bit RGBA as it is read from disk. You'd have to look at "bumptex" after it is loaded before calling glTexImage2D, to see how that data compares to what you see in Graphic Converter.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  File formats qwsed 8 13,678 Dec 18, 2010 10:49 AM
Last Post: AnotherJake
  how to use Glubuild2DMipmaps, GlTexImage2D and glTexParameter 007gamer 1 6,108 Jan 31, 2007 04:36 AM
Last Post: OneSadCookie
  internal formats. What are they good for? WhatMeWorry 2 5,101 Jan 9, 2007 11:58 PM
Last Post: arekkusu
  Tex Internal Formats - Clarification Jones 2 4,728 Nov 17, 2006 10:25 PM
Last Post: Jones
  SDL_GL_DEPTH_SIZE clarification... sealfin 2 6,232 Oct 25, 2006 03:51 AM
Last Post: sealfin